Application Raspberry PI in everyday life and non-standard applications

Raspberry PI is a device that has sufficient performance in order to be built on its basis, robots can recognize images, perform the work of people and other similar devices for automating and performing complex computing actions. Because clock frequency Raspberry PI processor 3 mb 1.2 GHz and its bits of 32 bits that Raspberry PI 3 significantly exceeds the usual Arduino in which the clock frequency is usually 16 MHz and the bit rate of the microcontroller 8 bits, Arduino certainly takes its place in performing operations that do not require high performance, but when it is not enough Raspberry PI. " comes to the rescue "and overlaps such a large range possible applications What you can be absolutely confident in the feasibility of purchasing this single-board computer Raspberry PI 3 (you can order on the link). Because Raspberry PI is a computer that in order to use it to install the operating system on it (although there are workarounds, but it is still better to install the operating system (OS below)). There are many OSs that can be installed on the Raspberry PI but one of the most popular (for use with Raspberry PI), the most suitable for beginners is Raspbian OS. In order to install the OS on the Raspberry Pi, you need a Micro SD card with an extender to insert it in normal computer And write to it. The SD card must have at least 4GB memory when installing the full version of Raspbian and at least 8GB to install the minimum versions of Raspbian. Minimum versions may not have (and most likely do not have) graphic interface And the rest of the rest can be considered superfluous and takes place. To avoid problems with the lack of file required, You can put the full version. You can use the SD card of the 10th grade and with 32GB of memory (verified works (as if see the video below)). After purchasing a memory card, you need to insert it into the computer to the appropriate connector, after that, to see what letter disk appears in the section "My computer" and remember, then you need to download the OS from the official site https://www.raspberrypi.org/downloads/raspbian / By clicking the "download zip" button under "Raspbian Jessie" to download the full version or under the "Raspbian Jessie Lite" to download lightly but, for beginners, it is better to choose "Raspbian Jessie" i.e. Full version. After downloading the archive of Raspbian Jessie, it needs to unzip it, then download the program (or from https://yadi.sk/d/sgge1lmns69yq), install it, open, then you need to specify the letter of the disc in the upper right corner (remembered earlier), find the unzipped image of the OS

And click the "Write" button.

After that, a warning window will be displayed and you need to press the "YES" button in this window,

After the entry is to end and the WRITE SUCCESSFUL window will appear (WRITE SUCCESSFUL). You need to click the "OK" button in this window.

Then close the program, pull out the SD card safe way And insert in Raspberry Pi.

