Skip to content

Commit

Permalink
BHI260AP added Euler and Quadruple examples, added example source des…
Browse files Browse the repository at this point in the history
…cription
  • Loading branch information
lewisxhe committed Jul 23, 2024
1 parent 60dea0f commit 4e00d3e
Show file tree
Hide file tree
Showing 12 changed files with 37,654 additions and 20 deletions.
6 changes: 3 additions & 3 deletions examples/BHI260AP_6DoF/BHI260AP_6DoF.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @file BHI260AP_6DoF.ino
* @author Lewis He (lewishe@outlook.com)
* @date 2023-09-06
*
* @note Changed from Boschsensortec API https://github.com/boschsensortec/BHY2_SensorAPI
*/
#include <Wire.h>
#include <SPI.h>
Expand All @@ -48,7 +48,7 @@


SensorBHI260AP bhy;
void accel_process_callback(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len)
void accel_process_callback(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len, uint64_t *timestamp)
{
struct bhy2_data_xyz data;
float scaling_factor = get_sensor_default_scaling(sensor_id);
Expand All @@ -63,7 +63,7 @@ void accel_process_callback(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len)
}


void gyro_process_callback(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len)
void gyro_process_callback(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len, uint64_t *timestamp)
{
struct bhy2_data_xyz data;
float scaling_factor = get_sensor_default_scaling(sensor_id);
Expand Down
4 changes: 2 additions & 2 deletions examples/BHI260AP_DebugInfo/BHI260AP_DebugInfo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @file BHI260AP_DebugInfo.ino
* @author Lewis He (lewishe@outlook.com)
* @date 2023-10-08
*
* @note Changed from Boschsensortec API https://github.com/boschsensortec/BHY2_SensorAPI
*/
#include <Wire.h>
#include <SPI.h>
Expand All @@ -49,7 +49,7 @@
SensorBHI260AP bhy;


void quaternion_process_callback(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len)
void quaternion_process_callback(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len, uint64_t *timestamp)
{
Serial.println(bhy.getSensorName(sensor_id));
}
Expand Down
6 changes: 3 additions & 3 deletions examples/BHI260AP_Orientation/BHI260AP_Orientation.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @file BHI260AP_Orientation.ino
* @author Lewis He (lewishe@outlook.com)
* @date 2023-10-07
*
* @note Changed from Boschsensortec API https://github.com/boschsensortec/BHY2_SensorAPI
*/
#include <Wire.h>
#include <SPI.h>
Expand All @@ -46,7 +46,7 @@
#define BHI260AP_RST 47
#endif

void orientation_process_callback(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len);
void orientation_process_callback(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len, uint64_t *timestamp);

SensorBHI260AP bhy;

Expand Down Expand Up @@ -106,7 +106,7 @@ void loop()
}


