get the current status of the Qwiic Relay. The relay responds with a 1 for on and a 0 for off. Default Qwiic relay address is 0x18. """ from time import sleep import board import busio import sparkfun_qwiicrelay # Create bus object using our board's I2C port i2c = busio.I2C(board.SCL, board.SDA) # Create relay object relay = sparkfun_qwiicrelay.Sparkfun_QwiicRelay(i2c) print('Qwiic Relay Example 4 Get Relay Status') # Check if connected if relay.connected: print('Relay connected.') else: print('Relay does not appear to be connected. Please check wiring.') exit() print('Type Ctrl-C to exit program.') try: while True: relay.relay_on()
try: # check to see if hex or decimal arguement if '0x' in sys.argv[1]: i2c_address = int(sys.argv[1], 16) else: i2c_address = int(sys.argv[1]) except ValueError: print('Ignoring invalid arguement: ' + str(sys.argv[1])) # Show the initial address print('Current i2c address = ' + str(i2c_address) + ' [' + hex(i2c_address) + ']') # Create library object using our Bus I2C port i2c = busio.I2C(board.SCL, board.SDA) relay = sparkfun_qwiicrelay.Sparkfun_QwiicRelay(i2c, i2c_address) if relay.connected: print('Qwiic Relay Example.') else: # if we can't connecct, something is wrong so just quit print('Relay does not appear to be connected. Please check wiring.') exit() print('Address: ' + str(i2c_address) + ' [' + hex(i2c_address) + ']') text = input('Enter a new I2C address (as a decimal from 8 to 119 or hex 0x08 to 0x77):') # check to see if hex or decimal value if '0x' in text: new_address = int(text, 16)