Skip to content

Commit 3e89187

Browse files
committed
Removing blocking from dataAvailable. Add optional INT pin to I2C begin
1 parent 25de266 commit 3e89187

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/SparkFun_BNO080_Arduino_Library.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@
3131

3232
//Attempt communication with the device
3333
//Return true if we got a 'Polo' back from Marco
34-
boolean BNO080::begin(uint8_t deviceAddress, TwoWire &wirePort)
34+
boolean BNO080::begin(uint8_t deviceAddress, TwoWire &wirePort, uint8_t intPin)
3535
{
3636
_deviceAddress = deviceAddress; //If provided, store the I2C address from user
3737
_i2cPort = &wirePort; //Grab which port the user wants us to use
38+
_int = intPin; //Get the pin that the user wants to use for interrupts. By default, it's NULL and we'll not use it in dataAvailable() function.
3839

3940
//We expect caller to begin their I2C port, with the speed of their choice external to the library
4041
//But if they forget, we start the hardware here.
41-
_i2cPort->begin();
42+
//_i2cPort->begin();
4243

4344
//Begin by resetting the IMU
4445
softReset();
@@ -137,6 +138,14 @@ void BNO080::enableDebugging(Stream &debugPort)
137138
//Returns false if new readings are not available
138139
bool BNO080::dataAvailable(void)
139140
{
141+
//If we have an interrupt pin connection available, check if data is available.
142+
//If int pin is NULL, then we'll rely on receivePacket() to timeout
143+
//See issue 13: https://github.com/sparkfun/SparkFun_BNO080_Arduino_Library/issues/13
144+
if(_int != NULL)
145+
{
146+
if(digitalRead(_int) == HIGH) return(false);
147+
}
148+
140149
if (receivePacket() == true)
141150
{
142151
//Check to see if this packet is a sensor reporting its data to us

src/SparkFun_BNO080_Arduino_Library.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ const byte CHANNEL_GYRO = 5;
135135
class BNO080 {
136136
public:
137137

138-
boolean begin(uint8_t deviceAddress = BNO080_DEFAULT_ADDRESS, TwoWire &wirePort = Wire); //By default use the default I2C addres, and use Wire port
138+
boolean begin(uint8_t deviceAddress = BNO080_DEFAULT_ADDRESS, TwoWire &wirePort = Wire, uint8_t intPin = NULL); //By default use the default I2C addres, and use Wire port, and don't declare an INT pin
139139
boolean beginSPI(uint8_t user_CSPin, uint8_t user_WAKPin, uint8_t user_INTPin, uint8_t user_RSTPin, uint32_t spiPortSpeed = 3000000, SPIClass &spiPort = SPI);
140140

141141
void enableDebugging(Stream &debugPort = Serial); //Turn on debug printing. If user doesn't specify then Serial will be used.

0 commit comments

Comments
 (0)