Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from OmegaExpansion import onionI2C
- #initializing I2C communication
- i2c = onionI2C.OnionI2C(0)
- #initializing Slave's device address and a degree sign for printing
- devAddres = 0x08
- degree = unichr(176)
- #reading and storing the value of the 0x00 register
- size = 1
- addr = 0x00
- val_cel_int =i2c.readBytes(devAddres, addr, size)
- #reading and storing the value of the 0x01 register
- size = 1
- addr = 0x01
- val_cel_frac =i2c.readBytes(devAddres, addr, size)
- #reading and storing the value of the 0x02 register
- size = 1
- addr = 0x02
- val_far_int = i2c.readBytes(devAddres, addr, size)
- #reading and storing the value of the 0x03 register
- size = 1
- addr = 0x03
- val_far_frac =i2c.readBytes(devAddres, addr, size)
- #formating the celsius and fahrenheit values into a single variable
- celsius = "%d.%02d"%(val_cel_int[0], val_cel_frac[0])
- fahrenheit = "%d.%02d"%(val_far_int[0], val_far_frac[0])
- #printing the temperature readings
- print "Celsius: ", celsius + degree + "C"
- print "Fahrenheit: ", fahrenheit + degree + "F"
Add Comment
Please, Sign In to add comment