#!/usr/bin/python import smbus import time import sys DEVICE_ADDRESS1 = 0x21 #7 bit address (will be left shifted to add the read write bit) DEVICE_ADDRESS2 = 0x22 #7 bit address (will be left shifted to add the read write bit) DEVICE_ADDRESS3 = 0x23 #7 bit address (will be left shifted to add the read write bit) try: sys.argv[1] 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) #Write a single register #bus.write_byte(DEVICE_ADDRESS1, 0) soil_cap = bus.read_byte_data(DEVICE_ADDRESS1, 0) soil_cap2 = bus.read_i2c_block_data(DEVICE_ADDRESS1,0) #bus.write_byte(DEVICE_ADDRESS1, 5) temp = bus.read_byte_data(DEVICE_ADDRESS1, 5) #temp2 = bus.read_i2c_block_data(DEVICE_ADDRESS1, 5) #bus.write_byte_data(DEVICE_ADDRESS2, 3, 0) bus.write_byte(DEVICE_ADDRESS1, 3) #time.sleep(4) light = bus.read_byte_data(DEVICE_ADDRESS1, 4) #light2 = bus.read_i2c_block_data(DEVICE_ADDRESS1, 4) #print "All Soil 1 = " + str(soil_cap2) #print "All Temp 1 = " + str(temp2) #print "All Light 1 = " + str(light2) print "soil_cap 1= " + str(soil_cap) print "temp 1 = " + str(temp) print "light 1 = " + str(light) print "" soil_cap = bus.read_byte_data(DEVICE_ADDRESS2, 0) soil_cap2 = bus.read_i2c_block_data(DEVICE_ADDRESS2,0) temp = bus.read_byte_data(DEVICE_ADDRESS2, 5) #bus.write_byte_data(DEVICE_ADDRESS2, 3, 0) bus.write_byte(DEVICE_ADDRESS2, 3) #time.sleep(4) light = bus.read_byte_data(DEVICE_ADDRESS2, 4) #print "All Data 2 = " + str(soil_cap2) print "soil_cap 2 = " + str(soil_cap) print "temp 2 = " + str(temp) print "light 2 = " + str(light) print "" soil_cap = bus.read_byte_data(DEVICE_ADDRESS3, 0) soil_cap2 = bus.read_i2c_block_data(DEVICE_ADDRESS3,0) temp = bus.read_byte_data(DEVICE_ADDRESS3, 5) #bus.write_byte_data(DEVICE_ADDRESS3, 3, 0) bus.write_byte(DEVICE_ADDRESS3, 3) #time.sleep(6) light = bus.read_byte_data(DEVICE_ADDRESS3, 4) #print "All Data 3 = " + str(soil_cap2) print "soil_cap 3 = " + str(soil_cap) print "temp 3 = " + str(temp) print "light 3 = " + str(light)