Skip to content

Instantly share code, notes, and snippets.

@pavelmetrokhin
Created December 8, 2017 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavelmetrokhin/d91fd5a7cadb2c273d27e30816f32977 to your computer and use it in GitHub Desktop.
Save pavelmetrokhin/d91fd5a7cadb2c273d27e30816f32977 to your computer and use it in GitHub Desktop.
A python program to request and receive the data back from the slave (arduino)
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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment