add BNO055 and BMP280 BFF examples
adding circuitpython and arduino examples for BNO055 BMP280 BFF. also updating adg728 example to flip between two channels
This commit is contained in:
parent
9fda4e298a
commit
e2b43f353e
3 changed files with 167 additions and 3 deletions
|
|
@ -14,12 +14,13 @@ switch = adafruit_adg72x.ADG72x(i2c)
|
||||||
|
|
||||||
c = 0
|
c = 0
|
||||||
switch_time = 2
|
switch_time = 2
|
||||||
|
channels = [0, 4]
|
||||||
clock = time.monotonic()
|
clock = time.monotonic()
|
||||||
while True:
|
while True:
|
||||||
if (time.monotonic() - clock) > switch_time:
|
if (time.monotonic() - clock) > switch_time:
|
||||||
print(f"Selecting channel {c + 1}")
|
print(f"Selecting channel {channels[c] + 1}")
|
||||||
switch.channel = c
|
switch.channel = channels[c]
|
||||||
c = (c + 1) % 8
|
c = (c + 1) % 2
|
||||||
clock = time.monotonic()
|
clock = time.monotonic()
|
||||||
print((analog_in.value,))
|
print((analog_in.value,))
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,133 @@
|
||||||
|
// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// BNO055 + BMP280 BFF Demo
|
||||||
|
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <Adafruit_Sensor.h>
|
||||||
|
#include <Adafruit_BMP280.h>
|
||||||
|
#include <Adafruit_BNO055.h>
|
||||||
|
#include <utility/imumaths.h>
|
||||||
|
|
||||||
|
Adafruit_BNO055 bno = Adafruit_BNO055(55, 0x28, &Wire);
|
||||||
|
Adafruit_BMP280 bmp;
|
||||||
|
|
||||||
|
void setup(void)
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
while (!Serial) delay(10); // wait for serial port to open!
|
||||||
|
|
||||||
|
Serial.println("Adafruit BNO055 + BMP280 BFF Demo");
|
||||||
|
|
||||||
|
/* Initialise the sensor */
|
||||||
|
if (!bno.begin())
|
||||||
|
{
|
||||||
|
/* There was a problem detecting the BNO055 ... check your connections */
|
||||||
|
Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
|
||||||
|
while (1);
|
||||||
|
}
|
||||||
|
if (!bmp.begin()) {
|
||||||
|
Serial.print("Ooops, no BMP280 detected ... Check your wiring or I2C ADDR!");
|
||||||
|
while (1);
|
||||||
|
}
|
||||||
|
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
|
||||||
|
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
|
||||||
|
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
|
||||||
|
Adafruit_BMP280::FILTER_X16, /* Filtering. */
|
||||||
|
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
|
||||||
|
Serial.println("Found BNO055 and BMP280 sensors!");
|
||||||
|
Serial.println();
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop(void)
|
||||||
|
{
|
||||||
|
//could add VECTOR_ACCELEROMETER, VECTOR_MAGNETOMETER,VECTOR_GRAVITY...
|
||||||
|
sensors_event_t orientationData , angVelocityData , linearAccelData, magnetometerData, accelerometerData, gravityData;
|
||||||
|
bno.getEvent(&orientationData, Adafruit_BNO055::VECTOR_EULER);
|
||||||
|
bno.getEvent(&angVelocityData, Adafruit_BNO055::VECTOR_GYROSCOPE);
|
||||||
|
bno.getEvent(&linearAccelData, Adafruit_BNO055::VECTOR_LINEARACCEL);
|
||||||
|
bno.getEvent(&magnetometerData, Adafruit_BNO055::VECTOR_MAGNETOMETER);
|
||||||
|
bno.getEvent(&accelerometerData, Adafruit_BNO055::VECTOR_ACCELEROMETER);
|
||||||
|
bno.getEvent(&gravityData, Adafruit_BNO055::VECTOR_GRAVITY);
|
||||||
|
Serial.println("BNO055 data:");
|
||||||
|
printEvent(&orientationData);
|
||||||
|
printEvent(&angVelocityData);
|
||||||
|
printEvent(&linearAccelData);
|
||||||
|
printEvent(&magnetometerData);
|
||||||
|
printEvent(&accelerometerData);
|
||||||
|
printEvent(&gravityData);
|
||||||
|
Serial.println("--");
|
||||||
|
Serial.println("BMP280 data:");
|
||||||
|
Serial.print(F("Temperature = "));
|
||||||
|
Serial.print(bmp.readTemperature());
|
||||||
|
Serial.println(" *C");
|
||||||
|
|
||||||
|
Serial.print(F("Pressure = "));
|
||||||
|
Serial.print(bmp.readPressure());
|
||||||
|
Serial.println(" Pa");
|
||||||
|
|
||||||
|
Serial.print(F("Approx altitude = "));
|
||||||
|
Serial.print(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */
|
||||||
|
Serial.println(" m");
|
||||||
|
|
||||||
|
Serial.println();
|
||||||
|
delay(2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void printEvent(sensors_event_t* event) {
|
||||||
|
double x = -1000000, y = -1000000 , z = -1000000; //dumb values, easy to spot problem
|
||||||
|
if (event->type == SENSOR_TYPE_ACCELEROMETER) {
|
||||||
|
Serial.print("Accl:");
|
||||||
|
x = event->acceleration.x;
|
||||||
|
y = event->acceleration.y;
|
||||||
|
z = event->acceleration.z;
|
||||||
|
}
|
||||||
|
else if (event->type == SENSOR_TYPE_ORIENTATION) {
|
||||||
|
Serial.print("Orient:");
|
||||||
|
x = event->orientation.x;
|
||||||
|
y = event->orientation.y;
|
||||||
|
z = event->orientation.z;
|
||||||
|
}
|
||||||
|
else if (event->type == SENSOR_TYPE_MAGNETIC_FIELD) {
|
||||||
|
Serial.print("Mag:");
|
||||||
|
x = event->magnetic.x;
|
||||||
|
y = event->magnetic.y;
|
||||||
|
z = event->magnetic.z;
|
||||||
|
}
|
||||||
|
else if (event->type == SENSOR_TYPE_GYROSCOPE) {
|
||||||
|
Serial.print("Gyro:");
|
||||||
|
x = event->gyro.x;
|
||||||
|
y = event->gyro.y;
|
||||||
|
z = event->gyro.z;
|
||||||
|
}
|
||||||
|
else if (event->type == SENSOR_TYPE_ROTATION_VECTOR) {
|
||||||
|
Serial.print("Rot:");
|
||||||
|
x = event->gyro.x;
|
||||||
|
y = event->gyro.y;
|
||||||
|
z = event->gyro.z;
|
||||||
|
}
|
||||||
|
else if (event->type == SENSOR_TYPE_LINEAR_ACCELERATION) {
|
||||||
|
Serial.print("Linear:");
|
||||||
|
x = event->acceleration.x;
|
||||||
|
y = event->acceleration.y;
|
||||||
|
z = event->acceleration.z;
|
||||||
|
}
|
||||||
|
else if (event->type == SENSOR_TYPE_GRAVITY) {
|
||||||
|
Serial.print("Gravity:");
|
||||||
|
x = event->acceleration.x;
|
||||||
|
y = event->acceleration.y;
|
||||||
|
z = event->acceleration.z;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Serial.print("Unk:");
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.print("\tx= ");
|
||||||
|
Serial.print(x);
|
||||||
|
Serial.print(" |\ty= ");
|
||||||
|
Serial.print(y);
|
||||||
|
Serial.print(" |\tz= ");
|
||||||
|
Serial.println(z);
|
||||||
|
}
|
||||||
30
BNO055_BMP280_BFF_Examples/CircuitPython/code.py
Normal file
30
BNO055_BMP280_BFF_Examples/CircuitPython/code.py
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
#
|
||||||
|
# BNO055 + BMP280 BFF Demo
|
||||||
|
|
||||||
|
import time
|
||||||
|
import board
|
||||||
|
import adafruit_bno055
|
||||||
|
import adafruit_bmp280
|
||||||
|
|
||||||
|
i2c = board.I2C() # uses board.SCL and board.SDA
|
||||||
|
bno055 = adafruit_bno055.BNO055_I2C(i2c)
|
||||||
|
|
||||||
|
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
|
||||||
|
bmp280.sea_level_pressure = 1013.25
|
||||||
|
|
||||||
|
while True:
|
||||||
|
print(f"Temperature: {bmp280.temperature:0.1f} C")
|
||||||
|
print(f"Pressure: {bmp280.pressure:0.1f} hPa")
|
||||||
|
print(f"Altitude = {bmp280.altitude:0.2f} meters")
|
||||||
|
print(f"Accelerometer (m/s^2): {bno055.acceleration}")
|
||||||
|
print(f"Magnetometer (microteslas): {bno055.magnetic}")
|
||||||
|
print(f"Gyroscope (rad/sec): {bno055.gyro}")
|
||||||
|
print(f"Euler angle: {bno055.euler}")
|
||||||
|
print(f"Quaternion: {bno055.quaternion}")
|
||||||
|
print(f"Linear acceleration (m/s^2): {bno055.linear_acceleration}")
|
||||||
|
print(f"Gravity (m/s^2): {bno055.gravity}")
|
||||||
|
print()
|
||||||
|
|
||||||
|
time.sleep(1)
|
||||||
Loading…
Reference in a new issue