From e2b43f353ed6698d0ebf2e39c21b35ef608d21ca Mon Sep 17 00:00:00 2001 From: Liz Date: Wed, 17 Apr 2024 16:20:11 -0400 Subject: [PATCH] add BNO055 and BMP280 BFF examples adding circuitpython and arduino examples for BNO055 BMP280 BFF. also updating adg728 example to flip between two channels --- ADG72x_Examples/CircuitPython_ADG728/code.py | 7 +- .../BNO055_BMP280_BFF_Arduino_Demo.ino | 133 ++++++++++++++++++ .../CircuitPython/code.py | 30 ++++ 3 files changed, 167 insertions(+), 3 deletions(-) create mode 100644 BNO055_BMP280_BFF_Examples/BNO055_BMP280_BFF_Arduino_Demo/BNO055_BMP280_BFF_Arduino_Demo.ino create mode 100644 BNO055_BMP280_BFF_Examples/CircuitPython/code.py diff --git a/ADG72x_Examples/CircuitPython_ADG728/code.py b/ADG72x_Examples/CircuitPython_ADG728/code.py index 3af434590..65ca8b071 100644 --- a/ADG72x_Examples/CircuitPython_ADG728/code.py +++ b/ADG72x_Examples/CircuitPython_ADG728/code.py @@ -14,12 +14,13 @@ switch = adafruit_adg72x.ADG72x(i2c) c = 0 switch_time = 2 +channels = [0, 4] clock = time.monotonic() while True: if (time.monotonic() - clock) > switch_time: - print(f"Selecting channel {c + 1}") - switch.channel = c - c = (c + 1) % 8 + print(f"Selecting channel {channels[c] + 1}") + switch.channel = channels[c] + c = (c + 1) % 2 clock = time.monotonic() print((analog_in.value,)) time.sleep(0.1) diff --git a/BNO055_BMP280_BFF_Examples/BNO055_BMP280_BFF_Arduino_Demo/BNO055_BMP280_BFF_Arduino_Demo.ino b/BNO055_BMP280_BFF_Examples/BNO055_BMP280_BFF_Arduino_Demo/BNO055_BMP280_BFF_Arduino_Demo.ino new file mode 100644 index 000000000..c66a288db --- /dev/null +++ b/BNO055_BMP280_BFF_Examples/BNO055_BMP280_BFF_Arduino_Demo/BNO055_BMP280_BFF_Arduino_Demo.ino @@ -0,0 +1,133 @@ +// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries +// +// SPDX-License-Identifier: MIT +// BNO055 + BMP280 BFF Demo + +#include +#include +#include +#include +#include + +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); +} diff --git a/BNO055_BMP280_BFF_Examples/CircuitPython/code.py b/BNO055_BMP280_BFF_Examples/CircuitPython/code.py new file mode 100644 index 000000000..ef5fcf2ca --- /dev/null +++ b/BNO055_BMP280_BFF_Examples/CircuitPython/code.py @@ -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)