Simple test

Ensure your device works with this simple test.

examples/bmi160_simpletest.py
import time
import board
import bmi160 as BMI160


i2c = board.I2C()  # uses board.SCL and board.SDA
bmi = BMI160.BMI160(i2c)

while True:
    accx, accy, accz = bmi.acceleration
    print("x:{:.2f}m/s2, y:{:.2f}m/s2, z{:.2f}m/s2".format(accx, accy, accz))
    gyrox, gyroy, gyroz = bmi.gyro
    print("x:{:.2f}°/s, y:{:.2f}°/s, z{:.2f}°/s".format(gyrox, gyroy, gyroz))
    print()
    time.sleep(0.5)

Gyro Simple Test

Simple test for the gyro functionality

examples/bmi160_gyro_simpletest.py
import time
import board
import bmi160 as BMI160


i2c = board.I2C()  # uses board.SCL and board.SDA
bmi = BMI160.BMI160(i2c)


while True:
    gyrox, gyroy, gyroz = bmi.gyro
    print("x:{:.2f}°/s, y:{:.2f}°/s, z{:.2f}°/s".format(gyrox, gyroy, gyroz))
    print()
    time.sleep(0.5)

Acceleration Data Range

Example showing how to change the acceleration data range

examples/bmi160_acce_datarange.py
import time
import board
import bmi160 as BMI160


i2c = board.I2C()  # uses board.SCL and board.SDA
bmi = BMI160.BMI160(i2c)

bmi.acceleration_range = BMI160.ACCEL_RANGE_4G

while True:
    for data_range in BMI160.acc_range_values:
        print("Current Acceleration Data Rate: ", bmi.acceleration_range)
        for _ in range(10):
            accx, accy, accz = bmi.acceleration
            print("x:{:.2f}m/s2, y:{:.2f}m/s2, z{:.2f}m/s2".format(accx, accy, accz))
            print()
            time.sleep(0.5)
        bmi.acceleration_range = data_range

Acceleration Data Rate

Example showing how to change the acceleration data rate

examples/bmi160_acc_datarate.py
import time
import board
import bmi160 as BMI160


i2c = board.I2C()  # uses board.SCL and board.SDA
bmi = BMI160.BMI160(i2c)

bmi.acceleration_output_data_rate = BMI160.BANDWIDTH_25_32

while True:
    for data_rate in BMI160.bandwidth_values:
        print("Current Acceleration Data Rate: ", bmi.acceleration_output_data_rate)
        for _ in range(10):
            accx, accy, accz = bmi.acceleration
            print("x:{:.2f}m/s2, y:{:.2f}m/s2, z{:.2f}m/s2".format(accx, accy, accz))
            print()
            time.sleep(0.5)
        bmi.acceleration_output_data_rate = data_rate

Gyro Data Range

Example showing how to change the gyro data range

examples/bmi160_gyro_range.py
import time
import board
import bmi160 as BMI160


i2c = board.I2C()  # uses board.SCL and board.SDA
bmi = BMI160.BMI160(i2c)

bmi.gyro_range = BMI160.GYRO_RANGE_500

while True:
    for data_range in BMI160.gyro_values:
        print("Current Gyro Data Range: ", bmi.gyro_range)
        for _ in range(10):
            gyrox, gyroy, gyroz = bmi.gyro
            print("x:{:.2f}°/s, y:{:.2f}°/s, z{:.2f}°/s".format(gyrox, gyroy, gyroz))
            print()
            time.sleep(0.5)
        bmi.gyro_range = data_range

Gyro Data Rate

Example showing how to change the gyro data rate

examples/bmi160_gyro_datarate.py
import time
import board
import bmi160 as BMI160


i2c = board.I2C()  # uses board.SCL and board.SDA
bmi = BMI160.BMI160(i2c)

bmi.gyro_output_data_rate = BMI160.BANDWIDTH_200

while True:
    for data_rate in BMI160.gyro_bandwidth_values:
        print("Current Gyro Data Range: ", bmi.gyro_output_data_rate)
        for _ in range(10):
            gyrox, gyroy, gyroz = bmi.gyro
            print("x:{:.2f}°/s, y:{:.2f}°/s, z{:.2f}°/s".format(gyrox, gyroy, gyroz))
            print()
            time.sleep(0.5)
        bmi.gyro_output_data_rate = data_rate

Temperature

Example using the temperature from the sensor

examples/bmi160_temperature.py
import time
import board
import bmi160 as BMI160


i2c = board.I2C()  # uses board.SCL and board.SDA
bmi = BMI160.BMI160(i2c)

while True:
    print(f"Temperature {bmi.temperature:.2f}°C")
    print()
    time.sleep(0.5)