In this tutorial, we will show how to interface 2 Channel relay shield from controleverything.com with onion omega.
we will be using following hardware.
1. Onion Omega
2. Onion Omega I²C adapter
Onion Omega - is a small size computer but very powerful. It has an onboard WiFi, UART, I2C, SPA, GPIO, USB , and Ethernet connection. It supports all major programming language, which makes so flexible and easy to work with. In this
tutorial, we will control 2 Channel Realy board using Onion Omega UI and Python Script. Onion Omega I²C adapter - is an interface board which will go between relay board and the onion omega. It has a USB port and I²C level shifter. 2 Channel Relay Shield -- is a relay board which has 2 SPDT relay and 6 GPIO. This board also has an onboard power supply, this power supply will provide the power to the Onion omega as well as the MCP23008 circuit on the relay board. the relay board has an MCP23008 digital io chip, this chip has 8 digital IO pins and 2 digital IO are used to control the relay and rest 6 are general purpose io lines. these 6 io lines are connected to screw terminal which gives an easy access to these pins.
Step 1: Onion Omega Relay Shield With Onion Omega UI
After connecting the relay shield, connect the onion omega with your computer.
to to that click on your wifi icon and look for onion omega network, connect your computer to the onion omega. after connecting to the onion omega, open your browser and go to 192.168.3.1. after login, you will see Onion Omega UI.
Click on relay control.
the I²C address of my board is 0x20 so I set the relay I²C address to 0x20, you can set it according to your relay board.
Now to turn on the relay 1, click on R1 and to turn on the relay 2 click on R2.
After turning both relays on you will that the led R1,R2 are also on.
Step 2: Onion Omega Relay Control Using Python Script
The python script to control the relay shield can be found here.
in the code, we need to do few basic things.
1. import the onion omega I²C lib
from OmegaExpansion import onionI2C
2. Initialize the I²C bus.
i2c = onionI2C.OnionI2C()
3. Initialize the MCP23008 and set the GPIO Pins as output
i2c.writeByte(0x20, 0x00, 0x00)
# Distributed with a free-will license.
# Use it any way you want, profit or free, provided it fits in the licenses of its associated works. # MCP23008 # This code is designed to work with the MCP23008_I2CR8G5LE_10A I2C relay controller available from ControlEverything.com. # https://www.controleverything.com/content/Relay-Controller?sku=MCP23008_... from OmegaExpansion import onionI2C import time # Get I2C bus i2c = onionI2C.OnionI2C() # MCP23008 address, 0x20(32) # Select IODIR register, 0x00(00) # 0x00(00) All pins are configured as outputs i2c.writeByte(0x20, 0x00, 0x00) time.sleep(0.5) # MCP23008 address, 0x20(32) # Select GPIO register, 0x09(09) # 0xFF(255) All pins are set to Logic HIGH i2c.writeByte(0x20, 0x09, 0xFF) # Output data to screen print "Turning all Relays ON"