Skip to content

Commit d62224f

Browse files
committed
Adding wait for Serial to setup
-With native USB boards, it is necessary to wait for Serial to become available. If you don't it can cause com port enumeration issues and your computer can show errors like "device not recognized". -Updated INT and RST pin arguments to SIGNED ints. They were previously UNSIGNED, and therefore could never be the "-1" (which indicates we don't want to use them)
1 parent 0bfb48c commit d62224f

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

examples/Example_01_RotationVector/Example_01_RotationVector.ino

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,29 @@
3737
#include "SparkFun_BNO08x_Arduino_Library.h" // CTRL+Click here to get the library: http://librarymanager/All#SparkFun_BNO08x
3838
BNO08x myIMU;
3939

40+
// For reliable interaction with the SHTP bus, we need
41+
// to use hardware reset control, and monitor the H_INT pin
42+
// The H_INT pin will go low when its okay to talk on the SHTP bus.
43+
// Note, these can be other GPIO if you like.
44+
// Do not define (or set to -1) to not user these features.
45+
#define BNO08X_INT 4
46+
//#define BNO08X_INT -1
47+
#define BNO08X_RST 22
48+
//#define BNO08X_RST -1
49+
50+
#define BNO08X_ADDR 0x4B // SparkFun BNO08x Breakout (Qwiic) defaults to 0x4B
51+
//#define BNO08X_ADDR 0x4A // Alternate address if ADR jumper is closed
52+
4053
void setup() {
54+
while(!Serial); // Wait for Serial to become available.
55+
// Necessary for boards with native USB (like the SAMD51 Thing+).
4156
Serial.begin(115200);
4257
Serial.println();
4358
Serial.println("BNO08x Read Example");
4459

4560
Wire.begin();
4661

47-
if (myIMU.begin() == false) {
62+
if (myIMU.begin(BNO08X_ADDR, Wire, BNO08X_INT, BNO08X_RST) == false) {
4863
Serial.println("BNO08x not detected at default I2C address. Check your jumpers and the hookup guide. Freezing...");
4964
while (1)
5065
;

src/SparkFun_BNO08x_Arduino_Library.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ size_t maxBufferSize();
8787

8888
//Initializes the sensor with basic settings using I2C
8989
//Returns false if sensor is not detected
90-
boolean BNO08x::begin(uint8_t deviceAddress, TwoWire &wirePort, uint8_t user_INTPin, uint8_t user_RSTPin)
90+
boolean BNO08x::begin(uint8_t deviceAddress, TwoWire &wirePort, int8_t user_INTPin, int8_t user_RSTPin)
9191
{
9292
_deviceAddress = deviceAddress;
9393
_i2cPort = &wirePort;

src/SparkFun_BNO08x_Arduino_Library.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
class BNO08x
145145
{
146146
public:
147-
boolean begin(uint8_t deviceAddress = BNO08x_DEFAULT_ADDRESS, TwoWire &wirePort = Wire, uint8_t user_INTPin = -1, uint8_t user_RSTPin = -1); //By default use the default I2C addres, and use Wire port
147+
boolean begin(uint8_t deviceAddress = BNO08x_DEFAULT_ADDRESS, TwoWire &wirePort = Wire, int8_t user_INTPin = -1, int8_t user_RSTPin = -1); //By default use the default I2C addres, and use Wire port
148148
boolean beginSPI(uint8_t user_CSPin, uint8_t user_INTPin, uint8_t user_RSTPin, uint32_t spiPortSpeed = 1000000, SPIClass &spiPort = SPI);
149149
boolean isConnected();
150150

0 commit comments

Comments
 (0)