Skip to content

Commit 615130d

Browse files
add change_address method to relay driver
1 parent 46edc80 commit 615130d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

qwiic_relay.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@
8686
QUAD_SOLID_STATE_RELAY_DEFUALT_ADDR,
8787
QUAD_SOLID_STATE_RELAY_JUMPER_CLOSE_ADDR]
8888

89+
# Define commands for changing i2c address to
90+
SINGLE_CHANGE_ADDRESS = 0x03
91+
QUAD_CHANGE_ADDRESS = 0xC7
92+
8993
# Define the register offsets of each relay
9094
RELAY_ONE = 1
9195
RELAY_TWO = 2
@@ -209,6 +213,23 @@ def set_relay_on(self, relayNum=None):
209213
# set_relay_off(relayNum)
210214
#
211215
# Turn's off a specific relay number, if we're using a single relay, do not pass in a relay number.
216+
217+
def change_address(self, newAddress, singleRelay=True):
218+
"""
219+
Change the I2C address of the relay
220+
221+
:param: The new address to change to
222+
:param: If we're changing the address of a single or quad relay
223+
"""
224+
if (newAddress < 0x07) or (newAddress > 0x78):
225+
return
226+
227+
if singleRelay:
228+
return self._i2c.writeByte(self.address, SINGLE_CHANGE_ADDRESS, newAddress)
229+
else:
230+
return self._i2c.writeByte(self.address, QUAD_CHANGE_ADDRESS, newAddress)
231+
232+
self.address = newAddress
212233

213234
def set_relay_off(self, relayNum=None):
214235
"""

0 commit comments

Comments
 (0)