lsm303dlh_mag_simpletest.py
1 """ Display magnetometer data once per second """ 2 3 import time 4 import board 5 import busio 6 import adafruit_lsm303dlh_mag 7 8 i2c = busio.I2C(board.SCL, board.SDA) 9 sensor = adafruit_lsm303dlh_mag.LSM303DLH_Mag(i2c) 10 11 while True: 12 mag_x, mag_y, mag_z = sensor.magnetic 13 14 print( 15 "Magnetometer (gauss): ({0:10.3f}, {1:10.3f}, {2:10.3f})".format( 16 mag_x, mag_y, mag_z 17 ) 18 ) 19 print("") 20 time.sleep(1.0)