Next can be connected to Raspberry PI uSB keyboard (or PS2 via), USB mouse and monitor or TV through hDMI Cable Or you can connect an Ethernet cable (but it is for experienced users. Therefore, let's consider the first option). After that you need to connect the power through micro USB. For example charger From a smartphone. After connecting the power, installation of the operating system will start. As a rule, in new (at the time of writing this article), the OS versions are already configured to communicate with the Raspberry PI on SSH and therefore in order to configure the connection with the Raspberry PI 3 via WiFi, it is enough to configure only WiFi, for this in the upper right corner of the screen there is a sign on which you need to click and select WiFi,

After that enter the password from this WiFi. in the text field that appears,

After these WiFi actions on the Raspberry PI 3 will be configured and then it will be possible without using the wires to program Raspberry PI 3 remotely via WiFi. After setting up the Raspberry PI 3, you can turn off on the command line (in the LXTerminal program that you can open a double click on the program icon) Sudo Halt command or pressing the appropriate shutdown buttons in graphical mode, after the final shutdown can be turned off the power and the following power supply Raspberry PI 3 Turn on with wifi. Now to program Raspberry PI 3 via WiFi you need to find out what is your IP address. In order to make it necessary to feed on the Raspberry PI 3, wait for the end of the OS boot, go to the web interface of the router (on the browser line 192.168.1.1 or what is needed to enter the web interface, enter the username and password), find the DHCP tab Leases or something similar, find there a string with Raspberry and IP address Raspberry PI 3.

Next, you need to open the PUTTY program (if it is not there before you download (or) and install) Put the port 22, the connection via SSH, enter in the "Host Name" field (OR IP ADRESS) "Raspberry PI 3

After that click the "Open" button at the bottom of the window, then appear black window With the proposal to enter login. By default, the username "PI" - it must be entered and press Enter. Next, you need to enter the password, the default "Raspberry". When entering a password, it is not displayed - this is normal. After the password is entered by invisible letters, you need to press ENTER and if everything was done correctly, we will get access to Raspberry PI 3 if not, you need to repeat the steps. After accessing Raspberry Pi 3 is received, you can program it, first you need to enter the "PI" folder for this you need to enter the command

And press ENTER (after CD necessarily space).
Now you can open text editor Nano. Nano is a special text editor that is on most OS on Linux similarity and in which you can write a program for Raspberry PI. To open this editor and at the same time creating a file with the name "first" and the "PY" extension to enter the command

And press ENTER. The Nano editor opens and you can notice that its interface is slightly different, but mostly - this is the same black field in which you need to enter commands. Because We want to manage the input ports of the Output (GPIO), then before running the program to manage these ports, you need to connect some device to them so that you can see that the control happened. It should also be noted that Pins configured as Raspberry PI outputs can issue a very small current (I assume that up to 25th) and considering that Raspberry PI is still not the cheapest device, it is strongly recommended to take care of the load on the conclusions was not too large. Low-power indicator LEDs, as a rule, can be used with Raspberry PI. It is to glow enough small current. For the first time, you can make a device with a connector, two ones parallel to the on-line LEDs and a resistor with a resistance of 220m connected in series with LEDs. Because Resistance to the resistor 220Ω, the current necessarily passes through this resistor and there are no parallel paths of its passage, the voltage at the 3.3B terminals will not be more than 3.3 / 220 \u003d 0.015a \u003d 15mA. You can connect it to free GPIO for example to 5 and 13 as in the diagram

(pinout is taken from https://en.wikipedia.org/wiki/raspberry_pi), it can look like this:

After everything is neat and correctly connected and there is confidence that nothing burns, you can copy the first simple program to the Nano editor python language

Import rpi.gpio as gpio
Import Time.
Gpio.SetMode (GPIO.BCM)
Gpio.Setup (13, GPIO.out)
Gpio.Setup (5, GPIO.out)
GPIO.Output (13, True)
GPIO.Output (5, False)
Time.Sleep (1)
GPIO.Output (13, False)
GPIO.Output (5, True)
Time.Sleep (1)
GPIO.Output (13, True)
GPIO.Output (5, False)
Time.Sleep (1)
GPIO.Output (13, False)
GPIO.Output (5, True)
Time.Sleep (1)
GPIO.Output (13, True)
GPIO.Output (5, False)
Time.Sleep (1)
GPIO.Output (13, False)
GPIO.Output (5, True)
Time.Sleep (1)
Gpio.cleanup ()

Then click

After exiting the Nano editor, you can enter the command

Sudo Python First.py.

After that, the LEDs murmulate for a number of times. Those. It turned out to manage the output ports general purpose on WiFi! Now let's look at the program and find out how it happened.
Line:

Import rpi.gpio as gpio

This is the connection of the GPIO library to control the outputs.
Line:

This is the connection of the Time library for delays.
Next, the GPIO mode is set:

Gpio.SetMode (GPIO.BCM)

Configuration of conclusions 5 and 13 as outputs:

Gpio.Setup (13, GPIO.out)
Gpio.Setup (5, GPIO.out)

Installing a logical unit at the output 13, setting the logical zero at the output 5:

GPIO.Output (13, True)
GPIO.Output (5, False)

Delay

Installing a logical zero at the output 13, setting a logical unit at the output 5:

GPIO.Output (13, False)
GPIO.Output (5, True)

Translates all conclusions in the initial state And the program is completed. So can be controlled by any free WiFi Pins and if you make food 5V from the battery, you can already do any autonomous Robot. or a device not tied with wires to any stationary. Python Programming Language (Python) is different from these languages, for example, instead of a semicolon, to complete the command, a row translation is used in Python, instead of curly brackets use an indentation from the left edge that is done by the Tab key. In general, Python is a very interesting language on which the readable simple code is obtained. After the work (or the game) with Raspberry PI 3 is finished, you can turn it off by the command

And after complete shutdown, remove the power. When powering the Raspberry Pi 3, you can also work with it again (or play). Raspberry PI 3 can be found at http://ali.pub/91xb2. About how is done setting up Raspberry. PI 3 and control of his Pimans can be viewed on video:

After successful blinking by LEDs, you can start a full-scale study. this computer And project creation using Raspberry PI 3 features that are limited only to your imagination!

A concept for connecting a button is depicted in Figure 12. Please note that male Plate It remains connected and the LED from the example in the first part of the article, but it is not shown on the current scheme.

As can be seen from the scheme, if the button is not pressed, the GPIO5 input will be connected via the resistor to the 3.3 V. The input port of the RPI has a high input resistance, so the voltage on the input line will be close to 3.3 V. This means that when the RPI is released, it will determine The state of entry like "Log. one". When the button is pressed, the voltage at the input will be 0 B, which is "log. 0 ".

For this simple circuit, the resistor resistance R1 is noncritical and may be in the range from 1 kΩ to 47 kΩ, however, low values \u200b\u200bshould be avoided, since in this case the current consumed when the button is pressed.

The source code for reading the button is available in the downloads section (file named Listing_4 (Button) .txt). Save the code in the file named Button-Test.py. and run to execute a command

sudo Python Button-Test.py.

The results of the program is displayed as a message about the current state of the button and the number of clicks on it. When executing this example, you will notice that sometimes the counter value becomes more than the actual number of presses on the button, and this is due to the "rat" of contacts. Approximately the same thing happens when the button is released. The solution is to use the "Davebound" suppression mechanism (Debouncing). This mechanism can be both hardware and software, and the latter is more common. In the source code shown in the file Listing_5 (Button_Debounce) .txt, suppressing the recreation of the contacts of the button is implemented, and the number of clicks of the button will be more accurate. The only difference from the previous code is that now with a delay of 20 ms, the second check of the entry status is performed - during this time, the ratios of contacts stop.

Another example: Voltmeter

As you know, the RPI boards have only digital I / O ports, but in the real world analog values \u200b\u200bare used, which may need to be measured or controlled. The following example demonstrates the conversion of analogue value in digital signalwhich can be read using the RPI inputs.

An example is a very simple, but accurate voltmeter with a measurement range of 0 ... 1 V (Figures 13, 14). Note that it cannot replace the portable multimeter, because it does not have the necessary protection circuits, and may fail or damage the RPI board, if used for something that goes beyond the examples described herein.

The diagram uses the AD654 chip (voltage-frequency converter), which generates rectangular pulses with a frequency depending on the input voltage. The digital output of the FOUT microcircuit is connected to the GPIO5 input (output 29 GPIO connector). Maximum frequency rectangular impulses With the elements indicated on the diagram, 10 kHz is equal, so it will require an accurate time counting system to determine the input voltage. Code for this example (file Listing_6 (Voltmeter) .txt) Written on Si and uses the Wiringpi library written by Gordon Henderson (Gordon Henderson). First of all, install the library wiringpi.For what follow the following commands:

mkdir Development.
CD Development
Git Clone Git: //git.drogon.net/wiringpi
CD Wiringpi.
./build.

Save the code in the file named voltmeter.c. and compile his team

gcc -o voltmeter -lrt -lwiringpi voltmeter.c.

To run the program, run the following command:

sudo ./voltmeter.

To improve the measurement accuracy, the program uses averaging. The duration of input rectangular pulses is quickly measured 64 times, then the obtained values \u200b\u200bare summed up and divided by 64. At the end of the calculation, the delay for one second to perform other processes, and then the measurement cycle is repeated

Several elements in the voltmeter scheme also affect the accuracy of measurements. The C1 condenser and the resistor R1 set the conversion characteristics, so it is desirable to choose a film polypropylene capacitor and an accurate resistor with a tolerance of 1%. You can use a stroke resistor. The supply voltage of the 5 V schema comes from the GPIO connector, but its real value may differ slightly from 5 V, so it is better to use a separate more accurate power source.

For fast check Schemes can use a voltage divider consisting of two resistors. The divisor's power circuit is shown in the left side of the voltmeter scheme (Figure 12). If precision resistors and supply voltage are accuracy equal to 5 V, the calculation of the voltage at the output of the divider gives 0.04950 V. The value obtained as a result of a real software measurement was 0.04991 V. Not bad for such a simple project!

Schottky d1 and d2 diodes in the scheme are not mandatory, but strongly recommended, because they will provide some protection of the chip, if the voltage is randomly the voltage of 0 ... 1 V.

Protected inputs

RPI can be protected from random high voltage ingress by adding an additional scheme to the inputs used. In some cases, a very good and inexpensive alternative to the following scheme (Figure 15) may serve as a support that can protect the RPI inputs from voltages to 60 V and cope with the ransom. The BC547B transistor in the diagram in Figure 14 can be replaced by 2N3904 or BC549. The permissible power dissipation of the resistor R1 may be 0.25 W at input voltages up to 50 V, otherwise it is better to use 0.5 W.

The diagram inverts the input signal, switching to "Log. 0 "with input voltage Over 2 V.

Connect to 5-volt logic

Direct connection of devices with 5-volt logic outputs to the RPI inputs can withdraw a fee. In this case, there are many solutions.

If the state of the 5-volt logical output changes relatively slowly, it can be given to the possibility of using a resistive divider at the rpi input, but this method is not applicable to rapid schemes. Then much more good decision There will be a buffer chip. For mean velocities (up to 100 kHz), a scheme is quite suitable on the N-channel MOSFET ZVN2110A (Figure 16). This scheme also inverts the input signal.

The transistor shown on the diagram can be replaced with ZVNL120A or VN10LP.

When soldy field transistors Basic precautions should be followed. When assembling the device, first set the R3 resistor and only then remove the MOSFET from the protective packaging and specify in the scheme. R3 resistor will provide some protection.

Speed \u200b\u200band jitter

Survey of the status of buttons and control of LEDs - events are relatively slow, measuring dozens and hundreds of milliseconds. Sometimes there are much more high-speed signals. For example, the remote control emits infrared light pulses at a speed of 40 thousand times per second. Despite the fact that the main RPI processor operates at 1 GHz frequency, the operation of the I / O subsystem at such a speed is not supported for a number of reasons, both hardware and software. We will look at some program aspects regarding the topic of the article.

RPI is running a multi-tasking operating system (OS) Linux. The system can preventively take control over your program to perform other tasks. All this happens pretty quickly, so it seems that the mouse still works during the execution of your program, but in fact your program and the OS mouse driver code provides only short intervals.

It usually does not matter, but when you need a processing of short or high-precision events, it can become a problem that manifests (for example) in the form of a jitter.

In addition, the selection of the programming language has an important value, since some libraries are better suitable than others. Interpretated and compiled codes can be performed with different speeds. In short, if a very accurate time-binding event is required, you may have to write a Linux driver or use external equipment (for example, another microcontroller or logic and generator).

One of good questionsimportant for more full use RPI features, is how quickly you can change the logical states of the GPIO outputs using the Python, SI libraries and the command script described above.

To find out this, the code was written to periodically switch the logical state of the output port to which the oscilloscope was connected. The result is presented in Table 1.

Table 1. Maximum switching frequency outputs
using different programming languages
Language
Programming
Frequency Duration
high level
Duration
Low level
Python 71.2 kHz 3.9 μS. 10.1 μS.
S. 5.8 MHz 85 ns. 85 ns.
Command Script. 3.9 kHz 115 μs. 139 μS.

However, it is always important to remember the jitter, which is necessarily accompanied by the work of Linux OS. For the case of a simple switching of the LED, it is preceded, not a problem. The character of the jitter can be seen on the oscilloscope in the overlay mode of several channels during synchronization with a common signal (Figure 17). Please note that jitter can take many values, despite the fact that the signals are discretened to 4 ns (250 MHz), which is associated with the hardware features of the RPI.

Conclusion

Now you have seen that the 40-pin GPIO connector on RPI boards can be used for various projects - from control of LEDs to electronic circuits to measure analog values. With small additional adaptation schemes, the RPI logical levels can interact with 5-volt devices. Using Python, it is very easy to manage the outputs, just as it does not represent the complexity and reading of the input status, and the WiringPI library greatly simplifies the management of programmers using C.

From the point of view of the external Raspberry PI interfaces, like other small single-board computers, is not very different from the usual desktop PC. On the RPI board are provided USB ports To connect the keyboard and mouse, the HDMI port for connecting the display. However, due to the fact that RPI is much more compact and cheaper than PC, it becomes possible to use them in various systems And applications where PCs or laptops are inappropriate.

Often, a desire arises to connect any non-standard "things" to the PC. It is possible, for example, that you will want to use a computer to measure the level of brightness and automatic lighting control, or to supply the audio signal when the intruder is detected.

In wider plan, it is about desire to use a computer to control electronic circuits (outputs) and to obtain information from circuits or devices (inputs).

It is here that the obvious advantage of RPI and other SBCs, due to the key difference between single-board computers and PCs, is manifested: single-board computers have a general-purpose I / O ports, which is not in the large PC (Figure 1).

Through these conclusions (pin connectors), RPI can interact with the electronic world consisting (among other things) from sensors, indicators and actuators.

In the article, we will consider examples of schemes that you can use "as is" (or change and expand), along with examples of code in several programming languages.

Raspberry Pi Expansion Connector

Figure 2 shows the location and assignment of the RASPBERRY PI expansion connector. The first conclusions of such connectors on printed boardsTypically, can be identified in a square contact site on the lower layer of the board. On the 40-pin RPI extension connector, digital inputs and outputs compatible with logical levels 3.3 V.

Compatibility with logical levels 3.3 B means that RPI will interpret the input level close to 0 in as a logical "0", and the level is higher than 2V as a logical "1". The supply to the voltage input above 3.3 can output RPI. Accordingly, when the GPIO port is configured as an output, RPI will install voltage close to 0 or 3.3 V.

In the article, we will talk about the conclusions marked in Figure 2 pink, white, red and orange. The remaining ports are used by serial data interfaces.

RPI digital outputs

First steps: LED control

The simplest example of using outputs is the control of the LED or a light bulb, or some drive or motor. To convert the RPI output signal to something that will manage necessary deviceThe electronic circuit is usually required. All that is necessary for a small LED is a serial current-translating resistor that protects the LED and the RPI output. The resistance of the resistor is selected from the range of 100 Ohm ... 1 com, depending on the LED used and the required brightness when setting the logical "1" output.

Connecting the LED to the GPIO connector contacts using an invaricular damp, shown in Figure 3, and the diagram itself - in Figure 4. The GND connection (0 B) was taken from the output 6 of the GPIO connector, the GPIO22 port is used to control the LED (15). You can use any GPIO port marked with pink color in Figure 2.

After all connections are made and checked, you can start writing code or LED control script. The choice of language depends on you. One example on popular language Python is contained in (listing 1).

Listing 1. Example of a Python program for easy flashing LED.


Import Time.
Import rpi.gpio as gpio
Gpio.SetMode (GPIO.BCM)
Gpio.Setup (22, GPIO.out)
Gpio.Output (22, True)
Time.Sleep (3)
Gpio.cleanup ()

Save the code to the file named led-test.py. And then run it by running the command:

sudo Python Led-test.py.

Another program (Listing 2) demonstrates an example of controlling the LED. The LED flashes 10 times. (Note: In Python, in contrast to other programming languages, it is important to use indents in the code).

Listing 2. The source code of the program on Python (LED flashes 10 times).

# LED connected to GPIO22 (contact 15)
Import Time.
Import rpi.gpio as gpio
Gpio.SetMode (GPIO.BCM)
FOR X IN RANGE (0.10):
Gpio.Setup (22, GPIO.out)
Gpio.Output (22, True)
Time.Sleep (0.05)
GPIO.Output (22, False)
Time.Sleep (0.45)

Gpio.cleanup ()

Another method of managing GPIO ports is based on the use of a shell script (shell script). This method seems a bit more complicated (if you do not like to write scripts), but it is good just to expand the horizons, since many programming languages \u200b\u200boften allow you to run command scripts, and if necessary, it can be one of the rapid GPIO port management methods from other languages . In addition, described in Listing 3 method is standard for different platforms, so your code can be transferred to other boards.

Listing 3. The command script (shell script) to control the LED connected to the GPIO22 Raspberry PI.

#! / bin / sh
GPIO_PATH \u003d / SYS / CLASS / GPIO
LED_PIN \u003d 22 #gpio 22 IS PIN 15
Echo "$ LED_PIN"\u003e $ GPIO_PATH / Export
Echo "Out"\u003e $ GPIO_PATH / GPIO $ LED_PIN / DIRECTION
Echo "1"\u003e $ GPIO_PATH / GPIO $ LED_PIN / VALUE
Sleep 1.
Echo "$ LED_PIN"\u003e $ GPIO_PATH / UNEXPORT

The first string of the script looks like a comment, but it indicates linux sheathWhat to do with a script when performing, so it is impossible to change it. The remaining script lines are used to control the corresponding GPIO port, configuring it as an output, installing high levels on it and perform delay by 1 s. At the end of the port is released to enable it to use it in other programs.

Another common programming language with which you can meet is Si, or his older brother C ++. Examples source code On SI or C ++ will be given later when we proceed to work with digital inputs.

Generator of tonal signals

More an interesting example It can be the use of several GPIO ports to control the tonal generator. RPI has a jack for connecting headphones, but often to alerts about events (for example, for alarm) a fairly simple signal or a series of signals of different tone.

Schematic diagram of a simple generator sound signalsperformed on the microcircuit integral timer ICM7555, depicted in Figure 5. The type of design assembled on the dumping board is shown in Figure 6. By changing the somes of the resistor and the condenser, you can create different tonal signals and sounds.

The generator management is carried out by two GPIO RPI ports. One output (GPIO22) is used to turn on or off the sound, and the second (GPIO27) - to switch between two alternative signal frequencies. If you wish, you can select other tones by changing the ratings of components C1, R1 and R2.

The source code of the program in the Python language generating several sound effects is shown in Listing 4. Save the code in the file named tone-Test.py. and then run to execute a command

sudo Python Tone-Test.py.

Listing 4. Sound Generator Management Program.

import Time.
Import rpi.gpio as gpio
Gpio.SetMode (GPIO.BCM)
Gpio.Setup (22, GPIO.out) # ON / OFF Generator
Gpio.Setup (27, GPIO.out) # Change tonality

Gpio.Output (22, True)
For x in Range (0,5):
Gpio.Output (27, True)
Time.Sleep (0.1)
Gpio.Output (27, False)
Time.Sleep (0.2)
GPIO.Output (22, False)
Time.Sleep (0.5)

For x in Range (0,5):
Gpio.Output (22, True)
Time.Sleep (0.1)
GPIO.Output (22, False)
Time.Sleep (0.2)
Gpio.Output (27, True)
Time.Sleep (0.2)

For x in Range (0,5):
Gpio.Output (22, True)
Time.Sleep (0.05)
GPIO.Output (22, False)
Time.Sleep (0.05)

FOR X IN RANGE (0.10):
Gpio.Output (22, True)
Time.Sleep (0.1)
GPIO.Output (22, False)
Time.Sleep (0.1)
Time.Sleep (1)

Gpio.cleanup ()

Note that the circuit is powered by a 3.3 V voltage (output 1 of the GPIO connector). Use this source only if you are confident that your scheme does not consume a significant current. Power bus 3.3 V can be loaded up to 50 mA. If necessary, you can use a separate voltage regulator 5 V - 3.3. In and connect it to the power source of 5 V, available on the output 2 of the GPIO connector.

The schemes discussed above are powered by low voltage and consume a small current, but sometimes it is necessary to control sufficiently powerful external devices. Several typical ways to solve such tasks are described below.

Connect to 5-volt logical devices

Using RPI to control 5-volt devices will not require any additional schemes. The logical inputs of the device with a supply voltage 5 V will function normally with 3.3 output signals in RPI ports.

Low power LEDs

For low-power blue and white LEDs, voltage is required above 3.3 V. The easiest way to control the unit LED using the transistor key, switching the tire 5 V (Figure 7). Resistance resistor R1 is calculated based on technical characteristics Specific LED, transistor - any n-p-n Type.

Powerful devices

The simplest and most common way to control powerful devices that are energized from the source of variable or direct current (But not from the network) is the use of a relay with a transistor key (Figure 8). It will be suitable almost any n-P-N Transistors, in particular, popular BC547B, 2N3904 and BC549. At the same time, if external device It can work from 5 V, to supply power on the relay with the output 2 GPIO connector. But in this case, we should not forget about the current consumption. Otherwise, the relay can be connected to an external power source in compliance with precautions that exclude hitting external tension On RPI.

Devices with power supply from the power supply

Accessing any schemes or devices directly controlling devices connected to the AC network requires special caution. Most of them simply do not meet safety standards, despite the fact that some manufacturers claim the opposite. A sufficiently safe approach is to find a ready-made solution. remote control The authoritative manufacturer offered by the authoritative supplier in which infrared or is used to control devices that feed on the network. wireless technology. For example, Energenie offers power outlets with radio channel control bundled with a small radio transmitter module (Figure 9) connected directly to the RPI GPIO connector, as well as examples of Python programs.

Relay group, LEDs or other devices

To manage multiple LEDs, relays, or other devices that feed from 12 V and consume less than 200 mA, an ancient (produced more than 25 years) chip ULN2803 can be used. The microcircuit is a set of eight keys based on the Darlington transistor. One of the options for connecting the ULN2803 microcircuit to RPI is shown in Figure 10.

Low Power DC Motors

The optimal solution for managing DC electric motors using RPI is the use of specialized drivers or extension boards, to some of which can be connected by stepper motors or several brushless engines.

5

Hi-Fi audio player based on the Minicomputer "Raspberry PI". Part 1. Power supply for Raspberry PI (5V, 2A)

The C31, R15 chain provides a zero trigger state when the power supply is turned on into the network 220 V.

The shutdown delay is necessary because after the software shutdown, after all GPIO is repaid, 2-3 seconds there is an appeal to the Micheputeter flash memory (the operating system is installed). This is another small problem that must be provided in this power supply.

Software

Program code issuing RPI_OFF signal
! #Include "stdlib.h" #include "bcm2835.h" #define PIN_12 RPI_V2_GPIO_P1_12 #define PIN_07 RPI_V2_GPIO_P1_07 int init_system (void) (if (bcm2835_init ()) return 0; bcm2835_gpio_fsel (PIN_12, BCM2835_GPIO_FSEL_OUTP); // output pin BCM2835_GPIO_FSEL (PIN_07, BCM2835_GPIO_FSEL_Inpt); // As input) Int Main (int argc, char * argv, char * enepv) (if (! init_system ()) Return 1; BCM2835_GPIO_WRITE (PIN_12, HIGH); // (Machine loaded) // Low level expectations (shutdown buttons) while (BCM2835_GPIO_LEV (PIN_07)) Delay (50); System ("PowerOff"); Return 0;)
This code is mainly included. softwareHere he is just as a working example for familiarizing or repetition. Next, you need to add this program to autoload. To do this in the file /etc/rc.localat the end of front EXIT 0. Add:
#! / BIN / SH ...... /ProgramS/Autorun.sh & EXIT 0

The "Programs.zip" project folder can be downloaded in the "Files" section below the article. autorun.sh.- This is our executable script that will run the program. In him:
#! / bin / sh ./programs/project_pin_on/bin/pin12on exit 0

PHIM controller DP408P (1M0880) in a pulsed BP

It is worth paying attention to the wonderful chip-controller of the DP408P (analog 1M0880). DP408P operates at 25 kHz, 1M0880 - 64 kHz. During my tests, attempts to make ideal transformers, etc., it seems that it is impossible to kill the chip. Without snubble chains, I turned it on, overloaded, it's not necessary for it. I recommend chip for those who first decided to build a reverse transducer. I have not burned so much chip. DP408P can be skipped in the old SAMSUNG monitors. Datasheet, unfortunately, not to find on it, but I also had 1M0880 in stock and, as a result of comparison, it turned out that they were almost the same.

The chip turns on as soon as its supply voltage exceeds 15 V. The chip is turned off when the supply voltage falls to 8.5-9 V. That is, after the chip is turned on, the voltage does not have to be 15 V and higher, but preferably.

If the supply voltage exceeds 27 V (25V for 1M0880), the protection and the microcircuit turns off. The next inclusion attempt will be passed only after removal of the power, if the supply voltage drops below 8.5-9 V and again exceed 15 V.

In the process of testing, for example, a freshly changed transformer, it is conveniently powered by PWM from a separate laboratory block Nutrition. It is necessary to remember about the priority of voltages: first high 308 V, then 15 V.

For primary startup, a separate rectifier D5 is used. Due to the R6 and C18, the supply voltage reaches a level of 15 V a little later than the appearance of 308 V. PWM starts, consuming about 20 mA. And if you do not connect the sump winding, C18 is discharged and the microcircuit turns off. Then the capacitor is then charged, and the startup process will repeat again.

At the end, connect the self-type of self-mood. It is necessary to wind the winding so that the voltage 15-17 V was on the minimum load - the load load of the idle force (in my case approx. 0.25 W).

In this power supply, I did not apply homemade transformers, a transformer from the killed AC / DC zipper was applied:


Figure 4. Pulse transformer donors


Putting this adapter some kind of router or a switch, I do not remember already, with the claimed parameters 5V 2A MAX.

The fact is that I could not wind the transformer better than this. As I did not rummaged - emissions when closing the power transistor of the chip were more than a Chinese transformer. Well, okay!

Armed eye

Let's see what happened:


Figure 5.. Oscillogram (PIN-1 IC1), load 2.1a (power transistor).



Fig. 6.. Oscillogram (PIN-1 IC1), load 2.1 A. (emissions cutter)



Figure 7. Oscillogram (PIN-1 IC1), load 50 mA. (Stills of power transistor).



Figure 8. Oscillogram (PIN-1 IC1), load 2.1 A. (38 NS 300 V).

By temperature: Branch resistor with a load of 2.1 a \u003d 50 ° C, DP408 \u003d 37 ° C, transformer \u003d 40 ° C. The temperature measured a contactless thermometer for babies.

And another photo of the design


Figure 9. Power supply - view of the left.


Figure 10.Power supply - bottom view.


Fig. 11.Board A2.

On the image 11 board A2. Three LEDs of different color and below them. In the housing, the button has a glass (see video) so the extreme LEDs swept up to the center. The fee is made by analogy of the native board of the VCR (the body applied from the VCR).

Video

The system is not optimized therefore "Raspberry" is loaded for a long time, and the flash drive with the operating system is slow. Then I will insert a real one

We continue to consider the use of the Raspberry PI computer for home automation. As you remember, in previous releases, we received general information about Raspberry PI, learned how to install and configure the operating system Raspbian., got acquainted with the framework Webiopi.and its capabilities for working with GPIO ports, in particular, how to manage discrete inputs / outputs and the operation of the UART serial port.

Today I will try to introduce you to the general structural scheme of the planned home automation system, which will be created usingRaspberry Pi. (Fig.1).

Fig. one

Home automation system consists of central Serverinterface RS 485. with installed in each room controllers, and to controllers, in turn, are connected all peripherals (various devices Control, control, regulation, protection). The advantage of such a network architecture is that there is no need to pull the wires from each device to the server, and it is enough to connect the controllers to which they are connected, two pairs of wires - one pair is powered by a single pair, and the second is used for the RS 485 interface. In addition, The logic of the work is thinking so that the failure of any controller or even the central server should not affect the performance of the rest of the system. In other words, the architecture of the home automation system must be distributedand decentralized. Similar architecture resembles widely used in commercial projects " smart home»Tire Smart Bus..

As a central server, home automation system is appliedRaspberry PI . It is installed on itWeb server.By which the user from any communication device (smartphone, laptop, tablet) through the browser can receive information about all processes occurring in the house and, accordingly, manage them. Access toWeb. a login and password server can be obtained from home local networkand from the Internet throughWi -Fi router.

To sequential portUART.Raspberry PI through the matching device on the interfaceRS 485 connect controllershaving a necessary set of input / outputs. In addition, toRS 485 connects GSM modem To access the system throughcellular or stationary telephone network In case, at the point where the user is located, it is not possible to get an Internet access. Access in this case is also performed through the password input.

As mentioned earlier, Raspberry PI has its own ports. Gpio.which can be used for various functions. UART GPIO We use to organize the RS 485 interface, while the remaining ports are free. Therefore, it is quite logical that in addition to connecting sensors and actuators to controllers, some elements of the home automation system can be connected directly to the GPIO Raspberry PI ports through buffer device Provided that such elements do not need to lay long communications. For example, it can be an atmospheric pressure sensor or a temperature control sensor with the cooling control of the Raspberry PI itself. On the structural diagram, the direct connection to the Raspberry PI ports is shown through a buffer module. Gpio..

Since in the first stage of the practical implementation of our system, we will organize the port connectionUART RASPBERRY PI to the interface controllerRS. 485, as well as connect actuators directly to the I / O portsGpio. I suggest to start to complete the setting and configuration.Raspberry PI To perform these tasks.

So, if you read the previous three parts of the review, installed the framework Webiopi., tried to control the ports, checked the work of the UART in the two-way metabolism mode through the terminal program, then it remains very little to complete the settings.

We go to the configuration file with the command:

sudo Nano / etc /webiPi /config

and install the following settings [ Gpio](Fig.2)

4 \u003d Out 0

7 \u003d Out 0

8 \u003d Out 0

25 \u003d Out 0

24 \u003d Out 0

Fig. 2.

In chapter [ Http.ServerConfiguration]it is necessary to register a string:

dOC-ROOT \u003d / HOME / PI / MYPROJECT / HTML

It will be the path to the folder that we will then create to store the web interface page index.hTML. Of course, it was possible to create this folder and elsewhere, speaking to her the corresponding path, but in order to avoid confusion and problems in the future, let's adhere to the monotony (Fig.3)

gpio-export \u003d 4, 7, 8, 25, 24

gPIO-POST-VALUE \u003d TRUE

gPIO-POST-FUNCTION \u003d TRUE

device-Mapping \u003d True


Fig. four

In the configuration configuration file completed. Keep them by pressing the keyboard keyCtrl and O., then click ENTER And we leave the teamCtrl and H..

Create on diskRaspberry PI folders for storing our project. For this, and in general, to work with files on the Raspberry Pi disk, you can use the file managerabout which mentioned. The nesting of the folders being created should have the following form:

/ HOME / PI / MyProject / HTML(Fig. 5)


Fig. five

To control the correctness of the executed operations, unpack the archive of the test file in the folder hTML. There must appear file index.hTML. Enter network address Raspberry PI, login and password ( webiopi. / raspberry.). Perform the WEBIPI command to restart:

sudo /etc/init.d/webiopi restart

After that, you must see the test Web interface (Fig. 6). With this interface, you can manage GPIO outputs 4 , 7 , 8 , 24 , 25 Click on the appropriate button. High level At the output is shown orange, low - black. After each click on the button, the output status changes to the opposite. For visual control of the commands performed to these outputs, you can connect LEDs through current-limiting resistors. 300 - 470 Oh..

Fig. 6.

If everything happened, it means that the settings are made correctly. In the next issue of our review, we turn to the practical implementation in the "hardware" of the first stage of the home automation system.

Did you like the article? To share with friends: