Difference between revisions of "Raspberry Relay"
(→Pinout) |
RonanKeryell (talk | contribs) m (Update C++14 to modern C++ since it is expected to change) |
||
(22 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
[[File:RPiRelay.jpg|thumb|300px|alt=The Raspberry Relay board|The Raspberry Relay board]] |
[[File:RPiRelay.jpg|thumb|300px|alt=The Raspberry Relay board|The Raspberry Relay board]] |
||
The Raspberry Relay board makes it possible to control 4 relays using your Raspberry Pi. There are now 3 versions: |
|||
* [http://www.bitwizard.nl/shop/raspberry-pi/rpi-relay Raspberry Relay board] |
|||
* [http://www.bitwizard.nl/shop/raspberry-pi?product_id=148 Raspberry SPI Relay board] |
|||
* [http://www.bitwizard.nl/shop/raspberry-pi?product_id=149 Raspberry Solid State Relay board] |
|||
== Overview == |
== Overview == |
||
The Raspberry Relay board can be connected to a Raspberry Pi using the 26-pin GPIO connector. The relays can be controlled using the Raspberry Pi GPIO pins. Optionally, the Pi can be powered by the micro USB port on the Relay board. This way, the connectors for power, ethernet and USB are on one side. Please note that the polyfuse will be bypassed if the Pi is powered via the Relay board. The polyfuse prevents damage when a short-circuit occurs. |
The Raspberry Relay board can be connected to a Raspberry Pi using the 26-pin GPIO connector. The relays can be controlled using the Raspberry Pi GPIO pins. Optionally, with the old version of the Relay board the Pi can be powered by the micro USB port on the Relay board. This way, the connectors for power, ethernet and USB are on one side. Please note that the polyfuse will be bypassed if the Pi is powered via the Relay board. The polyfuse prevents damage when a short-circuit occurs. If you power your Raspberry Pi with batteries, it is recommended to use the regular power connector, since a short-circuit could damage the battery. The positive side of bypassing the polyfuse is that the board is less sensitive to voltage fluctuations, since the polyfuse induces a 0.2V voltage drop. |
||
== Pinout == |
== Pinout == |
||
Line 11: | Line 16: | ||
| Neutral || Relay 1 out || Neutral || Relay 2 out || Neutral || Relay 3 out || Neutral || Relay 4 out || Neutral || Hot |
| Neutral || Relay 1 out || Neutral || Relay 2 out || Neutral || Relay 3 out || Neutral || Relay 4 out || Neutral || Hot |
||
|} |
|} |
||
XXX Please double check by following the traces or [http://www.bitwizard.nl/contact.php contact us]: we changed the pinout around to have the "hot" on the other side. Double check your version! XXX |
|||
If you want to switch mains, you should connect the 'Hot' wire to pin 10. In EU countries, this is usually the brown wire. The blue wire is the 'Neutral', and should be connected to pin 9. All other wires should be connected in the same way, so 'Neutral' to 'Neutral' and a 'Hot' wire to a relay output pin. |
If you want to switch mains, you should connect the 'Hot' wire to pin 10. In EU countries, this is usually the brown wire. The blue wire is the 'Neutral', and should be connected to pin 9. All other wires should be connected in the same way, so 'Neutral' to 'Neutral' and a 'Hot' wire to a relay output pin. |
||
[[File:Dsc05646_small.jpg|thumb|300px|Example configuration]] |
|||
== Usage == |
== Usage == |
||
There are two versions. One controlled by GPIO pins, the other by SPI. |
|||
=== GPIO version === |
|||
The module can be controlled with the GPIO pins on the Pi. Set a pin high, the relay will switch on and when the pin is low the relay will switch off. The pins are wired as follows: |
The module can be controlled with the GPIO pins on the Pi. Set a pin high, the relay will switch on and when the pin is low the relay will switch off. The pins are wired as follows: |
||
{| border=1 |
{| border=1 |
||
! Relay no. !! Pin number !! Pin name ([http://elinux.org/File:GPIOs.png Broadcom ref.]) !! Pin name ([http://wiringpi.com/pins/ wiringPi]) |
! Relay no. !! Pin number (by [http://elinux.org/File:RPi_P1_header.png this] scheme)!! Pin name ([http://elinux.org/File:GPIOs.png Broadcom ref.]) !! Pin name ([http://wiringpi.com/pins/ wiringPi]) |
||
|- |
|- |
||
| 1 || 11 || GPIO17 || 0 |
| 1 || 11 || GPIO17 || 0 |
||
Line 28: | Line 40: | ||
| 4 || 15 || GPIO22 || 3 |
| 4 || 15 || GPIO22 || 3 |
||
|} |
|} |
||
=== SPI version === |
|||
The module is effectively an "spi DIO", so you control the relays by sending the state of the 4 relays as the low 4 bits to register 0x10 at address 0xa6. |
|||
The rpi_spi_relay has a 4-pin jumper block. Put the jumper on the right side, vertically, and the module is connected to the SPI0 bus. |
|||
Example using [[Bw_tool]] : |
|||
bw_tool -a a6 -W 10:f |
|||
will turn on all 4 relays. |
|||
The SPI version has a jumper block. The pins 1,2 are marked, 3-4 are not. 1 is topright, 2 is top-left if you have the silkscreen on the board right-side-up. 1(top right) is SPI_CS0, the opposite corner (4, bottom left) is SPI_CS1. These signals can be connected to the other two with a jumper. 3, bottom-right is "board SPI CS". 2 top-left is the embedded processor's reset line. Putting a jumper 1-3 along the right of the jumper block will allow you to access the board using rapsberry pi SPI0 bus. Putting the jumper 1-2 along the top of the jumper block will allow you to flash the onboard processor, should that be needed. |
|||
Another modern C++ library and daemon utility for this SPI relay can be found on https://github.com/keryell/BitWizard_SPI_relay |
|||
== Examples == |
== Examples == |
||
Line 67: | Line 96: | ||
== Datasheets == |
== Datasheets == |
||
2A SSR: [http://www.components.omron.com/components/web/pdflib.nsf/0/F1D420C93E86CDB685257201007DD5BA/$file/G3MB_0609.pdf Omron G3MB-202P] |
|||
5A: [http://www.parallax.com/sites/default/files/downloads/27115-Single-Relay-Board-Datasheet.pdf Songle SRD-05VDC] |
|||
10A |
10A: [http://www.omron.com/ecb/products/pdf/en-g5le.pdf Omron G5LE] or [http://www.omron.com/ecb/products/pdf/en-g5la.pdf Omron G5LA] |
Latest revision as of 16:31, 31 December 2021
The Raspberry Relay board makes it possible to control 4 relays using your Raspberry Pi. There are now 3 versions:
Overview
The Raspberry Relay board can be connected to a Raspberry Pi using the 26-pin GPIO connector. The relays can be controlled using the Raspberry Pi GPIO pins. Optionally, with the old version of the Relay board the Pi can be powered by the micro USB port on the Relay board. This way, the connectors for power, ethernet and USB are on one side. Please note that the polyfuse will be bypassed if the Pi is powered via the Relay board. The polyfuse prevents damage when a short-circuit occurs. If you power your Raspberry Pi with batteries, it is recommended to use the regular power connector, since a short-circuit could damage the battery. The positive side of bypassing the polyfuse is that the board is less sensitive to voltage fluctuations, since the polyfuse induces a 0.2V voltage drop.
Pinout
Pin 1 | Pin 2 | Pin 3 | Pin 4 | Pin 5 | Pin 6 | Pin 7 | Pin 8 | Pin 9 | Pin 10 |
---|---|---|---|---|---|---|---|---|---|
Neutral | Relay 1 out | Neutral | Relay 2 out | Neutral | Relay 3 out | Neutral | Relay 4 out | Neutral | Hot |
XXX Please double check by following the traces or contact us: we changed the pinout around to have the "hot" on the other side. Double check your version! XXX
If you want to switch mains, you should connect the 'Hot' wire to pin 10. In EU countries, this is usually the brown wire. The blue wire is the 'Neutral', and should be connected to pin 9. All other wires should be connected in the same way, so 'Neutral' to 'Neutral' and a 'Hot' wire to a relay output pin.
Usage
There are two versions. One controlled by GPIO pins, the other by SPI.
GPIO version
The module can be controlled with the GPIO pins on the Pi. Set a pin high, the relay will switch on and when the pin is low the relay will switch off. The pins are wired as follows:
Relay no. | Pin number (by this scheme) | Pin name (Broadcom ref.) | Pin name (wiringPi) |
---|---|---|---|
1 | 11 | GPIO17 | 0 |
2 | 12 | GPIO18 | 1 |
3 | 13 | GPIO21 (rev 1)/GPIO27 (rev 2) | 2 |
4 | 15 | GPIO22 | 3 |
SPI version
The module is effectively an "spi DIO", so you control the relays by sending the state of the 4 relays as the low 4 bits to register 0x10 at address 0xa6.
The rpi_spi_relay has a 4-pin jumper block. Put the jumper on the right side, vertically, and the module is connected to the SPI0 bus.
Example using Bw_tool :
bw_tool -a a6 -W 10:f
will turn on all 4 relays.
The SPI version has a jumper block. The pins 1,2 are marked, 3-4 are not. 1 is topright, 2 is top-left if you have the silkscreen on the board right-side-up. 1(top right) is SPI_CS0, the opposite corner (4, bottom left) is SPI_CS1. These signals can be connected to the other two with a jumper. 3, bottom-right is "board SPI CS". 2 top-left is the embedded processor's reset line. Putting a jumper 1-3 along the right of the jumper block will allow you to access the board using rapsberry pi SPI0 bus. Putting the jumper 1-2 along the top of the jumper block will allow you to flash the onboard processor, should that be needed.
Another modern C++ library and daemon utility for this SPI relay can be found on https://github.com/keryell/BitWizard_SPI_relay
Examples
Shell
- First, install WiringPi
- Set the GPIO modes:
gpio mode 0 out gpio mode 1 out gpio mode 2 out gpio mode 3 out
- Enabling a relay:
gpio write X 1
where X is the relay number (0 to 3)
- Disabling a relay:
gpio write X 0
For more information about the gpio utility, see this page
Python
- Install the RPi.GPIO Python module:
sudo apt-get install python-rpi.gpio
- start the python interpreter
python
- or create a script
nano gpio.py
- The Python script should look like this:
#!/usr/bin/env python #import the GPIO library import RPi.GPIO as GPIO #select the board mode pin numbering GPIO.setmode(GPIO.BOARD) #set the needed GPIO pins as output GPIO.setup(11, GPIO.OUT) #relay 1 GPIO.setup(12, GPIO.OUT) #relay 2 GPIO.setup(13, GPIO.OUT) #relay 3 GPIO.setup(15, GPIO.OUT) #relay 4 #toggle the relays GPIO.output(13,True) #Enable relay 3 GPIO.output(11,False) #Disable relay 1
- For more information on the RPi.GPIO module, see this page.
Datasheets
2A SSR: Omron G3MB-202P
5A: Songle SRD-05VDC
10A: Omron G5LE or Omron G5LA