From e4a56b2fac69f8d6d67b45f4e7e03354ef3528f1 Mon Sep 17 00:00:00 2001 From: lewisxhe Date: Tue, 22 Oct 2024 16:57:13 +0800 Subject: [PATCH] [SensorBHI260AP] Update examples --- examples/BHI260AP_6DoF/BHI260AP_6DoF.ino | 7 +++-- .../BHI260AP_DebugInfo/BHI260AP_DebugInfo.ino | 14 +++------ .../BHI260AP_Orientation.ino | 1 + .../BHI260AP_StepCounter.ino | 7 +++-- .../BHI260AP_aux_BMM150.ino | 7 +++-- .../BHI260AP_aux_BMM150_BME280.ino | 25 ++++++++++------ ...BHI260AP_aux_BMM150_BME280_Expand_GPIO.ino | 7 +++-- .../BHI260AP_aux_BMM150_euler.ino | 11 +++---- .../BHI260AP_aux_BMM150_quaternion.ino | 10 +++---- platformio.ini | 29 ++++++++++++++----- 10 files changed, 70 insertions(+), 48 deletions(-) diff --git a/examples/BHI260AP_6DoF/BHI260AP_6DoF.ino b/examples/BHI260AP_6DoF/BHI260AP_6DoF.ino index 162f25a..8122e94 100644 --- a/examples/BHI260AP_6DoF/BHI260AP_6DoF.ino +++ b/examples/BHI260AP_6DoF/BHI260AP_6DoF.ino @@ -85,12 +85,13 @@ void setup() // Set the reset pin and interrupt pin, if any bhy.setPins(BHI260AP_RST, BHI260AP_IRQ); + Serial.println("Initializing Sensors..."); #ifdef BHY2_USE_I2C // Using I2C interface // BHI260AP_SLAVE_ADDRESS_L = 0x28 // BHI260AP_SLAVE_ADDRESS_H = 0x29 if (!bhy.init(Wire, BHI260AP_SDA, BHI260AP_SCL, BHI260AP_SLAVE_ADDRESS_L)) { - Serial.print("Failed to init BHI260AP - "); + Serial.print("Failed to initialize sensor - error code:"); Serial.println(bhy.getError()); while (1) { delay(1000); @@ -99,7 +100,7 @@ void setup() #else // Using SPI interface if (!bhy.init(SPI, BHI260AP_CS, BHI260AP_MOSI, BHI260AP_MISO, BHI260AP_SCK)) { - Serial.print("Failed to init BHI260AP - "); + Serial.print("Failed to initialize sensor - error code:"); Serial.println(bhy.getError()); while (1) { delay(1000); @@ -107,7 +108,7 @@ void setup() } #endif - Serial.println("Init BHI260AP Sensor success!"); + Serial.println("Initializing the sensor successfully!"); // Output all available sensors to Serial bhy.printSensors(Serial); diff --git a/examples/BHI260AP_DebugInfo/BHI260AP_DebugInfo.ino b/examples/BHI260AP_DebugInfo/BHI260AP_DebugInfo.ino index b66e47f..67ea7d1 100644 --- a/examples/BHI260AP_DebugInfo/BHI260AP_DebugInfo.ino +++ b/examples/BHI260AP_DebugInfo/BHI260AP_DebugInfo.ino @@ -49,13 +49,6 @@ SensorBHI260AP bhy; -void quaternion_process_callback(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len, uint64_t *timestamp) -{ - Serial.println(bhy.getSensorName(sensor_id)); -} - - - void setup() { Serial.begin(115200); @@ -65,12 +58,13 @@ void setup() // Set the reset pin and interrupt pin, if any bhy.setPins(BHI260AP_RST, BHI260AP_IRQ); + Serial.println("Initializing Sensors..."); #ifdef BHY2_USE_I2C // Using I2C interface // BHI260AP_SLAVE_ADDRESS_L = 0x28 // BHI260AP_SLAVE_ADDRESS_H = 0x29 if (!bhy.init(Wire, BHI260AP_SDA, BHI260AP_SCL, BHI260AP_SLAVE_ADDRESS_L)) { - Serial.print("Failed to init BHI260AP - "); + Serial.print("Failed to initialize sensor - error code:"); Serial.println(bhy.getError()); while (1) { delay(1000); @@ -79,7 +73,7 @@ void setup() #else // Using SPI interface if (!bhy.init(SPI, BHI260AP_CS, BHI260AP_MOSI, BHI260AP_MISO, BHI260AP_SCK)) { - Serial.print("Failed to init BHI260AP - "); + Serial.print("Failed to initialize sensor - error code:"); Serial.println(bhy.getError()); while (1) { delay(1000); @@ -87,7 +81,7 @@ void setup() } #endif - Serial.println("Init BHI260AP Sensor success!"); + Serial.println("Initializing the sensor successfully!"); // Output all current sensor information diff --git a/examples/BHI260AP_Orientation/BHI260AP_Orientation.ino b/examples/BHI260AP_Orientation/BHI260AP_Orientation.ino index f04f4fa..715d526 100644 --- a/examples/BHI260AP_Orientation/BHI260AP_Orientation.ino +++ b/examples/BHI260AP_Orientation/BHI260AP_Orientation.ino @@ -59,6 +59,7 @@ void setup() // Set the reset pin and interrupt pin, if any bhy.setPins(BHI260AP_RST, BHI260AP_IRQ); + Serial.println("Initializing Sensors..."); #ifdef BHY2_USE_I2C // Using I2C interface // BHI260AP_SLAVE_ADDRESS_L = 0x28 diff --git a/examples/BHI260AP_StepCounter/BHI260AP_StepCounter.ino b/examples/BHI260AP_StepCounter/BHI260AP_StepCounter.ino index 2c2c387..79c1124 100644 --- a/examples/BHI260AP_StepCounter/BHI260AP_StepCounter.ino +++ b/examples/BHI260AP_StepCounter/BHI260AP_StepCounter.ino @@ -72,12 +72,13 @@ void setup() // Set the reset pin and interrupt pin, if any bhy.setPins(BHI260AP_RST, BHI260AP_IRQ); + Serial.println("Initializing Sensors..."); #ifdef BHY2_USE_I2C // Using I2C interface // BHI260AP_SLAVE_ADDRESS_L = 0x28 // BHI260AP_SLAVE_ADDRESS_H = 0x29 if (!bhy.init(Wire, BHI260AP_SDA, BHI260AP_SCL, BHI260AP_SLAVE_ADDRESS_L)) { - Serial.print("Failed to init BHI260AP - "); + Serial.print("Failed to initialize sensor - error code:"); Serial.println(bhy.getError()); while (1) { delay(1000); @@ -86,7 +87,7 @@ void setup() #else // Using SPI interface if (!bhy.init(SPI, BHI260AP_CS, BHI260AP_MOSI, BHI260AP_MISO, BHI260AP_SCK)) { - Serial.print("Failed to init BHI260AP - "); + Serial.print("Failed to initialize sensor - error code:"); Serial.println(bhy.getError()); while (1) { delay(1000); @@ -94,7 +95,7 @@ void setup() } #endif - Serial.println("Init BHI260AP Sensor success!"); + Serial.println("Initializing the sensor successfully!"); // Output all available sensors to Serial bhy.printSensors(Serial); diff --git a/examples/BHI260AP_aux_BMM150/BHI260AP_aux_BMM150.ino b/examples/BHI260AP_aux_BMM150/BHI260AP_aux_BMM150.ino index 5641fe8..fc0d784 100644 --- a/examples/BHI260AP_aux_BMM150/BHI260AP_aux_BMM150.ino +++ b/examples/BHI260AP_aux_BMM150/BHI260AP_aux_BMM150.ino @@ -105,12 +105,13 @@ void setup() bhy.setBootFormFlash(true); #endif + Serial.println("Initializing Sensors..."); #ifdef BHY2_USE_I2C // Using I2C interface // BHI260AP_SLAVE_ADDRESS_L = 0x28 // BHI260AP_SLAVE_ADDRESS_H = 0x29 if (!bhy.init(Wire, BHI260AP_SDA, BHI260AP_SCL, BHI260AP_SLAVE_ADDRESS_L)) { - Serial.print("Failed to init BHI260AP - "); + Serial.print("Failed to initialize sensor - error code:"); Serial.println(bhy.getError()); while (1) { delay(1000); @@ -119,7 +120,7 @@ void setup() #else // Using SPI interface if (!bhy.init(SPI, BHI260AP_CS, BHI260AP_MOSI, BHI260AP_MISO, BHI260AP_SCK)) { - Serial.print("Failed to init BHI260AP - "); + Serial.print("Failed to initialize sensor - error code:"); Serial.println(bhy.getError()); while (1) { delay(1000); @@ -127,7 +128,7 @@ void setup() } #endif - Serial.println("Init BHI260AP Sensor success!"); + Serial.println("Initializing the sensor successfully!"); // Output all available sensors to Serial bhy.printSensors(Serial); diff --git a/examples/BHI260AP_aux_BMM150_BME280/BHI260AP_aux_BMM150_BME280.ino b/examples/BHI260AP_aux_BMM150_BME280/BHI260AP_aux_BMM150_BME280.ino index 1256531..f7e418d 100644 --- a/examples/BHI260AP_aux_BMM150_BME280/BHI260AP_aux_BMM150_BME280.ino +++ b/examples/BHI260AP_aux_BMM150_BME280/BHI260AP_aux_BMM150_BME280.ino @@ -103,7 +103,7 @@ void setup() // Set the reset pin and interrupt pin, if any bhy.setPins(BHI260AP_RST, BHI260AP_IRQ); - // Force update of the current firmware, regardless of whether it exists. + // Force update of the current firmware, regardless of whether it exists. // After uploading the firmware once, you can change it to false to speed up the startup time. bool force_update = true; // Set the firmware array address and firmware size @@ -112,12 +112,14 @@ void setup() // Set to load firmware from flash bhy.setBootFormFlash(WRITE_TO_FLASH); + Serial.println("Initializing Sensors..."); #ifdef BHY2_USE_I2C // Using I2C interface // BHI260AP_SLAVE_ADDRESS_L = 0x28 // BHI260AP_SLAVE_ADDRESS_H = 0x29 + Serial.println(""); if (!bhy.init(Wire, BHI260AP_SDA, BHI260AP_SCL, BHI260AP_SLAVE_ADDRESS_L)) { - Serial.print("Failed to init BHI260AP - "); + Serial.print("Failed to initialize sensor - error code:"); Serial.println(bhy.getError()); while (1) { delay(1000); @@ -126,7 +128,7 @@ void setup() #else // Using SPI interface if (!bhy.init(SPI, BHI260AP_CS, BHI260AP_MOSI, BHI260AP_MISO, BHI260AP_SCK)) { - Serial.print("Failed to init BHI260AP - "); + Serial.print("Failed to initialize sensor - error code:"); Serial.println(bhy.getError()); while (1) { delay(1000); @@ -134,14 +136,14 @@ void setup() } #endif - Serial.println("Init BHI260AP Sensor success!"); + Serial.println("Initializing the sensor successfully!"); // Output all available sensors to Serial bhy.printSensors(Serial); /* - * Enable monitoring. - * sample_rate ​​can only control the rate of the pressure sensor. + * Enable monitoring. + * sample_rate ​​can only control the rate of the pressure sensor. * Temperature and humidity will only be updated when there is a change. * * */ float sample_rate = 1.0; /* Set to 1Hz update frequency */ @@ -152,12 +154,17 @@ void setup() * Function depends on BME280. * If the hardware is not connected to BME280, the function cannot be used. * * */ - bhy.configure(SENSOR_ID_TEMP, sample_rate, report_latency_ms); - bhy.configure(SENSOR_ID_BARO, sample_rate, report_latency_ms); - bhy.configure(SENSOR_ID_HUM, sample_rate, report_latency_ms); + bool rlst = false; + rlst = bhy.configure(SENSOR_ID_TEMP, sample_rate, report_latency_ms); + Serial.printf("Configure temperature sensor %.2f HZ %s\n", sample_rate, rlst ? "successfully" : "failed"); + rlst = bhy.configure(SENSOR_ID_BARO, sample_rate, report_latency_ms); + Serial.printf("Configure pressure sensor %.2f HZ %s\n", sample_rate, rlst ? "successfully" : "failed"); + rlst = bhy.configure(SENSOR_ID_HUM, sample_rate, report_latency_ms); + Serial.printf("Configure humidity sensor %.2f HZ %s\n", sample_rate, rlst ? "successfully" : "failed"); // Register BME280 data parse callback function + Serial.println("Register sensor result callback function"); bhy.onResultEvent(SENSOR_ID_TEMP, parse_bme280_sensor_data); bhy.onResultEvent(SENSOR_ID_HUM, parse_bme280_sensor_data); bhy.onResultEvent(SENSOR_ID_BARO, parse_bme280_sensor_data); diff --git a/examples/BHI260AP_aux_BMM150_BME280_Expand_GPIO/BHI260AP_aux_BMM150_BME280_Expand_GPIO.ino b/examples/BHI260AP_aux_BMM150_BME280_Expand_GPIO/BHI260AP_aux_BMM150_BME280_Expand_GPIO.ino index 49bddff..af1644c 100644 --- a/examples/BHI260AP_aux_BMM150_BME280_Expand_GPIO/BHI260AP_aux_BMM150_BME280_Expand_GPIO.ino +++ b/examples/BHI260AP_aux_BMM150_BME280_Expand_GPIO/BHI260AP_aux_BMM150_BME280_Expand_GPIO.ino @@ -137,12 +137,13 @@ void setup() // Set to load firmware from flash bhy.setBootFormFlash(WRITE_TO_FLASH); + Serial.println("Initializing Sensors..."); #ifdef BHY2_USE_I2C // Using I2C interface // BHI260AP_SLAVE_ADDRESS_L = 0x28 // BHI260AP_SLAVE_ADDRESS_H = 0x29 if (!bhy.init(Wire, BHI260AP_SDA, BHI260AP_SCL, BHI260AP_SLAVE_ADDRESS_L)) { - Serial.print("Failed to init BHI260AP - "); + Serial.print("Failed to initialize sensor - error code:"); Serial.println(bhy.getError()); while (1) { delay(1000); @@ -151,7 +152,7 @@ void setup() #else // Using SPI interface if (!bhy.init(SPI, BHI260AP_CS, BHI260AP_MOSI, BHI260AP_MISO, BHI260AP_SCK)) { - Serial.print("Failed to init BHI260AP - "); + Serial.print("Failed to initialize sensor - error code:"); Serial.println(bhy.getError()); while (1) { delay(1000); @@ -159,7 +160,7 @@ void setup() } #endif - Serial.println("Init BHI260AP Sensor success!"); + Serial.println("Initializing the sensor successfully!"); // Register BME280 data parse callback function bhy.onResultEvent(SENSOR_ID_TEMP, parse_bme280_sensor_data); diff --git a/examples/BHI260AP_aux_BMM150_euler/BHI260AP_aux_BMM150_euler.ino b/examples/BHI260AP_aux_BMM150_euler/BHI260AP_aux_BMM150_euler.ino index 064bba0..9b69ca9 100644 --- a/examples/BHI260AP_aux_BMM150_euler/BHI260AP_aux_BMM150_euler.ino +++ b/examples/BHI260AP_aux_BMM150_euler/BHI260AP_aux_BMM150_euler.ino @@ -92,7 +92,7 @@ void parse_euler(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len, uint64_t *t Serial.print(" x:"); Serial.print(data.heading * 360.0f / 32768.0f); Serial.print(" y:"); Serial.print(data.pitch * 360.0f / 32768.0f); Serial.print(" x:"); Serial.print(data.roll * 360.0f / 32768.0f); - Serial.print(" acc:"); Serial.print(accuracy); + Serial.print(" acc:"); Serial.println(accuracy); /* Serial.printf("SID: %u; T: %u.%09u; h: %f, p: %f, r: %f; acc: %u\r\n", sensor_id, @@ -110,7 +110,7 @@ void parse_euler(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len, uint64_t *t Serial.print("."); Serial.print(ns); Serial.print(" x:"); Serial.print(data.heading * 360.0f / 32768.0f); Serial.print(" y:"); Serial.print(data.pitch * 360.0f / 32768.0f); - Serial.print(" x:"); Serial.print(data.roll * 360.0f / 32768.0f); + Serial.print(" x:"); Serial.println(data.roll * 360.0f / 32768.0f); /* Serial.printf("SID: %u; T: %u.%09u; h: %f, p: %f, r: %f\r\n", sensor_id, @@ -143,12 +143,13 @@ void setup() bhy.setBootFormFlash(true); #endif + Serial.println("Initializing Sensors..."); #ifdef BHY2_USE_I2C // Using I2C interface // BHI260AP_SLAVE_ADDRESS_L = 0x28 // BHI260AP_SLAVE_ADDRESS_H = 0x29 if (!bhy.init(Wire, BHI260AP_SDA, BHI260AP_SCL, BHI260AP_SLAVE_ADDRESS_L)) { - Serial.print("Failed to init BHI260AP - "); + Serial.print("Failed to initialize sensor - error code:"); Serial.println(bhy.getError()); while (1) { delay(1000); @@ -157,7 +158,7 @@ void setup() #else // Using SPI interface if (!bhy.init(SPI, BHI260AP_CS, BHI260AP_MOSI, BHI260AP_MISO, BHI260AP_SCK)) { - Serial.print("Failed to init BHI260AP - "); + Serial.print("Failed to initialize sensor - error code:"); Serial.println(bhy.getError()); while (1) { delay(1000); @@ -165,7 +166,7 @@ void setup() } #endif - Serial.println("Init BHI260AP Sensor success!"); + Serial.println("Initializing the sensor successfully!"); // Output all available sensors to Serial bhy.printSensors(Serial); diff --git a/examples/BHI260AP_aux_BMM150_quaternion/BHI260AP_aux_BMM150_quaternion.ino b/examples/BHI260AP_aux_BMM150_quaternion/BHI260AP_aux_BMM150_quaternion.ino index a4ab446..075d5ee 100644 --- a/examples/BHI260AP_aux_BMM150_quaternion/BHI260AP_aux_BMM150_quaternion.ino +++ b/examples/BHI260AP_aux_BMM150_quaternion/BHI260AP_aux_BMM150_quaternion.ino @@ -91,7 +91,7 @@ void parse_quaternion(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len, uint64 Serial.print(" y:"); Serial.print(data.y / 16384.0f); Serial.print(" x:"); Serial.print(data.z / 16384.0f); Serial.print(" w:"); Serial.print(data.w / 16384.0f); - Serial.print(" acc:"); Serial.print(((data.accuracy * 180.0f) / 16384.0f) / 3.141592653589793f); + Serial.print(" acc:"); Serial.println(((data.accuracy * 180.0f) / 16384.0f) / 3.141592653589793f); /* Serial.printf("SID: %u; T: %u.%09u; x: %f, y: %f, z: %f, w: %f; acc: %.2f\r\n", @@ -126,13 +126,13 @@ void setup() bhy.setBootFormFlash(true); #endif - + Serial.println("Initializing Sensors..."); #ifdef BHY2_USE_I2C // Using I2C interface // BHI260AP_SLAVE_ADDRESS_L = 0x28 // BHI260AP_SLAVE_ADDRESS_H = 0x29 if (!bhy.init(Wire, BHI260AP_SDA, BHI260AP_SCL, BHI260AP_SLAVE_ADDRESS_L)) { - Serial.print("Failed to init BHI260AP - "); + Serial.print("Failed to initialize sensor - error code:"); Serial.println(bhy.getError()); while (1) { delay(1000); @@ -141,7 +141,7 @@ void setup() #else // Using SPI interface if (!bhy.init(SPI, BHI260AP_CS, BHI260AP_MOSI, BHI260AP_MISO, BHI260AP_SCK)) { - Serial.print("Failed to init BHI260AP - "); + Serial.print("Failed to initialize sensor - error code:"); Serial.println(bhy.getError()); while (1) { delay(1000); @@ -149,7 +149,7 @@ void setup() } #endif - Serial.println("Init BHI260AP Sensor success!"); + Serial.println("Initializing the sensor successfully!"); // Output all available sensors to Serial bhy.printSensors(Serial); diff --git a/platformio.ini b/platformio.ini index 30c0951..160e4ed 100644 --- a/platformio.ini +++ b/platformio.ini @@ -19,7 +19,7 @@ ; src_dir = examples/PCF8563_TimeSynchronization ; src_dir = examples/PCF85063_SimpleTime ; src_dir = examples/PCF85063_AlarmByUnits -src_dir = examples/PCF8563_ClockOutput +; src_dir = examples/PCF8563_ClockOutput ; src_dir = examples/PCF85063_ClockOutput ; src_dir = examples/QMC6310_CalibrateExample ; src_dir = examples/QMC6310_CompassExample @@ -51,7 +51,8 @@ src_dir = examples/PCF8563_ClockOutput ; src_dir = examples/BHI260AP_aux_BMM150 ; src_dir = examples/BHI260AP_aux_BMM150_euler ; src_dir = examples/BHI260AP_aux_BMM150_quaternion -; src_dir = examples/BHI260AP_aux_BMM150_BME280 +src_dir = examples/BHI260AP_aux_BMM150_BME280 +; src_dir = examples/BHI260AP_aux_BMM150_BME280_Expand_GPIO ; src_dir = examples/BMM150_GetDataExample @@ -67,10 +68,10 @@ src_dir = examples/PCF8563_ClockOutput ; src_dir = examples/TouchDrv_GT9895_GetPoint ; default_envs = esp32dev -default_envs = esp32s3 +; default_envs = esp32s3 ; default_envs = esp32c3 ; default_envs = rp2040 -; default_envs = nrf52840 +default_envs = nrf52840 ; default_envs = stm32 ; Custom board variant @@ -97,7 +98,6 @@ build_flags = ; -DARDUINO_T_WATCH_S3_U ; -DLOG_PORT=Serial - -DCORE_DEBUG_LEVEL=0 -Wnarrowing -Wtype-limits ; -Werror @@ -107,18 +107,26 @@ build_flags = -Wmissing-field-initializers -std=c++11 - +; lib_deps = + ; https://github.com/CreativeRobotics/Commander + [env:esp32dev] extends = env platform = espressif32@6.8.1 framework = arduino board = esp32dev +build_flags = + ${env.build_flags} + -DCORE_DEBUG_LEVEL=0 [env:esp32c3] extends = env platform = espressif32@6.8.1 framework = arduino board = esp32-c3-devkitm-1 +build_flags = + ${env.build_flags} + -DCORE_DEBUG_LEVEL=0 [env:esp32s3] extends = env @@ -129,6 +137,7 @@ build_flags = ${env.build_flags} -DARDUINO_USB_CDC_ON_BOOT=1 ; -UARDUINO_USB_CDC_ON_BOOT + -DCORE_DEBUG_LEVEL=0 [env:rp2040] extends = env @@ -138,7 +147,7 @@ framework = arduino board_build.core = earlephilhower [env:nrf52840] -platform = nordicnrf52 +platform = nordicnrf52@10.6.0 board = nrf52840_dk_adafruit framework = arduino monitor_speed = 115200 @@ -147,6 +156,12 @@ upload_protocol = nrfutil ; upload_protocol = nrfjprog ; upload_protocol = jlink +build_flags = + ${env.build_flags} + -DCFG_DEBUG=3 + -DCFG_LOGGER=0 + -DCFG_SYSVIEW=1 + [env:stm32] platform = ststm32 framework = arduino