lsm303_simpletest.py
1 """ Display both accelerometer and magnetometer data once per second """ 2 3 import time 4 import board 5 import busio 6 import adafruit_lsm303 7 8 i2c = busio.I2C(board.SCL, board.SDA) 9 sensor = adafruit_lsm303.LSM303(i2c) 10 11 while True: 12 acc_x, acc_y, acc_z = sensor.acceleration 13 mag_x, mag_y, mag_z = sensor.magnetic 14 15 print('Acceleration (m/s^2): ({0:10.3f}, {1:10.3f}, {2:10.3f})'.format(acc_x, acc_y, acc_z)) 16 print('Magnetometer (gauss): ({0:10.3f}, {1:10.3f}, {2:10.3f})'.format(mag_x, mag_y, mag_z)) 17 print('') 18 time.sleep(1.0)