-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v0.1.0 f the BHI160 Sensor Hub Arduino library
- Loading branch information
0 parents
commit 09680a4
Showing
12 changed files
with
8,480 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# BHI160 Sensor Hub Arduino library | ||
|
||
## Sensor Overview | ||
|
||
The BHI160 is a small, low-power smart-hub with an integrated three axis gyroscope, an integrated three axis accelerometer, and a programmable microcontroller. Containing pre-installed software and specific algorithms for activity recognition it is specifically designed to enable always-on motion sensing. It perfectly matches the requirements of smartphones, wearables or any other application which demands accurate, real-time motion data at very low power consumption. The device integrates our best-in-class 6-axis IMU (BMI160) with an MCU – the new Bosch Sensortec Fuser core. It is bringing you the full Android sensor stack inside your devices – even without having an Android OS or an Android environment. Combining this with the built in computing power and the highly configurable on-board memory the BHI160 offers you a low power solution for motion sensing and data processing. Software binaries included! | ||
|
||
### Applications | ||
|
||
- Activity recognition of standing, walking, running, biking or in vehicle | ||
- Step-counting, Indoor navigation and PDR | ||
- HMI interfaces incl. gesture detection of motion, tilt, pickup, wake up, glance or other gestures for wearables | ||
- Augmented reality, immersive gaming and tilt-compensated eCompass | ||
- Full 9DoF data fusion for highly accurate 3D orientation, quaternions, Euler angles, etc. | ||
|
||
For more information refer product page [Link](https://www.bosch-sensortec.com/bst/products/all_products/bhi160) | ||
|
||
### Library reference documentation | ||
|
||
> Coming soon | ||
--- | ||
|
||
#### Copyright (C) 2019 Bosch Sensortec GmbH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#include <Wire.h> | ||
|
||
#include "bhy.h" | ||
#include "firmware\Bosch_PCB_7183_di03_BMI160-7183_di03.2.1.11696_170103.h" | ||
|
||
#define BHY_INT_PIN 10 | ||
|
||
BHYSensor bhi160; | ||
|
||
volatile bool intrToggled = false; | ||
|
||
bool checkSensorStatus(void); | ||
|
||
void bhyInterruptHandler(void) | ||
{ | ||
intrToggled = true; | ||
} | ||
void waitForBhyInterrupt(void) | ||
{ | ||
while (!intrToggled) | ||
; | ||
intrToggled = false; | ||
} | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
Wire.begin(); | ||
|
||
if (Serial) | ||
{ | ||
Serial.println("Serial working"); | ||
} | ||
|
||
attachInterrupt(BHY_INT_PIN, bhyInterruptHandler, RISING); | ||
|
||
bhi160.begin(BHY_I2C_ADDR2); | ||
|
||
// Check to see if something went wrong. | ||
if (!checkSensorStatus()) | ||
return; | ||
|
||
Serial.println("Sensor found over I2C! Product ID: 0x" + String(bhi160.productId, HEX)); | ||
|
||
Serial.println("Uploading Firmware."); | ||
bhi160.loadFirmware(bhy1_fw); | ||
|
||
if (!checkSensorStatus()) | ||
return; | ||
|
||
intrToggled = false; /* Clear interrupt status received during firmware upload */ | ||
waitForBhyInterrupt(); /* Wait for meta events from boot up */ | ||
Serial.println("Firmware booted"); | ||
|
||
/* Install a metaevent callback handler and a timestamp callback handler here if required before the first run */ | ||
bhi160.run(); /* The first run processes all boot events */ | ||
|
||
/* Link callbacks and configure desired virtual sensors here */ | ||
|
||
if (checkSensorStatus()) | ||
Serial.println("All ok"); | ||
} | ||
|
||
void loop() | ||
{ | ||
if (intrToggled) | ||
{ | ||
intrToggled = false; | ||
bhi160.run(); | ||
checkSensorStatus(); | ||
} | ||
} | ||
|
||
bool checkSensorStatus(void) | ||
{ | ||
if (bhi160.status == BHY_OK) | ||
return true; | ||
|
||
if (bhi160.status < BHY_OK) /* All error codes are negative */ | ||
{ | ||
Serial.println("Error code: (" + String(bhi160.status) + "). " + bhi160.getErrorString(bhi160.status)); | ||
|
||
return false; /* Something has gone wrong */ | ||
} | ||
else /* All warning codes are positive */ | ||
{ | ||
Serial.println("Warning code: (" + String(bhi160.status) + ")."); | ||
|
||
return true; | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#include <Wire.h> | ||
|
||
#include "bhy.h" | ||
#include "firmware\Bosch_PCB_7183_di03_BMI160_BMM150-7183_di03.2.1.11696_170103.h" | ||
|
||
#define BHY_INT_PIN 10 | ||
|
||
BHYSensor bhi160; | ||
|
||
volatile bool intrToggled = false; | ||
bool newOrientationData = false; | ||
float heading, roll, pitch; | ||
uint8_t status; | ||
|
||
bool checkSensorStatus(void); | ||
|
||
void bhyInterruptHandler(void) | ||
{ | ||
intrToggled = true; | ||
} | ||
void waitForBhyInterrupt(void) | ||
{ | ||
while (!intrToggled) | ||
; | ||
intrToggled = false; | ||
} | ||
void orientationHandler(bhyVector data, bhyVirtualSensor type) | ||
{ | ||
heading = data.x; | ||
roll = data.z; | ||
pitch = data.y; | ||
status = data.status; | ||
newOrientationData = true; | ||
} | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
Wire.begin(); | ||
|
||
if (Serial) | ||
{ | ||
Serial.println("Serial working"); | ||
} | ||
|
||
attachInterrupt(BHY_INT_PIN, bhyInterruptHandler, RISING); | ||
|
||
bhi160.begin(BHY_I2C_ADDR2); | ||
|
||
/* Check to see if something went wrong. */ | ||
if (!checkSensorStatus()) | ||
return; | ||
|
||
Serial.println("Sensor found over I2C! Product ID: 0x" + String(bhi160.productId, HEX)); | ||
|
||
Serial.println("Uploading Firmware."); | ||
bhi160.loadFirmware(bhy1_fw); | ||
|
||
if (!checkSensorStatus()) | ||
return; | ||
|
||
intrToggled = false; /* Clear interrupt status received during firmware upload */ | ||
waitForBhyInterrupt(); /* Wait for meta events from boot up */ | ||
Serial.println("Firmware booted"); | ||
|
||
/* Install a metaevent callback handler and a timestamp callback handler here if required before the first run */ | ||
bhi160.run(); /* The first run processes all boot events */ | ||
|
||
/* Install a vector callback function to process the data received from the wake up Orientation sensor */ | ||
if (bhi160.installSensorCallback(BHY_VS_ORIENTATION, true, orientationHandler)) | ||
{ | ||
checkSensorStatus(); | ||
|
||
return; | ||
} | ||
else | ||
Serial.println("Orientation callback installed"); | ||
|
||
/* Enable the Orientation virtual sensor that gives you the heading, roll, pitch | ||
based of data from the accelerometer, gyroscope and magnetometer. | ||
The sensor is set into wake up mode so as to interrupt the host when a new sample is available | ||
Additionally, the FIFO buffer of the sensor is flushed for all previous data | ||
The maximum report latency of the sensor sample, the sensitivity and the dynamic range | ||
are set to 0 | ||
*/ | ||
if (bhi160.configVirtualSensor(BHY_VS_ORIENTATION, true, BHY_FLUSH_ALL, 200, 0, 0, 0)) | ||
{ | ||
Serial.println("Failed to enable virtual sensor (" + bhi160.getSensorName( | ||
BHY_VS_ORIENTATION) + "). Loaded firmware may not support requested sensor id."); | ||
} | ||
else | ||
Serial.println(bhi160.getSensorName(BHY_VS_ORIENTATION) + " virtual sensor enabled"); | ||
|
||
} | ||
|
||
void loop() | ||
{ | ||
if (intrToggled) | ||
{ | ||
intrToggled = false; | ||
bhi160.run(); | ||
checkSensorStatus(); | ||
if (newOrientationData) | ||
{ | ||
/* Can also be viewed using the plotter */ | ||
Serial.println(String(heading) + "," + String(pitch) + "," + String(roll) + "," + String(status)); | ||
newOrientationData = false; | ||
} | ||
} | ||
} | ||
|
||
bool checkSensorStatus(void) | ||
{ | ||
if (bhi160.status == BHY_OK) | ||
return true; | ||
|
||
if (bhi160.status < BHY_OK) /* All error codes are negative */ | ||
{ | ||
Serial.println("Error code: (" + String(bhi160.status) + "). " + bhi160.getErrorString(bhi160.status)); | ||
|
||
return false; /* Something has gone wrong */ | ||
} | ||
else /* All warning codes are positive */ | ||
{ | ||
Serial.println("Warning code: (" + String(bhi160.status) + ")."); | ||
|
||
return true; | ||
} | ||
|
||
return true; | ||
} |
Oops, something went wrong.
09680a4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Help me ~
I use Arduino UNO and BHI160 shuttle board.
This source will output an error message stating that the memory is insufficient.
Is there a solution?
09680a4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @vegito4,
The Arduino Uno and other similar AVR devices do not have enough memory to store the binary of the BHI160 sensor. Also, the BHI160 cannot connect to a 5V device without having voltage level translators.
Kindly report all issues to the BST Community forum.