Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds pin parameterisation #6

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@ determine offsets. Follow the instructions below to calibrate your sensor.

- Magnetometer: Move the magnetometer in a large 8 like pattern a few times
gently.

Setting up pins
-----------

See the declaration for initSensor in NineAxesMotion.h
Ensure you have correctly configured the Interrupt and Reset pins. Modern boards default to Interrupt Pin = 2 and Reset Pin = 7, although your board may be jumpered differently. The most probable alternative pins are Interrupt Pin = 4 and Reset Pin = 3. Consult your shield and observe how these tracks are jumpered on your particular setup.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=9 Axes Motion
version=1.1.0
version=1.2.0
author=Bosch Sensortec GmbH
maintainer=Arduino <[email protected]>
sentence=Arduino 9 Axes Motion Shield Library
Expand Down
27 changes: 16 additions & 11 deletions src/NineAxesMotion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,35 @@ NineAxesMotion::NineAxesMotion()

/*******************************************************************************************
*Description: Function with the bare minimum initialization
*Input Parameters: None
*Input Parameters:
unsigned int address: I2C address of the BNO055. Default 0x28
int int_pin: GPIO to receive the Interrupt from the BNO055 for the Arduino Uno (Interrupt is visible on the INT LED on the Shield)
int reset_pin: GPIO to reset the BNO055 (RESET pin has to be HIGH for the BNO055 to operate)
*Return Parameter: None
*******************************************************************************************/
void NineAxesMotion::initSensor(unsigned int address)
void NineAxesMotion::initSensor(unsigned int address, int int_pin, int reset_pin)
{
//Initialize the GPIO peripheral
pinMode(INT_PIN, INPUT_PULLUP); //Configure Interrupt pin
pinMode(RESET_PIN, OUTPUT); //Configure Reset pin
pinMode(int_pin, INPUT_PULLUP); //Configure Interrupt pin
pinMode(reset_pin, OUTPUT); //Configure Reset pin

//Power on the BNO055
resetSensor(address);
resetSensor(address, reset_pin);
}

/*******************************************************************************************
*Description: This function is used to reset the BNO055
*Input Parameters: None
*Input Parameters:
unsigned int address: I2C address of the BNO055. Default 0x28
int reset_pin: GPIO to reset the BNO055 (RESET pin has to be HIGH for the BNO055 to operate)
*Return Parameter: None
*******************************************************************************************/
void NineAxesMotion::resetSensor(unsigned int address)
void NineAxesMotion::resetSensor(unsigned int address, int reset_pin)
{
//Reset sequence
digitalWrite(RESET_PIN, LOW); //Set the Reset pin LOW
digitalWrite(reset_pin, LOW); //Set the Reset pin LOW
delay(RESET_PERIOD); //Hold it for a while
digitalWrite(RESET_PIN, HIGH); //Set the Reset pin HIGH
digitalWrite(reset_pin, HIGH); //Set the Reset pin HIGH
delay(INIT_PERIOD); //Pause for a while to let the sensor initialize completely (Anything >500ms should be fine)
//Initialization sequence
//Link the function pointers for communication (late-binding)
Expand Down Expand Up @@ -979,7 +984,7 @@ signed char BNO055_I2C_bus_read(unsigned char dev_addr,unsigned char reg_addr, u
}


signed char BNO055_I2C_bus_write(unsigned char dev_addr,unsigned char reg_addr, unsigned char *reg_data, unsigned char cnt)
signed char BNO055_I2C_bus_write(unsigned char dev_addr, unsigned char reg_addr, unsigned char *reg_data, unsigned char cnt)
{
BNO055_RETURN_FUNCTION_TYPE comres = BNO055_ZERO_U8X;
I2C.beginTransmission(dev_addr); //Start of transmission
Expand All @@ -1000,7 +1005,7 @@ void _delay(u_32 period)
}


void NineAxesMotion::begin(unsigned int address = 0x28)
void NineAxesMotion::begin(unsigned int address)
{
initSensor(address);
}
Expand Down
28 changes: 10 additions & 18 deletions src/NineAxesMotion.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,6 @@ struct bno055_accel_stat_t {
uint8_t powerMode; //Power mode: Normal - Deep suspend
};

//GPIO pins used for controlling the Sensor
#define RESET_PIN 4 //GPIO to reset the BNO055 (RESET pin has to be HIGH for the BNO055 to operate)

#if defined(__AVR_ATmega32U4__) //Arduino Yun and Leonardo
#define INT_PIN 4 //GPIO to receive the Interrupt from the BNO055 for the Arduino Uno(Interrupt is visible on the INT LED on the Shield)
#elif defined(ARDUINO_ARCH_SAM) //INT_PIN is the interrupt number not the interrupt pin
#define INT_PIN 2
#elif defined(ARDUINO_ARCH_SAMD)
#define INT_PIN 7
#else
#define INT_PIN 0
#endif

#define ENABLE 1 //For use in function parameters
#define DISABLE 0 //For use in function parameters
#define NO_MOTION 1 //Enables the no motion interrupt
Expand Down Expand Up @@ -147,17 +134,22 @@ class NineAxesMotion {

/*******************************************************************************************
*Description: Function with the bare minimum initialization
*Input Parameters: None
*Input Parameters:
unsigned int address: I2C address of the BNO055. Default 0x28
int int_pin: GPIO to receive the Interrupt from the BNO055 for the Arduino Uno (Interrupt is visible on the INT LED on the Shield)
int reset_pin: GPIO to reset the BNO055 (RESET pin has to be HIGH for the BNO055 to operate)
*Return Parameter: None
*******************************************************************************************/
void initSensor(unsigned int address = 0x28);
void initSensor(unsigned int address = 0x28, int int_pin = 2, int reset_pin = 7);

/*******************************************************************************************
*Description: This function is used to reset the BNO055
*Input Parameters: None
*Input Parameters:
unsigned int address: I2C address of the BNO055. Default 0x28
int reset_pin: GPIO to reset the BNO055 (RESET pin has to be HIGH for the BNO055 to operate)
*Return Parameter: None
*******************************************************************************************/
void resetSensor(unsigned int address);
void resetSensor(unsigned int address, int reset_pin = 7);

/*******************************************************************************************
*Description: This function is used to set the operation mode of the BNO055
Expand Down Expand Up @@ -754,4 +746,4 @@ signed char BNO055_I2C_bus_read(unsigned char,unsigned char, unsigned char*, uns
signed char BNO055_I2C_bus_write(unsigned char ,unsigned char , unsigned char* , unsigned char );
void _delay(u_32);

#endif __NAXISMOTION_H__
#endif