Skip to content

Commit 9e5371d

Browse files
authored
Merge pull request #54 from adafruit/i2c-gpio_example
Added i2c-gpio example
2 parents d8ad1e6 + 2b358f2 commit 9e5371d

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
This example demonstrates how to instantiate the
3+
Adafruit BNO055 Sensor using this library and just
4+
the I2C bus number.
5+
This example will only work on a Raspberry Pi
6+
and does require the i2c-gpio kernel module to be
7+
installed and enabled. Most Raspberry Pis will
8+
already have it installed, however most do not
9+
have it enabled. You will have to manually enable it
10+
"""
11+
12+
import time
13+
from adafruit_extended_bus import ExtendedI2C as I2C
14+
import adafruit_bno055
15+
16+
# To enable i2c-gpio, add the line `dtoverlay=i2c-gpio` to /boot/config.txt
17+
# Then reboot the pi
18+
19+
# Create library object using our Extended Bus I2C port
20+
# Use `ls /dev/i2c*` to find out what i2c devices are connected
21+
i2c = I2C(1) # Device is /dev/i2c-1
22+
sensor = adafruit_bno055.BNO055_I2C(i2c)
23+
24+
while True:
25+
print("Temperature: {} degrees C".format(sensor.temperature))
26+
print("Accelerometer (m/s^2): {}".format(sensor.acceleration))
27+
print("Magnetometer (microteslas): {}".format(sensor.magnetic))
28+
print("Gyroscope (rad/sec): {}".format(sensor.gyro))
29+
print("Euler angle: {}".format(sensor.euler))
30+
print("Quaternion: {}".format(sensor.quaternion))
31+
print("Linear acceleration (m/s^2): {}".format(sensor.linear_acceleration))
32+
print("Gravity (m/s^2): {}".format(sensor.gravity))
33+
print()
34+
35+
time.sleep(1)

0 commit comments

Comments
 (0)