Skip to content

Commit

Permalink
Added BHI260 example
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Oct 4, 2023
1 parent 99eec29 commit 31ab2fd
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/workflows/arduino_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
examples/XL9555_ExtensionIOInterrupt/XL9555_ExtensionIOInterrupt.ino,
examples/XL9555_ExtensionIORead/XL9555_ExtensionIORead.ino,
examples/XL9555_ExtensionIOWirte/XL9555_ExtensionIOWirte.ino,
examples/BHI260AP_6DoF/BHI260AP_6DoF.ino,
]

env:
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/pio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ on:
pull_request:
push:
paths:
- 'examples/**'
- 'src/**'
- "examples/**"
- "src/**"

jobs:
build:
Expand Down Expand Up @@ -51,6 +51,7 @@ jobs:
examples/XL9555_ExtensionIOInterrupt/XL9555_ExtensionIOInterrupt.ino,
examples/XL9555_ExtensionIORead/XL9555_ExtensionIORead.ino,
examples/XL9555_ExtensionIOWirte/XL9555_ExtensionIOWirte.ino,
examples/BHI260AP_6DoF/BHI260AP_6DoF.ino,
]

steps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file BHI260AP_Accelerometer.ino
* @file BHI260AP_6DoF.ino
* @author Lewis He (lewishe@outlook.com)
* @date 2023-09-06
*
Expand All @@ -36,12 +36,13 @@
#define BHI260AP_SDA 21
#define BHI260AP_SCL 22
#define BHI260AP_IRQ 39
#define BHI260AP_RST -1
#else
#define BHI260AP_MOSI 33
#define BHI260AP_MISO 34
#define BHI260AP_SCK 35
#define BHI260AP_CS 36
#define BHI260AP_INT 37
#define BHI260AP_IRQ 37
#define BHI260AP_RST -1
#endif

Expand All @@ -53,7 +54,23 @@ void setup()
Serial.begin(115200);
while (!Serial);

bhy.setPins(BHI260AP_RST, BHI260AP_INT);

//TODO:
bhy.onEvent( BHY2_EVENT_INITIALIZED, [](uint8_t event, uint8_t *data, uint32_t size) {
Serial.println("===========BHY2_EVENT_INITIALIZED==========");
});

bhy.onEvent( BHY2_EVENT_SAMPLE_RATE_CHANGED, [](uint8_t event, uint8_t *data, uint32_t size) {
Serial.println("===========BHY2_EVENT_SAMPLE_RATE_CHANGED==========");
});

bhy.onEvent( BHY2_EVENT_POWER_MODE_CHANGED, [](uint8_t event, uint8_t *data, uint32_t size) {
Serial.println("===========BHY2_EVENT_POWER_MODE_CHANGED==========");
});



bhy.setPins(BHI260AP_RST, BHI260AP_IRQ);

#ifdef BHY2_USE_I2C
if (!bhy.init(Wire, BHI260AP_SLAVE_ADDRESS, BHI260AP_SDA, BHI260AP_SCL)) {
Expand All @@ -64,7 +81,8 @@ void setup()
}
#else
if (!bhy.init(SPI, BHI260AP_CS, BHI260AP_MOSI, BHI260AP_MISO, BHI260AP_SCK)) {
Serial.println("Failed to find BHI260AP - check your wiring!");
Serial.print("Failed to find BHI260AP - ");
Serial.println(bhy.getError());
while (1) {
delay(1000);
}
Expand All @@ -76,12 +94,40 @@ void setup()

bhy.printSensors(Serial);

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

bhy.configure(SENSOR_ID_ACC_PASS, sample_rate, report_latency_ms);
bhy.configure(SENSOR_ID_GYRO_PASS, sample_rate, report_latency_ms);


bhy.onResultEvent(SENSOR_ID_ACC_PASS, [](float scaling_factor, uint8_t *data_ptr, uint32_t len) {
struct bhy2_data_xyz data;
bhy2_parse_xyz(data_ptr, &data);
Serial.printf("ACCEL-> x: %f, y: %f, z: %f;\r\n",
data.x * scaling_factor,
data.y * scaling_factor,
data.z * scaling_factor
);

});

bhy.onResultEvent(SENSOR_ID_GYRO_PASS, [](float scaling_factor, uint8_t *data_ptr, uint32_t len) {
struct bhy2_data_xyz data;
bhy2_parse_xyz(data_ptr, &data);
Serial.printf("GYRO-> x: %f, y: %f, z: %f;\r\n",
data.x * scaling_factor,
data.y * scaling_factor,
data.z * scaling_factor
);
});

}


void loop()
{
bhy.update();
delay(50);
}

Expand Down
22 changes: 17 additions & 5 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
; src_dir = examples/XL9555_ExtensionIOWirte
; src_dir = examples/DRV2605_Basic
; src_dir = examples/CM32181_LightSensor
src_dir = examples/CM32181_LightSensorInterrupt
; src_dir = examples/BHI260AP_Accelerometer
; src_dir = examples/CM32181_LightSensorInterrupt
; src_dir = examples/LTR553ALS_Sensor
src_dir = examples/BHI260AP_6DoF

; Touch devices support list
; src_dir = examples/TouchDrv_FT3267_LilyGo_T_RGB
Expand All @@ -50,11 +50,12 @@ src_dir = examples/CM32181_LightSensorInterrupt
; src_dir = examples/TouchDrv_CSTxxx_GetPoint


; default_envs = esp32-s3n4r2
default_envs=esp32s3-opi
default_envs = esp32-s3n4r2
; default_envs=esp32s3-opi
; default_envs=esp32s3-qspi
; default_envs=esp32c3
; default_envs=esp32dev
; default_envs = rp2040

; Custom board variant
boards_dir = ./board
Expand All @@ -80,21 +81,32 @@ build_flags =
-DCORE_DEBUG_LEVEL=4

[env:esp32dev]
extends = env
platform = espressif32
framework = arduino
board = esp32dev

[env:esp32s3-opi]
extends = env
platform = espressif32
framework = arduino
board = ESP32-S3-R8-OPI

[env:esp32c3]
extends = env
platform = espressif32
framework = arduino
board = esp32-c3-devkitm-1

[env:esp32-s3n4r2]
extends = env
platform = espressif32
framework = arduino
board = ESP32-S3-N4R2-QSPI
board = ESP32-S3-N4R2-QSPI

[env:rp2040]
extends = env
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = pico
framework = arduino
board_build.core = earlephilhower

0 comments on commit 31ab2fd

Please sign in to comment.