The difference between Raspberry Pi and Arduino
Among fans of radio engineering and electronics, everyone has heard about the existence of such devices as Arduino and Raspberry Pi. Both boards are used to solve similar problems, both are great for beginners. But in comparison with Arduino Raspberry is a multifunctional computer on which the operating system can be launched.
Of the main differences, you can allocate a clock speed - Raspberry runs 40 times faster than Arduino, and the amount of RAM - Raspberry memory more about 128,000 times. Due to the simplicity of management and use, it is preferable to develop hardware projects on Arduino. Arduino can work with any sensors or chips, and Raspberry Pi is not so flexible, additional hardware devices are required to work with sensors. Raspberry Pi is very demanding on power, the voltage should be strictly 5 V at the input, while for Arduino the recommended power is 7-12 V, which stabilizes to 5 V.
An important difference is in the environment in which the program is written. With Arduino IDE it's much easier to work than with Linux. Installation of libraries for writing a program is required for both systems, but the code on Arduino will be written easier and shorter.
Raspberry Pi can be used in multitasking mode, just like a regular computer. At the same time, several programs can run in the background.
To expand the possibilities, you can share both cards. To control the sensors and sensors, use Arduino, and leave complex computational tasks for Raspberry Pi.
GPIO description
The number of ports in the older and new Raspberry Pi models is different -model A and model B are equipped with 26 general purpose GPIO outputs, in the future versions the number of pins is increased to 40.
There are several types of designations of conclusions:
BCM - number outputs Broadcom microprocessor. Used when working with special packages Rpi.GPIO. In a large number of projects this numbering is used.
WiringPi - numbering contacts for the Wiring Pi package. This is a library, similar to the libraries for Arduino, for working with GPIO contacts.
The usual digital numbering of the outputs on the board itself.
The location of the contacts is shown in the figure. In the picture for convenience, the last 14 contacts are separated - these are the new outputs that were added in the new versions of the board.
GPIO Contact Description
Output number | BCM | WiringPi | Contact Description |
1 | 3v3 | Feed contact for 3.3V | |
2 | 5v | Feed contact for 5 V | |
3 | BCM2 | 8 | SDA |
4 | 5v | Feed contact for 5 V | |
5 | BCM3 | 9 | SCL |
6th | GND | Earth | |
7th | BCM4 | 7th | GPCLK0 |
8 | BCM14 | 15 | TXD - responsible for data transfer |
9 | GND | Earth | |
10 | BCM15 | 16 | RXD - responsible for receiving data |
eleven | BCM17 | 0 | General Purpose Output |
12 | BCM18 | 1 | PCM_C - used in conjunction with the PWM method. |
13 | BCM27 | 2 | General contact |
14 | GND | Earth | |
15 | BCM22 | 3 | General contact |
16 | BCM23 | 4 | General contact |
17th | 3V3 | Supply voltage 3.3V | |
18 | BCM24 | 5 | General contact |
19 | BCM10 | 12 | MOSI |
20 | GND | Earth | |
21 | BCM9 | 13 | MISO |
22 | BCM25 | 6th | General contact |
23 | BCM11 | 14 | SCLK |
24 | BCM8 | 10 | CS0 |
25 | GND | Earth | |
26th | BCM7 | eleven | CS1 |
27th | BCM0 | thirty | ID_SD |
28 | BCM1 | 31 | ID_SD |
29 | BCM5 | 21 | General contact |
thirty | GND | Earth | |
31 | BCM6 | 22 | General contact |
32 | BCM12 | 26th | General contact |
33 | BCM13 | 23 | General contact |
34 | GND | Earth | |
35 | BCM19 | 24 | MISO |
36 | BCM16 | 27th | General contact |
37 | BCM26 | 25 | General contact |
38 | BCM20 | 28 | MOSI |
39 | GND | Earth | |
40 | BCM21 | 29 | SCLK |
Conclusions earth, voltage and other similar can be used any that will be more convenient in a particular project. It is important to ensure that the voltage on the GPIO is 3.3V, otherwise the contact may be disrupted.
Among the general purpose terminals there are UART contacts (on the eighth and tenth contacts). They allow the interaction of Arduino and Raspberry Pi. Also 4 outputs support I2C, the main task of which is communication with peripherals. For verification in the code, you need to add lines
sudo apt-get install i2c-tools
sudo i2cdetect -y 1
To access I2C, you need to connect the smbus library.
SPI supports 11 general purpose terminals. With this interface, you can configure the connection of multiple devices using a single contact group.
Project example: LED flashing
To work, you will need a Raspberry Pi board, LED, a 200 ohm resistor and connecting wires. The anode of the LED (long leg) must be connected through a resistor to one of the digital terminals, for example GPIO24, the cathode (short leg) to the ground. The layout of the connection is shown in the figure. The resistor in this circuit is necessary in order to protect the LED from burning out. You can choose the correct nominal value using Ohm's law R = U / I. The board is powered by 3.3V. The nominal value, which will be obtained by the formula - the minimum, it is possible to choose the resistance more, but in this case the brightness of the LED will be somewhat lower.
Now we need to write a program. The code will be written in the installed version of Python 2. To do this, open the Python 2 environment (IDLE) and click on the "new file".
In the editor window, you need to write a sketch that will cause the LED to light up for 10 seconds and turn it off. First, you need to choose the numbering of the outputs. As mentioned above, there are several types of numbering. In this case, the numbering of BCM will be used.
The code itself looks like this:
1 2 3 4 5 6th 7th 8 9 10 eleven 12 13 14 15 | from RPi import GPIO from time import sleep //первые 2 строки включают библиотеки для совместной работы с GPIO и sleep GPIO.setmode(GPIO.BCM) //этой строкой выбирается нумерация контактов GPIO.setup(24, GPIO.OUT) //чтобы управлять светодиодом или другим устройством, нужно задать OUT. Для того чтобы считывать сигнал сенсора, нужно ввести IN. GPIO.output(24, True) //подача истины на контакты sleep(10) //светодиод загорается на 10 секунд, ожидание GPIO.output(24, False) GPIO.cleanup() //сброс всех настроек портов, чтобы они не мешали следующей программе. |
You need to press the start of the program using F5 or the Run / Run Module menu.
The code can be slightly changed so that the LED turns on and off at a certain frequency. To do this, add the while statement instead of the GPIO.output and Sleep lines. In the loop, you specify the frequency with which the LED will flash. In this case, it will flash once every 1 second.
1 2 3 4 5 6th 7th 8 9 | while True: GPIO.output(24, True) sleep(1) GPIO.output(24, False) sleep(1) |
The big drawback of such a program is that it will be repeated indefinitely and it will not be possible to stop it using the regular method. To do this, you must enter an additional design that interrupts the work when typing Ctrl + C on the keyboard.
1 2 3 4 5 6th 7th 8 9 10 eleven 12 13 14 15 | try: while True: GPIO.output(24, True) sleep(0.5) GPIO.output(24, False) sleep(0.5) except KeyboardInterrupt: print 'program stop' |
The program should be saved by pressing ctrl + S. Then you need to press F5, the LED will start flashing at a frequency of once per second. To stop the program, press ctrl + C.
Post a Comment