Skip to content

Commit f3b651f

Browse files
authored
Merge pull request #2787 from adafruit/bno055_bmp280_bff
add BNO055 and BMP280 BFF examples
2 parents 9fda4e2 + e2b43f3 commit f3b651f

File tree

3 files changed

+167
-3
lines changed

3 files changed

+167
-3
lines changed

ADG72x_Examples/CircuitPython_ADG728/code.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414

1515
c = 0
1616
switch_time = 2
17+
channels = [0, 4]
1718
clock = time.monotonic()
1819
while True:
1920
if (time.monotonic() - clock) > switch_time:
20-
print(f"Selecting channel {c + 1}")
21-
switch.channel = c
22-
c = (c + 1) % 8
21+
print(f"Selecting channel {channels[c] + 1}")
22+
switch.channel = channels[c]
23+
c = (c + 1) % 2
2324
clock = time.monotonic()
2425
print((analog_in.value,))
2526
time.sleep(0.1)
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
// BNO055 + BMP280 BFF Demo
5+
6+
#include <Wire.h>
7+
#include <Adafruit_Sensor.h>
8+
#include <Adafruit_BMP280.h>
9+
#include <Adafruit_BNO055.h>
10+
#include <utility/imumaths.h>
11+
12+
Adafruit_BNO055 bno = Adafruit_BNO055(55, 0x28, &Wire);
13+
Adafruit_BMP280 bmp;
14+
15+
void setup(void)
16+
{
17+
Serial.begin(115200);
18+
19+
while (!Serial) delay(10); // wait for serial port to open!
20+
21+
Serial.println("Adafruit BNO055 + BMP280 BFF Demo");
22+
23+
/* Initialise the sensor */
24+
if (!bno.begin())
25+
{
26+
/* There was a problem detecting the BNO055 ... check your connections */
27+
Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
28+
while (1);
29+
}
30+
if (!bmp.begin()) {
31+
Serial.print("Ooops, no BMP280 detected ... Check your wiring or I2C ADDR!");
32+
while (1);
33+
}
34+
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
35+
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
36+
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
37+
Adafruit_BMP280::FILTER_X16, /* Filtering. */
38+
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
39+
Serial.println("Found BNO055 and BMP280 sensors!");
40+
Serial.println();
41+
delay(1000);
42+
}
43+
44+
void loop(void)
45+
{
46+
//could add VECTOR_ACCELEROMETER, VECTOR_MAGNETOMETER,VECTOR_GRAVITY...
47+
sensors_event_t orientationData , angVelocityData , linearAccelData, magnetometerData, accelerometerData, gravityData;
48+
bno.getEvent(&orientationData, Adafruit_BNO055::VECTOR_EULER);
49+
bno.getEvent(&angVelocityData, Adafruit_BNO055::VECTOR_GYROSCOPE);
50+
bno.getEvent(&linearAccelData, Adafruit_BNO055::VECTOR_LINEARACCEL);
51+
bno.getEvent(&magnetometerData, Adafruit_BNO055::VECTOR_MAGNETOMETER);
52+
bno.getEvent(&accelerometerData, Adafruit_BNO055::VECTOR_ACCELEROMETER);
53+
bno.getEvent(&gravityData, Adafruit_BNO055::VECTOR_GRAVITY);
54+
Serial.println("BNO055 data:");
55+
printEvent(&orientationData);
56+
printEvent(&angVelocityData);
57+
printEvent(&linearAccelData);
58+
printEvent(&magnetometerData);
59+
printEvent(&accelerometerData);
60+
printEvent(&gravityData);
61+
Serial.println("--");
62+
Serial.println("BMP280 data:");
63+
Serial.print(F("Temperature = "));
64+
Serial.print(bmp.readTemperature());
65+
Serial.println(" *C");
66+
67+
Serial.print(F("Pressure = "));
68+
Serial.print(bmp.readPressure());
69+
Serial.println(" Pa");
70+
71+
Serial.print(F("Approx altitude = "));
72+
Serial.print(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */
73+
Serial.println(" m");
74+
75+
Serial.println();
76+
delay(2000);
77+
}
78+
79+
void printEvent(sensors_event_t* event) {
80+
double x = -1000000, y = -1000000 , z = -1000000; //dumb values, easy to spot problem
81+
if (event->type == SENSOR_TYPE_ACCELEROMETER) {
82+
Serial.print("Accl:");
83+
x = event->acceleration.x;
84+
y = event->acceleration.y;
85+
z = event->acceleration.z;
86+
}
87+
else if (event->type == SENSOR_TYPE_ORIENTATION) {
88+
Serial.print("Orient:");
89+
x = event->orientation.x;
90+
y = event->orientation.y;
91+
z = event->orientation.z;
92+
}
93+
else if (event->type == SENSOR_TYPE_MAGNETIC_FIELD) {
94+
Serial.print("Mag:");
95+
x = event->magnetic.x;
96+
y = event->magnetic.y;
97+
z = event->magnetic.z;
98+
}
99+
else if (event->type == SENSOR_TYPE_GYROSCOPE) {
100+
Serial.print("Gyro:");
101+
x = event->gyro.x;
102+
y = event->gyro.y;
103+
z = event->gyro.z;
104+
}
105+
else if (event->type == SENSOR_TYPE_ROTATION_VECTOR) {
106+
Serial.print("Rot:");
107+
x = event->gyro.x;
108+
y = event->gyro.y;
109+
z = event->gyro.z;
110+
}
111+
else if (event->type == SENSOR_TYPE_LINEAR_ACCELERATION) {
112+
Serial.print("Linear:");
113+
x = event->acceleration.x;
114+
y = event->acceleration.y;
115+
z = event->acceleration.z;
116+
}
117+
else if (event->type == SENSOR_TYPE_GRAVITY) {
118+
Serial.print("Gravity:");
119+
x = event->acceleration.x;
120+
y = event->acceleration.y;
121+
z = event->acceleration.z;
122+
}
123+
else {
124+
Serial.print("Unk:");
125+
}
126+
127+
Serial.print("\tx= ");
128+
Serial.print(x);
129+
Serial.print(" |\ty= ");
130+
Serial.print(y);
131+
Serial.print(" |\tz= ");
132+
Serial.println(z);
133+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
#
4+
# BNO055 + BMP280 BFF Demo
5+
6+
import time
7+
import board
8+
import adafruit_bno055
9+
import adafruit_bmp280
10+
11+
i2c = board.I2C() # uses board.SCL and board.SDA
12+
bno055 = adafruit_bno055.BNO055_I2C(i2c)
13+
14+
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
15+
bmp280.sea_level_pressure = 1013.25
16+
17+
while True:
18+
print(f"Temperature: {bmp280.temperature:0.1f} C")
19+
print(f"Pressure: {bmp280.pressure:0.1f} hPa")
20+
print(f"Altitude = {bmp280.altitude:0.2f} meters")
21+
print(f"Accelerometer (m/s^2): {bno055.acceleration}")
22+
print(f"Magnetometer (microteslas): {bno055.magnetic}")
23+
print(f"Gyroscope (rad/sec): {bno055.gyro}")
24+
print(f"Euler angle: {bno055.euler}")
25+
print(f"Quaternion: {bno055.quaternion}")
26+
print(f"Linear acceleration (m/s^2): {bno055.linear_acceleration}")
27+
print(f"Gravity (m/s^2): {bno055.gravity}")
28+
print()
29+
30+
time.sleep(1)

0 commit comments

Comments
 (0)