BNO08x on a QT Py ESP32 Pico not working

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
garyrkey
 
Posts: 13
Joined: Fri Feb 07, 2014 8:14 pm

BNO08x on a QT Py ESP32 Pico not working

Post by garyrkey »

I recently received a new QT Py ESP32 Pico (https://www.adafruit.com/product/5395) and connect a BNO08x 9 DoF sensor (https://www.adafruit.com/product/4754) to it using a short QWIIC cable.

Using the latest Arduino IDE I loaded or updated the relevant software using the board and libraries managers to the current levels.

Board settings were set like https://learn.adafruit.com/adafruit-qt- ... -3108136-5 (except for upload speed, which I set to 115200).

When I uploaded the BNO08x example "more_reports" the BNO08x was not found, and following a reset the following message was shown:
"
ets Jul 29 2019 12:21:46

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 271414342, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1184
load:0x40078000,len:12812
load:0x40080400,len:3032
entry 0x400805e4
Adafruit BNO08x test!
I2C address not found <<<<<<<<
Failed to find BNO08x chip <<<<<<<<
"

I loaded the "Adafruit Testbed", selected "I2C_Scan", and uploaded it. The results were:
"
Default port (Wire) I2C scan:
Secondary port (Wire1) I2C scan: 0x4A,
"
This appears to indicate that the QT Py can see the BN08x, and the 0x4A address appears correct.

I tried a 2.2k pull-up to 3.3V on the SDA line (on the BNO08x board breakout pins) with no success.

I attached the BNO08x to a Adafruit Feather STM32F405 (https://www.adafruit.com/product/4382) using the same cable, and all worked as expected.

I've searched the Forum, and found a few related looking post, but nothing that solves this problem.

So, I'm basically out of ideas.
Any thoughts, suggestions, or help will be appreciated.

Thanks!

Gary

User avatar
mikeysklar
 
Posts: 13823
Joined: Mon Aug 01, 2016 8:10 pm

Re: BNO08x on a QT Py ESP32 Pico not working

Post by mikeysklar »

Gary,

Can you post the example code you are trying to run on the QtPy? It looks like there is some mention of SPI issues in the errors you pasted in, but if you are using the QtPy stemma cable that would be i2c. I suspect there could be a setting in the example code that needs to be modified for i2c mode.

User avatar
garyrkey
 
Posts: 13
Joined: Fri Feb 07, 2014 8:14 pm

Re: BNO08x on a QT Py ESP32 Pico not working

Post by garyrkey »

Additional information:
I changed to an Adafruit STM32F405 feather (from the QT Py ESP32) using the same cable and BNO08x board and the same example code, and it runs as expected.
So, it seems that sensor, cable, and code can be assumed good at this point.
I'm going to try a couple of other sensors and a different QT Py board next.

User avatar
adafruit2
 
Posts: 22111
Joined: Fri Mar 11, 2005 7:36 pm

Re: BNO08x on a QT Py ESP32 Pico not working

Post by adafruit2 »

you need to use Wire1 and use Wire1.setPins first in order use the QT Port - check the pico guide for example code

User avatar
garyrkey
 
Posts: 13
Joined: Fri Feb 07, 2014 8:14 pm

Re: BNO08x on a QT Py ESP32 Pico not working

Post by garyrkey »

I have taken the BNO08x example code and mod-defiled it to only initialize the BNO08x.
I don't understand the statement in one of the Primary Guides that "...we need to reference
Wire1 for I2C communication..." (see below, in the code comment).

The Simplified Code:

Code: Select all

#include <Adafruit_BNO08x.h>
#define BNO08X_RESET -1
Adafruit_BNO08x bno08x(BNO08X_RESET);

#define DEFAULT_I2C_PORT &Wire
#define SECONDARY_I2C_PORT &Wire1    //?????????? is this a sufficient reference to Wire1?

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

  Wire1.setPins(SDA1, SCL1);

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

  if (!bno08x.begin_I2C()) {
    Serial.println("Failed to find BNO08x chip");
    while (1) {delay(10);}
  }
  Serial.println("BNO08x Found!");
}

void loop() {
  while (1) {delay(10);}
}
This code compiles, uploads, and prints the following:

Code: Select all

Adafruit BNO08x test!
I2C address not found
Failed to find BNO08x chip
Can someone please ELI5 what I am missing?

Thanks,
Gary
Last edited by adafruit_support_carter on Tue Jul 12, 2022 1:11 pm, edited 1 time in total.
Reason: added [code] tags

User avatar
adafruit2
 
Posts: 22111
Joined: Fri Mar 11, 2005 7:36 pm

Re: BNO08x on a QT Py ESP32 Pico not working

Post by adafruit2 »

wrt docs here: https://adafruit.github.io/Adafruit_BNO ... a1814209c8

so use
if (!bno08x.begin_I2C( BNO08x_I2CADDR_DEFAULT,&Wire1)) {

User avatar
garyrkey
 
Posts: 13
Joined: Fri Feb 07, 2014 8:14 pm

Re: BNO08x on a QT Py ESP32 Pico not working

Post by garyrkey »

Well, I have tried multiple controllers and multiple sensors using the QWIIC connection scheme. The only combination that I cannot get to work is when the BNO08x sensor board is used.
So, is there a problem with the BNO08x library? Maybe I should just toss these boards, and use something else, but then I guess I have a form of OCD, because I want to understand why they don't work first.

Here's the code that fails:

Code: Select all

#include <Adafruit_BNO08x.h>
#define BNO08X_RESET -1
Adafruit_BNO08x  bno08x(BNO08X_RESET);

#define DEFAULT_I2C_PORT &Wire
#define SECONDARY_I2C_PORT &Wire1
#define BNO08x_I2C_2nd_Addr 0x4A

void setup(void) {
  Serial.begin(115200);
  while (!Serial) delay(10);
  
  Wire1.setPins(SDA1, SCL1);  // Because esp32?
  
  Serial.println("Adafruit BNO08x test!");
  
  if (!bno08x.begin_I2C(BNO08x_I2C_2nd_Addr, SECONDARY_I2C_PORT)) {
    Serial.println("Failed to find BNO08x chip");
    while (1) { delay(10); }
  }
  Serial.println("BNO08x Found!");
}

void loop() {
  delay(100);
}
Thanks for any suggestions ( well, other than deep psychotherapy :-)

Gary
Last edited by adafruit_support_carter on Tue Jul 12, 2022 1:12 pm, edited 1 time in total.
Reason: added [code] tags

User avatar
adafruit2
 
Posts: 22111
Joined: Fri Mar 11, 2005 7:36 pm

Re: BNO08x on a QT Py ESP32 Pico not working

Post by adafruit2 »

ok tried it as well and ... it doesnt work at all with esp32! :( we spent a few hours debugging it but our attempts to figure out whats up were not successful - esp32 is not getting correct data and its getting confused. the driver used to but theres a lot of changes recently, these two bugs MAY be related:
https://github.com/espressif/arduino-esp32/issues/6553
https://github.com/espressif/arduino-esp32/issues/6842
there's not much we can suggest right now - theres no easy fix. you may just have to try another chipset! the bno085 and bno055 are notoriously 'unfriendly' i2c chips that do a lot of stuff that make i2c controllers upset.

User avatar
garyrkey
 
Posts: 13
Joined: Fri Feb 07, 2014 8:14 pm

Re: BNO08x on a QT Py ESP32 Pico not working

Post by garyrkey »

Thank you! At least I don't feel like a complete moron - just a partial one, hehe. I sometimes just can't let go. Now, maybe my wife can make some cool earrings out of the BNO08xs, and I'll move on to another sensor.

I appreciate your time.

Gary

User avatar
adafruit2
 
Posts: 22111
Joined: Fri Mar 11, 2005 7:36 pm

Re: BNO08x on a QT Py ESP32 Pico not working

Post by adafruit2 »

thanks for letting us know! do keep those sensors, they're hard to get these days and they may be working eventually if those bugs are fixed :)

User avatar
gammaburst
 
Posts: 1013
Joined: Thu Dec 31, 2015 12:06 pm

Re: BNO08x on a QT Py ESP32 Pico not working

Post by gammaburst »

Hi adafruit2,

I bought a few QT Py ESP32-S2 (Adafruit 5348) and FeatherS2 (Adafruit 4769), and had no problem talking to a BNO055 (Adafruit 4646) or BNO085 (Adafruit 4754) using Arduino IDE sketches and Adafruit libraries.

I couldn't find a Pico (Adafruit 5395) to buy.

Here's my test sketch for QT Py ESP32-S2 (Adafruit 5348). It reads quaternions from a BNO085 through a Qwiic cable:

Code: Select all

#include <Adafruit_BNO08x.h>

Adafruit_BNO08x bno08x(-1);

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

  Wire1.setPins(SDA1, SCL1);  // Adafruit 5348 QT Py ESP32-S2: Qwiic connector uses second I2C port
  bno08x.begin_I2C(BNO08x_I2CADDR_DEFAULT, &Wire1);
  Wire.setClock(200000L);   // I2C speed, 400 kHz is a little fast for default pullups

  bno08x.enableReport(SH2_ROTATION_VECTOR,100);
}

void loop()
{
  sh2_SensorValue_t sensorValue;
  if (!bno08x.getSensorEvent(&sensorValue))
    return;

  switch (sensorValue.sensorId)
  {
    case SH2_ROTATION_VECTOR:
      Serial.print("Quaternion: ");
      Serial.print(sensorValue.un.rotationVector.real,4);  Serial.print(" ");
      Serial.print(sensorValue.un.rotationVector.i,4);     Serial.print(" ");
      Serial.print(sensorValue.un.rotationVector.j,4);     Serial.print(" ");
      Serial.print(sensorValue.un.rotationVector.k,4);     Serial.println();
      break;
  }
}
I recommend adding an extra pullup resistor (about 2K or 3K ohms) to SDA, because otherwise it's on the verge of failure - simply touching SDA with my finger crashes I2C communication. The culprit is a timing bug in the BNO's I2C controller.

By the way, does Adafruit have a Windows 7 driver for talking to these ESP32 boards in Arduino IDE mode? I couldn't find one, so I learned how to modify the USB VID and PID values in a generic CDC-ACM installer .inf file. It seems to work fine, although the RST/BOOT buttons and COM port address changes are confusing/awkward.

User avatar
adafruit2
 
Posts: 22111
Joined: Fri Mar 11, 2005 7:36 pm

Re: BNO08x on a QT Py ESP32 Pico not working

Post by adafruit2 »

windows 7 is not supported for ESP32-S2 by espressif
https://learn.adafruit.com/adafruit-esp ... -ide-setup
you could try
https://github.com/espressif/arduino-es ... 1109081388
and let us know how it goes

for the BNO085 its seems to be an 'ESP32' (not S2 or S3) thing

User avatar
gammaburst
 
Posts: 1013
Joined: Thu Dec 31, 2015 12:06 pm

Re: BNO08x on a QT Py ESP32 Pico not working

Post by gammaburst »

Hi adafruit2,

Thanks, although kutukvpavel's procedure (at your link) is similar to the procedure that I already used to get the USB serial link working on my old Win7 machine.

When your visitors read the orange box at the top of https://learn.adafruit.com/adafruit-esp ... -ide-setup, they see "Win7 unsupported" rather than "Win7 die-hards should read kutukvpavel's simple solution in the 9th message of the linked discussion". I suggest clarifying the orange box.

I tried a plain ESP32 HUZZAH32 (Adafruit 3405), and it worked fine with BNO055, but it didn't work with BNO085. I see I2C activity but no serial output messages. I didn't attempt troubleshooting, as the BNO085 library is monstrous. Instead, I tried my old sketch that doesn't use any BNO085 library, and it outputs quaternions fine. (It also runs on small microcontrollers.) I suggest Adafruit consider creating a "lite" BNO085 library.

Code: Select all

#include <Wire.h>

#define pinRST      A3          // output pin to BNO RST (optional, but I recommend it)

#define BNO_ADDR    0x4A        // I2C address of BNO085 sensor (0x4A if SA0=0, 0x4B if SA0=1)
#define I2C_CLOCK   200000L     // I2C clock rate (Feather M4 Express: why must I specify 104000L or 480000L to get correct rates?)
#define SERIAL_BAUD 115200L     // serial port baud rate
#define SENSOR_US   10000L      // time between sensor reports, microseconds, 10000L is 100 Hz, 20000L is 50 Hz

// *******************************
// **  Request desired reports  **
// *******************************

#define QUAT_REPORT  0x05   // quaternion report, see 6.5.18
#define TIME_REPORT  0xFB   // time report, see 7.2.1

static void request_reports(void)
{
  // request quaternion reports, see 6.5.4
  static const uint8_t cmd_quat[] = {21, 0, 2, 0, 0xFD, QUAT_REPORT, 0, 0, 0, (SENSOR_US>>0)&255, (SENSOR_US>>8)&255, (SENSOR_US>>16)&255, (SENSOR_US>>24)&255, 0, 0, 0, 0, 0, 0, 0, 0};
  Wire.beginTransmission(BNO_ADDR);  Wire.write(cmd_quat, sizeof(cmd_quat));  Wire.endTransmission();

  // At 10ms rate, BNO08x outputs most reports in one burst, Gyro-Quat-Lac-Mag, however Acc is asynchronous and a few percent faster. Situation may vary with SENSOR_US and maximum sensor rates.
}

// *******************
// **  Output data  **
// *******************

int16_t iax, iay, iaz;          // accel, integer
int16_t igx, igy, igz;          // gyro, integer
int16_t imx, imy, imz;          // magneto, integer
int16_t ilx, ily, ilz;          // linear accel, integer
int16_t iqw, iqx, iqy, iqz;     // quaternion, integer

char obuf[70], *pbuf;           // ensure this output buffer is big enough for your output string!

void uart_b64(int32_t i)        // output 18-bit integer as compact 3-digit base64
{
  for (int n=12; n >= 0; n-=6)
  {
    uint8_t c = (i >> n) & 63;
    *pbuf++ = (char)(c<26 ? 'A'+c : c<52 ? 'a'-26+c : c<62 ? '0'-52+c : c==62 ? '+' : '/');
  }
}

static void output_data()
{
  // my BNO08x orientation dot is towards left rear, rotate BNO08x quaternion to NED conventions
  float q0 = iqw+iqz;
  float q1 = iqx+iqy;
  float q2 = iqx-iqy;
  float q3 = iqw-iqz;
  float norm = 1 / sqrt(q0*q0 + q1*q1 + q2*q2 + q3*q3);
  q0 *= norm;
  q1 *= norm;
  q2 *= norm;
  q3 *= norm;
  Serial.print("Quaternion: ");
  Serial.print(q0, 4);  Serial.print(" ");
  Serial.print(q1, 4);  Serial.print(" ");
  Serial.print(q2, 4);  Serial.print(" ");
  Serial.print(q3, 4);  Serial.println();
}

// ******************************************
// **  Check for and parse sensor reports  **
// ******************************************

static void ensure_read_available(int16_t length)  // ensure a read byte is available, if necessary reread and discard 4-byte SHTP header, then read as much length as possible
{
  if (!Wire.available())
    Wire.requestFrom(BNO_ADDR,4+length), Wire.read(), Wire.read(), Wire.read(), Wire.read();
}

static void check_report()
{
  int16_t length;
  uint8_t channel __attribute__((unused));
  uint8_t seqnum  __attribute__((unused));

  Wire.requestFrom(BNO_ADDR,4+1);       // read 4-byte SHTP header and first byte of cargo
  length  = Wire.read();                // length LSB
  length |= (Wire.read() & 0x7F) << 8;  // length MSB (ignore continuation flag)
  channel = Wire.read();                // channel number
  seqnum  = Wire.read();                // sequence number (ignore)
  length -= 4;                          // done reading SHTP Header
  if (length <= 0 || length > 1000)     // if null/bad/degenerate SHTP header
    return;

  while (length)                        // while more reports in cargo
  {
    uint8_t buf[20];                    // report buffer, big enough for longest interesting report (uninteresting reports will be ignored)
    uint16_t n = 0;                     // index into report buffer

    ensure_read_available(length);
    buf[n++] = Wire.read();             // first byte of report
    length--;

    // known reports
    if (channel==3 && buf[0]==TIME_REPORT && length >= 5-1)
    {
      for (uint8_t n=1; n<5; n++)       // read remainder of report
      {
        ensure_read_available(length);
        buf[n] = Wire.read();
        length--;
      }
      continue;
    }
    if (channel==3 && buf[0]==QUAT_REPORT && length >= 14-1)
    {
      for (uint8_t n=1; n<14; n++)      // read remainder of report
      {
        ensure_read_available(length);
        buf[n] = Wire.read();
        length--;
      }
      iqw = *(int16_t*)&buf[10];
      iqx = *(int16_t*)&buf[4];
      iqy = *(int16_t*)&buf[6];
      iqz = *(int16_t*)&buf[8];
      output_data();
      continue;
    }

    // unknown reports
    while (length)                      // discard remainder of cargo (shouldn't happen very often)
    {
      ensure_read_available(length);
      Wire.read();
      length--;
    }
    continue;
  }
  return;
}

// **********************
// **  Setup and Loop  **
// **********************

void setup()
{
  Serial.begin(SERIAL_BAUD);            // initialize serial
  Serial.println("\nRunning...");

  pinMode(pinRST,OUTPUT);               // reset BNO
  digitalWrite(pinRST,LOW);
  delay(1);
  digitalWrite(pinRST,HIGH);
  delay(300);

  Wire.begin();                         // initialize I2C
  Wire.setClock(I2C_CLOCK);

  request_reports();                    // request desired reports

  do                                    // wait until BNO outputs non-zero quaternions
    check_report();
  while (!iqw && !iqx && !iqy && !iqz);
}

void loop()
{
  check_report();                       // check for reports
}
I have another version of this code that outputs additional sensor values such as acceleratometer and gyro, in case anyone is interested.

User avatar
adafruit2
 
Posts: 22111
Joined: Fri Mar 11, 2005 7:36 pm

Re: BNO08x on a QT Py ESP32 Pico not working

Post by adafruit2 »

great, we've added their windows driver for folks still using windows 7. we dont have a solution to bno085 on ESP32 right now - if someone can open an issue on the github repo it would help us track it!

User avatar
gammaburst
 
Posts: 1013
Joined: Thu Dec 31, 2015 12:06 pm

Re: BNO08x on a QT Py ESP32 Pico not working

Post by gammaburst »

Hi adafruit2,

Thanks for updating the orange box. That info would have saved me about a day's work.

I updated my above example sketch - reads BNO085 quaternions without using a BNO085 library.
You can now choose the I2C port with a macro.
You can now choose the BNO reset method with a macro.
It runs smoothly on my QT Py ESP32-S2.

Be sure to add the extra pullup resistor to SDA (about 2K to 3K ohms).
Without that resistor, the project runs badly or not at all.
If using a STEMMA/Qwiic cable, connect the resistor to the BNO pins, not the ESP32-S2 pins.

Code: Select all

#include <Wire.h>

#define I2C_PORT    2           // 1 selects first I2C port, 2 selects second I2C port
#define BNO_ADDR    0x4A        // I2C address of BNO085 (0x4A if SA0=0, 0x4B if SA0=1)
//#define pinRST    A3          // comment-out this line to soft-reset BNO with a command, uncomment this line to output a hard-reset pulse to BNO's RST pin
#define I2C_CLOCK   200000L     // I2C clock rate
#define SERIAL_BAUD 115200L     // serial port baud rate
#define SENSOR_US   10000L      // time between sensor reports, microseconds, 10000L is 100 Hz, 20000L is 50 Hz, etc.

// *******************
// **  Output data  **
// *******************

int16_t iqw, iqx, iqy, iqz;             // quaternion, integer

static void output_data()
{
  // my BNO08x orientation dot is towards left rear, rotate BNO08x quaternion to NED conventions
  float q0 = iqw+iqz;
  float q1 = iqx+iqy;
  float q2 = iqx-iqy;
  float q3 = iqw-iqz;
  float norm = 1 / sqrt(q0*q0 + q1*q1 + q2*q2 + q3*q3);
  q0 *= norm;
  q1 *= norm;
  q2 *= norm;
  q3 *= norm;
  Serial.print("Quaternion: ");
  Serial.print(q0, 4);  Serial.print(" ");
  Serial.print(q1, 4);  Serial.print(" ");
  Serial.print(q2, 4);  Serial.print(" ");
  Serial.print(q3, 4);  Serial.println();
}

#if I2C_PORT == 1                       // use first I2C port
  #define WIRE Wire
  #define SELECT_I2C_PINS()
#elif I2C_PORT == 2                     // use second I2C port
  #define WIRE Wire1
  #define SELECT_I2C_PINS()  WIRE.setPins(SDA1,SCL1)  // Adafruit advises this for QT Py ESP32-S2
#endif

// *******************************
// **  Request desired reports  **
// *******************************

#define QUAT_REPORT  0x05               // quaternion report, see 6.5.18
#define TIME_REPORT  0xFB               // time report, see 7.2.1

static void request_reports(void)
{
  // request quaternion reports, see 6.5.4
  static const uint8_t cmd_quat[] = {21, 0, 2, 0, 0xFD, QUAT_REPORT, 0, 0, 0, (SENSOR_US>>0)&255, (SENSOR_US>>8)&255, (SENSOR_US>>16)&255, (SENSOR_US>>24)&255, 0, 0, 0, 0, 0, 0, 0, 0};
  WIRE.beginTransmission(BNO_ADDR);  WIRE.write(cmd_quat, sizeof(cmd_quat));  WIRE.endTransmission();
  // at 10ms rate, BNO08x outputs most reports in one burst, Gyro-Quat-Lac-Mag, however Acc is asynchronous and a few percent faster. Situation may vary with SENSOR_US and maximum sensor rates.
}

// ******************************************
// **  Check for and parse sensor reports  **
// ******************************************

static void ensure_read_available(int16_t length)  // ensure a read byte is available, if necessary reread and discard 4-byte SHTP header, then read as much length as possible
{
  if (!WIRE.available())
    WIRE.requestFrom(BNO_ADDR,4+length), WIRE.read(), WIRE.read(), WIRE.read(), WIRE.read();
}

static void check_report()
{
  int16_t length;
  uint8_t channel __attribute__((unused));
  uint8_t seqnum  __attribute__((unused));

  WIRE.requestFrom(BNO_ADDR,4+1);       // read 4-byte SHTP header and first byte of cargo
  length  = WIRE.read();                // length LSB
  length |= (WIRE.read() & 0x7F) << 8;  // length MSB (ignore continuation flag)
  channel = WIRE.read();                // channel number
  seqnum  = WIRE.read();                // sequence number (ignore)
  length -= 4;                          // done reading SHTP Header
  if (length <= 0 || length > 1000)     // if null/bad/degenerate SHTP header
    return;

  while (length)                        // while more reports in cargo
  {
    uint8_t buf[20];                    // report buffer, big enough for longest interesting report (uninteresting reports will be ignored)
    uint16_t n = 0;                     // index into report buffer

    ensure_read_available(length);
    buf[n++] = WIRE.read();             // first byte of report
    length--;

    // known reports
    if (channel==3 && buf[0]==TIME_REPORT && length >= 5-1)
    {
      for (uint8_t n=1; n<5; n++)       // read remainder of report
      {
        ensure_read_available(length);
        buf[n] = WIRE.read();
        length--;
      }
      continue;
    }
    if (channel==3 && buf[0]==QUAT_REPORT && length >= 14-1)
    {
      for (uint8_t n=1; n<14; n++)      // read remainder of report
      {
        ensure_read_available(length);
        buf[n] = WIRE.read();
        length--;
      }
      iqw = *(int16_t*)&buf[10];
      iqx = *(int16_t*)&buf[4];
      iqy = *(int16_t*)&buf[6];
      iqz = *(int16_t*)&buf[8];
      output_data();
      continue;
    }

    // unknown reports
    while (length)                      // discard remainder of cargo (shouldn't happen very often)
    {
      ensure_read_available(length);
      WIRE.read();
      length--;
    }
    continue;
  }
  return;
}

// **********************
// **  Setup and Loop  **
// **********************

void setup()
{
  Serial.begin(SERIAL_BAUD);            // initialize serial
  Serial.println("\nRunning...");

  #ifdef pinRST                         // hard reset BNO by pulsing its RST pin
    //hard_reset();
    pinMode(pinRST,OUTPUT);
    digitalWrite(pinRST,LOW);
    delay(2);                           // because 1 sometimes gets truncated
    digitalWrite(pinRST,HIGH);
    delay(300);                         // let BNO reboot, about 150 works marginally, so let's double it
  #endif

  // pinMode(A2,OUTPUT);  digitalWrite(A2,HIGH);  delayMicroseconds(10);  digitalWrite(A2,LOW);  delayMicroseconds(10);  // scope trigger for debugging

  SELECT_I2C_PINS();
  WIRE.begin();                         // initialize I2C
  WIRE.setClock(I2C_CLOCK);

  // clear I2C bus, just in case
  WIRE.beginTransmission(BNO_ADDR);
  WIRE.endTransmission();

  #ifndef pinRST                        // if no hard reset, soft reset BNO by sending SHTP "reset" command, see 1.3.1
    static const uint8_t cmd_reset[] = {5, 0, 1, 0, 1};
    WIRE.beginTransmission(BNO_ADDR);  WIRE.write(cmd_reset, sizeof(cmd_reset));  WIRE.endTransmission();
    delay(300);                         // let BNO reboot, about 150 works marginally, so let's double it
  #endif

  request_reports();                    // request desired reports

  do                                    // wait until BNO outputs non-zero quaternions
    check_report();
  while (!iqw && !iqx && !iqy && !iqz);
}

void loop()
{
  check_report();                       // check for reports
}
I borrowed some of these BNO085 access techniques from jps2000's rock-bottom code. Thanks again!

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”