Skip to content

Commit

Permalink
[SensorBHI260AP] Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Oct 22, 2024
1 parent 8b12554 commit e4a56b2
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 48 deletions.
7 changes: 4 additions & 3 deletions examples/BHI260AP_6DoF/BHI260AP_6DoF.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -99,15 +100,15 @@ 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);
}
}
#endif

Serial.println("Init BHI260AP Sensor success!");
Serial.println("Initializing the sensor successfully!");

// Output all available sensors to Serial
bhy.printSensors(Serial);
Expand Down
14 changes: 4 additions & 10 deletions examples/BHI260AP_DebugInfo/BHI260AP_DebugInfo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -79,15 +73,15 @@ 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);
}
}
#endif

Serial.println("Init BHI260AP Sensor success!");
Serial.println("Initializing the sensor successfully!");


// Output all current sensor information
Expand Down
1 change: 1 addition & 0 deletions examples/BHI260AP_Orientation/BHI260AP_Orientation.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions examples/BHI260AP_StepCounter/BHI260AP_StepCounter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -86,15 +87,15 @@ 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);
}
}
#endif

Serial.println("Init BHI260AP Sensor success!");
Serial.println("Initializing the sensor successfully!");

// Output all available sensors to Serial
bhy.printSensors(Serial);
Expand Down
7 changes: 4 additions & 3 deletions examples/BHI260AP_aux_BMM150/BHI260AP_aux_BMM150.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -119,15 +120,15 @@ 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);
}
}
#endif

Serial.println("Init BHI260AP Sensor success!");
Serial.println("Initializing the sensor successfully!");

// Output all available sensors to Serial
bhy.printSensors(Serial);
Expand Down
25 changes: 16 additions & 9 deletions examples/BHI260AP_aux_BMM150_BME280/BHI260AP_aux_BMM150_BME280.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -126,22 +128,22 @@ 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);
}
}
#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 */
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -151,15 +152,15 @@ 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);
}
}
#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);
Expand Down
11 changes: 6 additions & 5 deletions examples/BHI260AP_aux_BMM150_euler/BHI260AP_aux_BMM150_euler.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -157,15 +158,15 @@ 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);
}
}
#endif

Serial.println("Init BHI260AP Sensor success!");
Serial.println("Initializing the sensor successfully!");

// Output all available sensors to Serial
bhy.printSensors(Serial);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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);
Expand All @@ -141,15 +141,15 @@ 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);
}
}
#endif

Serial.println("Init BHI260AP Sensor success!");
Serial.println("Initializing the sensor successfully!");

// Output all available sensors to Serial
bhy.printSensors(Serial);
Expand Down
Loading

0 comments on commit e4a56b2

Please sign in to comment.