Skip to content

Instantly share code, notes, and snippets.

@DamianZaremba
Created December 27, 2013 15:59
Show Gist options
  • Save DamianZaremba/8148963 to your computer and use it in GitHub Desktop.
Save DamianZaremba/8148963 to your computer and use it in GitHub Desktop.
Multiple relays on the skpang 4ch relay board
You can switch multiple relays on the same was as single relays – it’s just a different value passed.
If you think of the relays as 1, 2, 4, 8 then it makes sense. Passing these values directly will turn on the relays singularly, something like
for relay in [1, 2, 4, 8]:
bus.write_byte_data(0×20,0×09,relay)
time.sleep(1)
will step though all the relays (this is what the test_relays script does).
If you want to switch multiple relays on, add the numbers together and use that. For example:
Relay 1+2 – 1+2 = 3
Relay 2+3 – 2+4 = 6
Relay 1+2+3 – 1+2+4 = 7
Relay 1+2+3+4 – 1+2+4+8 = 15
Relay 1+4 – 1+8 = 9
Relay 3+4 – 4+8 = 12
etc…
This should give you control of all 16 combinations. For reference 0/16 is all off, 15 is all on (anything higher than 16 will cycle back around).
Hope this helps!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment