[Solved]Python Relay Expansion help
-
This post is deleted!
-
Is your expansion working if you use the console ?
-
@Rudy-Trujillo
To install everything required:opkg update opkg install python-light pyRelayExp
And here is a short script that just tests the functionality:
from OmegaExpansion import relayExp import time import sys # check the arguments if len(sys.argv) != 2: print 'ERROR: expected addr offset:' print sys.argv[0], '<addr offset>' exit() addr = int(sys.argv[1]) print 'Starting to use relay-exp functions on addr offset', addr relayExp.setVerbosity(0) # check initialization ret = relayExp.checkInit(addr) print "checking if initialized: ", ret # initialize the relay-exp ret = relayExp.driverInit(addr) print "Result from relayDriverInit: ", ret if (ret != 0): exit() # check initialization ret = relayExp.checkInit(addr) print "checking if initialized: ", ret time.sleep(1) # set channel 0 to on ret = relayExp.setChannel(addr, 0, 1) print "Result from relaySetChannel: ", ret if (ret != 0): exit() time.sleep(2) # set both channels to on ret = relayExp.setAllChannels(addr, 1) print "Result from relaySetAllChannels: ", ret if (ret != 0): exit() time.sleep(2) # set channel 0 to off ret = relayExp.setChannel(addr, 0, 0) print "Result from relaySetChannel: ", ret if (ret != 0): exit() time.sleep(2) print "Done"
I'll post examples for all three modules later this week!
EDIT: Note that the address argument that specifies the offset to add to the base address of 0x20. Follow the address table on the Wiki.
-
This post is deleted!
-
@Rudy-Trujillo
Once the Relay Expansion hardware is initialized once, it will remain initialized. I'm guessing the screenshot above was not from the first time the script was ran? If that's the case, everything seems to be running correctly.
(You can make thedriverInit
call dependant on thecheckInit
return value to avoid unnecessary initialization in your real program)Here's my output when I run it right after plugging in the Relay Expansion:
root@Omega-18C2:~# python relay-test.py 7 Starting to use relay-exp functions on addr offset 7 checking if initialized: 0 > Initializing Relay Expansion chip Result from relayDriverInit: 0 checking if initialized: 1 > Setting RELAY0 to ON Result from relaySetChannel: 0 > Setting both RELAYS to ON Result from relaySetAllChannels: 0 > Setting RELAY0 to OFF Result from relaySetChannel: 0 Done
In general, the functions return 0 to indicate success and 1 to indicate failure. The
checkInit
function is special, take a look at this section from the Relay Expansion Library wiki for more info.
-
This post is deleted!
-
Small Update:
Example python code has been added to the i2c-exp-driver repo.The examples are also linked in the wiki articles for the Relay, PWM, and OLED Libraries.
Edit: Updated the links
-
@Lazar-Demin
Your link to the address table on the Wiki is a dead link. Can you update it please?
-
@Stephen-Tunney I may be wrong, but I think the link(s) you are looking for in relation to Relay, PWM and OLED python libraries are:
-
Awesomesauce!!! Thank you, @Kit-Bishop.