From 83a2b1c65517566003f71b3decb639c2de6b641a Mon Sep 17 00:00:00 2001 From: ladyada Date: Mon, 13 Jul 2020 12:39:33 -0400 Subject: [PATCH 1/3] Added i2c-gpio example --- examples/bno055_i2c-gpio_simpletest.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 examples/bno055_i2c-gpio_simpletest.py diff --git a/examples/bno055_i2c-gpio_simpletest.py b/examples/bno055_i2c-gpio_simpletest.py new file mode 100644 index 0000000..1fe78c0 --- /dev/null +++ b/examples/bno055_i2c-gpio_simpletest.py @@ -0,0 +1,21 @@ +import time +import board +from adafruit_extended_bus import ExtendedI2C as I2C +import adafruit_bno055 + +# Create library object using our Extended Bus I2C port +i2c = I2C(1) # Device is /dev/i2c-1 +sensor = adafruit_bno055.BNO055_I2C(i2c) + +while True: + print("Temperature: {} degrees C".format(sensor.temperature)) + print("Accelerometer (m/s^2): {}".format(sensor.acceleration)) + print("Magnetometer (microteslas): {}".format(sensor.magnetic)) + print("Gyroscope (rad/sec): {}".format(sensor.gyro)) + print("Euler angle: {}".format(sensor.euler)) + print("Quaternion: {}".format(sensor.quaternion)) + print("Linear acceleration (m/s^2): {}".format(sensor.linear_acceleration)) + print("Gravity (m/s^2): {}".format(sensor.gravity)) + print() + + time.sleep(1) From f750d88bc17734c142d34ef570c484c50cf55be5 Mon Sep 17 00:00:00 2001 From: ladyada Date: Mon, 13 Jul 2020 12:42:39 -0400 Subject: [PATCH 2/3] Formatting --- examples/bno055_i2c-gpio_simpletest.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/examples/bno055_i2c-gpio_simpletest.py b/examples/bno055_i2c-gpio_simpletest.py index 1fe78c0..a0957fd 100644 --- a/examples/bno055_i2c-gpio_simpletest.py +++ b/examples/bno055_i2c-gpio_simpletest.py @@ -1,10 +1,19 @@ +""" +This example demonstrates how to instantiate the +Adafruit BNO055 Sensor using this library and just +the I2C bus number. +This example will only work on a Raspberry Pi +and does require the i2c-gpio kernel module to be +installed and enabled. Most Raspberry Pis will +already have it installed. +""" + import time -import board from adafruit_extended_bus import ExtendedI2C as I2C import adafruit_bno055 # Create library object using our Extended Bus I2C port -i2c = I2C(1) # Device is /dev/i2c-1 +i2c = I2C(1) # Device is /dev/i2c-1 sensor = adafruit_bno055.BNO055_I2C(i2c) while True: From 2b358f2958ba50f20a874777b3831a6496555a47 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 13 Jul 2020 13:31:05 -0400 Subject: [PATCH 3/3] Added better docs --- examples/bno055_i2c-gpio_simpletest.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/bno055_i2c-gpio_simpletest.py b/examples/bno055_i2c-gpio_simpletest.py index a0957fd..19ff0ef 100644 --- a/examples/bno055_i2c-gpio_simpletest.py +++ b/examples/bno055_i2c-gpio_simpletest.py @@ -5,14 +5,19 @@ This example will only work on a Raspberry Pi and does require the i2c-gpio kernel module to be installed and enabled. Most Raspberry Pis will -already have it installed. +already have it installed, however most do not +have it enabled. You will have to manually enable it """ import time from adafruit_extended_bus import ExtendedI2C as I2C import adafruit_bno055 +# To enable i2c-gpio, add the line `dtoverlay=i2c-gpio` to /boot/config.txt +# Then reboot the pi + # Create library object using our Extended Bus I2C port +# Use `ls /dev/i2c*` to find out what i2c devices are connected i2c = I2C(1) # Device is /dev/i2c-1 sensor = adafruit_bno055.BNO055_I2C(i2c)