#!/usr/bin/python import smbus import time import sys #DEVICE_ADDRESS = 0x24 #7 bit address (will be left shifted to add the read write bit) DEVICE_REG_MODE1 = 0x00 DEVICE_REG_LEDOUT0 = 0x1d try: sys.argv[1] sys.argv[2] except: print "You need to send in command line arguments" else: bus = smbus.SMBus(1) # 0 = /dev/i2c-0 (port I2C0), 1 = /dev/i2c-1 (port I2C1) #DEVICE_ADDRESS = sys.argv[1] #NEW_ADDRESS = sys.argv[2] DEVICE_ADDRESS = hex(int(sys.argv[1], 16)) NEW_ADDRESS = hex(int(sys.argv[2], 16)) #hexadd = hex(int(sys.argv[1])) #intadd = int(sys.argv[2], 16) #hexint = hex(int(sys.argv[2], 16)) #print "hexadd = " + str(hexadd) print "DEVICE_ADDRESS = " + str(DEVICE_ADDRESS) print "NEW_ADDRESS = " + str(NEW_ADDRESS) #Write a single register bus.write_byte_data(DEVICE_ADDRESS, 1, NEW_ADDRESS) time.sleep(2) bus.write_byte_data(DEVICE_ADDRESS, 6, DEVICE_REG_MODE1) #bus.write_byte_data(DEVICE_ADDRESS, 1, 0x23) #time.sleep(2) #bus.write_byte_data(DEVICE_ADDRESS, 6, DEVICE_REG_MODE1)