- Sun May 21, 2017 2:10 pm
#194953
Hello,
I looking for a python sample for sparkfun module MAG3110, Does anyone know where i can find an example?
used Pycom Sipy and i can´t get info of sensor using i2c
There is my code for add more info,
Thanks
I looking for a python sample for sparkfun module MAG3110, Does anyone know where i can find an example?
used Pycom Sipy and i can´t get info of sensor using i2c
There is my code for add more info,
Thanks
Code: Select all
start_val = 2590 # 259.0 degrees
i2c = I2C(0, I2C.MASTER, baudrate=100000, pins=('P9', 'P10'))
addr = i2c.scan()
if addr:
addr = addr[0]
else:
addr = 0x21 # use default address
class Sensor():
def __init__(self, i2c, addr):
self.i2c = i2c
self.addr = addr
self.val = 0
def read(self):
self.i2c.writeto(addr, bytes([0x41])) # query for heading
time.sleep_ms(10)
# read 2 bytes
raw_val = self.i2c.readfrom(self.addr, 2)
# bitshift first byte 8 places to the left
self.val = raw_val[0] * 2**8 + raw_val[1]
return self.val
sensor = Sensor(i2c, addr)
other_val = sensor.read()