void orientation_process_callback(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len)
void orientation_process_callback(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len, uint64_t *timestamp)
{
char report[256];
uint8_t direction = *data_ptr;
Expand Down
6 changes: 3 additions & 3 deletions examples/BHI260AP_StepCounter/BHI260AP_StepCounter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @file BHI260AP_StepCounter.ino
* @author Lewis He (lewishe@outlook.com)
* @date 2023-10-08
*
* @note Changed from Boschsensortec API https://github.com/boschsensortec/BHY2_SensorAPI
*/
#include <Wire.h>
#include <SPI.h>
Expand All @@ -49,13 +49,13 @@
SensorBHI260AP bhy;


void step_detector_process_callback(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len)
void step_detector_process_callback(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len, uint64_t *timestamp)
{
Serial.print(bhy.getSensorName(sensor_id));
Serial.println(" detected.");
}

void step_counter_process_callback(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len)
void step_counter_process_callback(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len, uint64_t *timestamp)
{
Serial.print(bhy.getSensorName(sensor_id));
Serial.print(":");
Expand Down
10 changes: 5 additions & 5 deletions examples/BHI260AP_aux_BMM150/BHI260AP_aux_BMM150.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
* @file BHI260AP_aux_BMM150.ino
* @author Lewis He (lewishe@outlook.com)
* @date 2024-07-22
*
* @note Changed from Boschsensortec API https://github.com/boschsensortec/BHY2_SensorAPI
*/
#include <Wire.h>
#include <SPI.h>
#include <Arduino.h>
#include "SensorBHI260AP.hpp"

/*
Write the firmware containing the BMM150 magnetometer function into the flash.
This function requires the BHI260AP external SPI Flash.
Write the firmware containing the BMM150 magnetometer function into the flash.
This function requires the BHI260AP external SPI Flash.
If there is no Flash, it can only be written and run in RAM.
Example firmware source: https://github.com/boschsensortec/BHY2_SensorAPI/tree/master/firmware
You can also compile custom firmware to write
Expand Down Expand Up @@ -70,8 +70,8 @@ const size_t fw_size = sizeof(bhi26ap_aux_bmm150_fw);

SensorBHI260AP bhy;

void bhy_process_callback(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len)

void bhy_process_callback(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len, uint64_t *timestamp)
{
struct bhy2_data_xyz data;
float scaling_factor = get_sensor_default_scaling(sensor_id);
Expand Down
9,710 changes: 9,710 additions & 0 deletions examples/BHI260AP_aux_BMM150_euler/BHI260AP_aux_BMM150-flash.fw.h

Large diffs are not rendered by default.

8,939 changes: 8,939 additions & 0 deletions examples/BHI260AP_aux_BMM150_euler/BHI260AP_aux_BMM150.fw.h

Large diffs are not rendered by default.

171 changes: 171 additions & 0 deletions examples/BHI260AP_aux_BMM150_euler/BHI260AP_aux_BMM150_euler.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/**
*
* @license MIT License
*
* Copyright (c) 2024 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file BHI260AP_aux_BMM150_euler.ino
* @author Lewis He (lewishe@outlook.com)
* @date 2024-07-23
* @note Changed from Boschsensortec API https://github.com/boschsensortec/BHY2_SensorAPI
*/
#include <Wire.h>
#include <SPI.h>
#include <Arduino.h>
#include "SensorBHI260AP.hpp"

/*
Write the firmware containing the BMM150 magnetometer function into the flash.
This function requires the BHI260AP external SPI Flash.
If there is no Flash, it can only be written and run in RAM.
Example firmware source: https://github.com/boschsensortec/BHY2_SensorAPI/tree/master/firmware
You can also compile custom firmware to write
How to build custom firmware see : https://www.bosch-sensortec.com/media/boschsensortec/downloads/application_notes_1/bst-bhi260ab-an000.pdf
*/
#define WRITE_TO_FLASH 1 //Set 1 write fw to flash ,set 0 write fw to ram

#ifdef WRITE_TO_FLASH
#include "BHI260AP_aux_BMM150-flash.fw.h"
const uint8_t *firmware = bhi26ap_aux_bmm150_flash_fw;
const size_t fw_size = sizeof(bhi26ap_aux_bmm150_flash_fw);

#else
#include "BHI260AP_aux_BMM150.fw.h"
const uint8_t *firmware = bhi26ap_aux_bmm150_fw;
const size_t fw_size = sizeof(bhi26ap_aux_bmm150_fw);
#endif

#ifdef BHY2_USE_I2C
#define BHI260AP_SDA 21
#define BHI260AP_SCL 22
#define BHI260AP_IRQ 39
#define BHI260AP_RST -1
#else
#define BHI260AP_MOSI 27
#define BHI260AP_MISO 46
#define BHI260AP_SCK 3
#define BHI260AP_CS 28
#define BHI260AP_IRQ 30
#define BHI260AP_RST -1
#endif


SensorBHI260AP bhy;


void parse_euler(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len, uint64_t *timestamp)
{
struct bhy2_data_orientation data;
uint32_t s, ns;
uint64_t tns;

// Function to parse FIFO frame data into orientation
bhy2_parse_orientation(data_ptr, &data);

uint64_t _timestamp = *timestamp;
time_to_s_ns(_timestamp, &s, &ns, &tns);

uint8_t accuracy = bhy.getAccuracy();
if (accuracy) {
Serial.printf("SID: %u; T: %u.%09u; h: %f, p: %f, r: %f; acc: %u\r\n",
sensor_id,
s,
ns,
data.heading * 360.0f / 32768.0f,
data.pitch * 360.0f / 32768.0f,
data.roll * 360.0f / 32768.0f,
accuracy);
} else {
Serial.printf("SID: %u; T: %u.%09u; h: %f, p: %f, r: %f\r\n",
sensor_id,
s,
ns,
data.heading * 360.0f / 32768.0f,
data.pitch * 360.0f / 32768.0f,
data.roll * 360.0f / 32768.0f);
}
}


void setup()
{
Serial.begin(115200);
while (!Serial);

// Set the reset pin and interrupt pin, if any
bhy.setPins(BHI260AP_RST, BHI260AP_IRQ);

// Set the firmware array address and firmware size
bhy.setFirmware(firmware, fw_size, WRITE_TO_FLASH);

#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.println(bhy.getError());
while (1) {
delay(1000);
}
}
#else
// Using SPI interface
if (!bhy.init(SPI, BHI260AP_CS, BHI260AP_MOSI, BHI260AP_MISO, BHI260AP_SCK)) {
Serial.print("Failed to init BHI260AP - ");
Serial.println(bhy.getError());
while (1) {
delay(1000);
}
}
#endif

Serial.println("Init BHI260AP Sensor success!");

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

float sample_rate = 100.0; /* Read out hintr_ctrl measured at 100Hz */
uint32_t report_latency_ms = 0; /* Report immediately */

/*
* Enable Euler function
* The Euler function depends on BMM150.
* If the hardware is not connected to BMM150, the Euler function cannot be used.
* * */
bhy.configure(SENSOR_EULER_ID, sample_rate, report_latency_ms);

// Register event callback function
bhy.onResultEvent(SENSOR_EULER_ID, parse_euler);


}


void loop()
{
// Update sensor fifo
bhy.update();
delay(50);
}



Loading

0 comments on commit 4e00d3e

Please sign in to comment.