getSensorEvent() running forever using UART on BNO085

In our project, we are using UART to communicate from an ESP32 Itsy Bitsy microcontroller to a BNO085 IMU, and the getSensorEvent() that is responsible to grab sensor data from the IMU is looping forever. Why is this?

Below is the code. In our serial monitor, we receive the print statements from each println up to Serial.println("Before getSensorEvent") , after which getSensorEvent() runs and we do not receive any more print statements.

// Basic demo for readings from Adafruit BNO08x
#include <Adafruit_BNO08x.h>

// For SPI mode, we need a CS pin
#define BNO08X_CS 10
#define BNO08X_INT 9

// For SPI mode, we also need a RESET 
//#define BNO08X_RESET 5
// but not for I2C or UART
#define BNO08X_RESET -1

Adafruit_BNO08x  bno08x(BNO08X_RESET);
sh2_SensorValue_t sensorValue;

void setup(void) {
  Serial.begin(115200);
  delay(5000);
  while (!Serial) delay(10);     // will pause Zero, Leonardo, etc until serial console opens

  Serial.println("Adafruit BNO08x test!");

  // Try to initialize!
  //if (!bno08x.begin_I2C()) {
  while (!bno08x.begin_UART(&Serial1)) {  // Requires a device with > 300 byte UART buffer!
  //if (!bno08x.begin_SPI(BNO08X_CS, BNO08X_INT)) {
    Serial.println("Failed to find BNO08x chip");
    //while (1) { delay(10); }
    delay(10);
  }
  Serial.println("BNO08x Found!");

  for (int n = 0; n < bno08x.prodIds.numEntries; n++) {
    Serial.print("Part ");
    Serial.print(bno08x.prodIds.entry[n].swPartNumber);
    Serial.print(": Version :");
    Serial.print(bno08x.prodIds.entry[n].swVersionMajor);
    Serial.print(".");
    Serial.print(bno08x.prodIds.entry[n].swVersionMinor);
    Serial.print(".");
    Serial.print(bno08x.prodIds.entry[n].swVersionPatch);
    Serial.print(" Build ");
    Serial.println(bno08x.prodIds.entry[n].swBuildNumber);
  }

  setReports();

  Serial.println("Reading events");
  delay(100);
}

// Here is where you define the sensor outputs you want to receive
void setReports(void) {
  Serial.println("Setting desired reports");
  if (!bno08x.enableReport(SH2_GAME_ROTATION_VECTOR)) {
    Serial.println("Could not enable game vector");
  } else {
    Serial.println("Game vector enabled");
  }
}


void loop() {
  delay(10);

  if (bno08x.wasReset()) {
    Serial.print("sensor was reset ");
    setReports();
  }

  Serial.println("Before getSensorEvent");

  while (!bno08x.getSensorEvent(&sensorValue)) {
    Serial.println("No new sensor event");
    return;
  }

  Serial.println("After getSensorEvent");
  
  Serial.print("Sensor ID: ");
  Serial.println(sensorValue.sensorId);
  
  switch (sensorValue.sensorId) {
    case SH2_GAME_ROTATION_VECTOR:
      Serial.print("Game Rotation Vector - r: ");
      Serial.print(sensorValue.un.gameRotationVector.real);
      Serial.print(" i: ");
      Serial.print(sensorValue.un.gameRotationVector.i);
      Serial.print(" j: ");
      Serial.print(" k: ");
      Serial.println(sensorValue.un.gameRotationVector.k);
      break;
    // Add more cases here for other sensor types if needed
  }
}

Post an annotated schematic showing exactly how this is interconnected. Please be sure to label the connections.

Here is the picture of the labeled circuit. The microcontroller on the left is the ITSY BITSY ESP32 microcontroller, and the right is the BNO085. Let me know if you spot any issues

Are you sure you don't have RX and TX backwards on the itsy bitsy?

Per the AdaFruit ItsyBitsy ESP32 pinouts at Pinouts | Adafruit ItsyBitsy ESP32 | Adafruit Learning System
it looks like the Serial1 TX is on the end & RX is the 2nd to the end:


I think my pins and connections are correct. If you look at the pinout diagram attached, I have the Tx wire connected to GPIO 20 and the Rx wire connected to GPIO 8.

That attempt at soldering is completely unfit for purpose. I can't see most of the header pins being electrically connected to the pads.

1 Like

You are right. The other pinout and the board schematic show RX/8 on the end:

Do you know that you have good connections? Can you see the data twiddle the times with an Oscilloscope or something else?

If there isn't communication between the devices, you would have the same symptoms.