Problem with running "orientation.ino" sample code in BHI160 Sensor Hub Arduino library
My team is in the process of building a wearable product, and are currently testing using the BHI160 Sensor Hub with the nRF52832 Adafruit Feather. For some contextual information between the sensor hub and the Adafruit nRF boards, respectively, both VDD and VDDIO are tied to 3.3V, GND is tied to GND, SDA is tied to SDA, SCL is tied to SCL, and INTC/IO7 is tied to pin 7. In addition, the appropriate 2.2 KOhm resistors are being used as pullups on the I2C bus.
We are having trouble running the orientation.ino sample code provided in the library. The application code being tested can be found below. You will notice that there is one change made to the original "orientation.ino" example found in the library. The firmware hex file was changed to "Bosch_PCB_7183_di01_BMI160-7183_di01.2.1.10836_170103.h". This was because we were getting the following error message when using the original one: "Error code: (-22). RAM-Patch Mismatch".
#define BHY_INT_PIN 7
volatile bool intrToggled = false;
bool newOrientationData = false;
float heading, roll, pitch;
intrToggled = true;
intrToggled = false;
void orientationHandler(bhyVector data, bhyVirtualSensor type)
heading = data.x;
roll = data.z;
pitch = data.y;
status = data.status;
newOrientationData = true;
attachInterrupt(BHY_INT_PIN, bhyInterruptHandler, RISING);
/* Check to see if something went wrong. */
Serial.println("Sensor found over I2C! Product ID: 0x" + String(bhi160.productId, HEX));
intrToggled = false; /* Clear interrupt status received during firmware upload */
waitForBhyInterrupt(); /* Wait for meta events from boot up */
/* 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))
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.");
Serial.println(bhi160.getSensorName(BHY_VS_ORIENTATION) + " virtual sensor enabled");
intrToggled = false;
/* Can also be viewed using the plotter */
Serial.println(String(heading) + "," + String(pitch) + "," + String(roll) + "," + String(status));
newOrientationData = false;
if (bhi160.status == BHY_OK)
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) + ").");
The sketch compiles and runs but does not return any sensor data. We get the following Serial monitor output (notice the warning code 1):
Sensor found over I2C! Product ID: 0x83
Orientation callback installed
Orientation (Non Wake-up) virtual sensor enabled
Warning code: (1)
One observation that we have made is that the warning code (1) is because of line 2088 in bhy.cpp, where the acknowledgement bit is being read as 0x80 due to an invalid parameter number (227) being written. According to the documentation, only numbers between 1-127 (for Parameter Page 3) are valid.
Another observation we made was that the "orientationHandler" ISR is never being called, and therefore, newOrientationData is never being set to true. We are not too sure of what is happening in the following vector callback function: "bhi160.installSensorCallback(BHY_VS_ORIENTATION, true, orientationHandler)". We believe that there is something weird going on in its function definition located in the bhy.cpp file.
We are not sure what is going on here, and any help would be greatly appreciated.
Re: Problem with running "orientation.ino" sample code in BHI160 Sensor Hub Arduino librar
The orientation sensor is defined by Google as requiring Accelerometer, Magnetometer and (optionally) Gyroscope. https://source.android.com/devices/sensors/sensor-types#orientation_deprecated
The RAM patch your are using does not include Magnetometer support, as hinted in the lack of "BMM150" in the filename, and therefore does not support Orientation.
I believe that you are looking for Game Rotation Vector : https://source.android.com/devices/sensors/sensor-types#game_rotation_vector