From eacc6e9fcfe05ecbd0dd304f11931e7faa515f7d Mon Sep 17 00:00:00 2001 From: Andrew Bullock Date: Mon, 18 Nov 2019 16:59:02 +0000 Subject: [PATCH 1/6] fixes #4 by parameterising interrupt and reset pins, and setting the defaults to the pins mapped to modern shields --- library.properties | 2 +- src/NineAxesMotion.cpp | 10 ++++++++-- src/NineAxesMotion.h | 26 ++++++++++++++------------ 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/library.properties b/library.properties index 32674bf..337ab98 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=9 Axes Motion -version=1.1.0 +version=1.2.0 author=Bosch Sensortec GmbH maintainer=Arduino sentence=Arduino 9 Axes Motion Shield Library diff --git a/src/NineAxesMotion.cpp b/src/NineAxesMotion.cpp index 82c6bbb..e498b5d 100755 --- a/src/NineAxesMotion.cpp +++ b/src/NineAxesMotion.cpp @@ -65,11 +65,17 @@ 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) { + INT_PIN = int_pin; + RESET_PIN = reset_pin; + //Initialize the GPIO peripheral pinMode(INT_PIN, INPUT_PULLUP); //Configure Interrupt pin pinMode(RESET_PIN, OUTPUT); //Configure Reset pin diff --git a/src/NineAxesMotion.h b/src/NineAxesMotion.h index c53bdcd..9ddb206 100644 --- a/src/NineAxesMotion.h +++ b/src/NineAxesMotion.h @@ -92,17 +92,16 @@ 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 +//GPIO to reset the BNO055 (RESET pin has to be HIGH for the BNO055 to operate) +int RESET_PIN = 7; // 7 or 4 are most likely candidate pins + +//GPIO to receive the Interrupt from the BNO055 (Interrupt is visible on the INT LED on the Shield) +#if defined(__AVR_ATmega32U4__) //Arduino Yun and Leonardo have I2C shared with pins 2 and 3 +int INT_PIN = 7; +#elif defined(ARDUINO_SAMD) +int INT_PIN = 7; // Older SAMD boards have NMI mapped on pin 2 #else -#define INT_PIN 0 +int INT_PIN = 2; #endif #define ENABLE 1 //For use in function parameters @@ -147,10 +146,13 @@ 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 From 33c266330b1821901962d4017f468af257c9d3e9 Mon Sep 17 00:00:00 2001 From: Andrew Bullock Date: Mon, 18 Nov 2019 17:11:16 +0000 Subject: [PATCH 2/6] improved readme when fixing #4 --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 540664b..163a37a 100755 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file From 2e910086b1ad1f29c58fbc8d5210af793d35de1b Mon Sep 17 00:00:00 2001 From: Andrew Bullock Date: Mon, 18 Nov 2019 19:57:06 +0000 Subject: [PATCH 3/6] further tidying, fixed build warnings --- src/NineAxesMotion.cpp | 20 +++++++++++--------- src/NineAxesMotion.h | 22 ++++++---------------- 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/NineAxesMotion.cpp b/src/NineAxesMotion.cpp index e498b5d..2594207 100755 --- a/src/NineAxesMotion.cpp +++ b/src/NineAxesMotion.cpp @@ -77,24 +77,26 @@ void NineAxesMotion::initSensor(unsigned int address, int int_pin, int reset_pin RESET_PIN = 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) @@ -985,7 +987,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 @@ -1006,7 +1008,7 @@ void _delay(u_32 period) } -void NineAxesMotion::begin(unsigned int address = 0x28) +void NineAxesMotion::begin(unsigned int address) { initSensor(address); } diff --git a/src/NineAxesMotion.h b/src/NineAxesMotion.h index 9ddb206..37fa796 100644 --- a/src/NineAxesMotion.h +++ b/src/NineAxesMotion.h @@ -58,7 +58,7 @@ extern "C" { -#include +#include "utility/BNO055.h" } #include #include "Arduino.h" @@ -92,18 +92,6 @@ struct bno055_accel_stat_t { uint8_t powerMode; //Power mode: Normal - Deep suspend }; -//GPIO to reset the BNO055 (RESET pin has to be HIGH for the BNO055 to operate) -int RESET_PIN = 7; // 7 or 4 are most likely candidate pins - -//GPIO to receive the Interrupt from the BNO055 (Interrupt is visible on the INT LED on the Shield) -#if defined(__AVR_ATmega32U4__) //Arduino Yun and Leonardo have I2C shared with pins 2 and 3 -int INT_PIN = 7; -#elif defined(ARDUINO_SAMD) -int INT_PIN = 7; // Older SAMD boards have NMI mapped on pin 2 -#else -int INT_PIN = 2; -#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 @@ -156,10 +144,12 @@ class NineAxesMotion { /******************************************************************************************* *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 @@ -756,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 From c8e8c97e544ce7e1946ea55918cf17f7a94c3469 Mon Sep 17 00:00:00 2001 From: Andrew Bullock Date: Mon, 18 Nov 2019 19:57:57 +0000 Subject: [PATCH 4/6] reverted accidental debug change to includes --- src/NineAxesMotion.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NineAxesMotion.h b/src/NineAxesMotion.h index 37fa796..e9130b0 100644 --- a/src/NineAxesMotion.h +++ b/src/NineAxesMotion.h @@ -58,7 +58,7 @@ extern "C" { -#include "utility/BNO055.h" +#include } #include #include "Arduino.h" From 16622618893816b6d8f10d117a9fc1d09aa35717 Mon Sep 17 00:00:00 2001 From: Andrew Bullock Date: Mon, 18 Nov 2019 19:58:59 +0000 Subject: [PATCH 5/6] removed legacy variable assignments --- src/NineAxesMotion.cpp | 3 --- src/NineAxesMotion.h | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/NineAxesMotion.cpp b/src/NineAxesMotion.cpp index 2594207..a620755 100755 --- a/src/NineAxesMotion.cpp +++ b/src/NineAxesMotion.cpp @@ -73,9 +73,6 @@ NineAxesMotion::NineAxesMotion() *******************************************************************************************/ void NineAxesMotion::initSensor(unsigned int address, int int_pin, int reset_pin) { - INT_PIN = int_pin; - RESET_PIN = reset_pin; - //Initialize the GPIO peripheral pinMode(int_pin, INPUT_PULLUP); //Configure Interrupt pin pinMode(reset_pin, OUTPUT); //Configure Reset pin diff --git a/src/NineAxesMotion.h b/src/NineAxesMotion.h index e9130b0..37fa796 100644 --- a/src/NineAxesMotion.h +++ b/src/NineAxesMotion.h @@ -58,7 +58,7 @@ extern "C" { -#include +#include "utility/BNO055.h" } #include #include "Arduino.h" From 026d74a9f22f53780dd1c845fe01741cf5ad5d9c Mon Sep 17 00:00:00 2001 From: Andrew Bullock Date: Mon, 18 Nov 2019 21:04:42 +0000 Subject: [PATCH 6/6] reverted quotes for angles --- src/NineAxesMotion.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NineAxesMotion.h b/src/NineAxesMotion.h index 37fa796..e9130b0 100644 --- a/src/NineAxesMotion.h +++ b/src/NineAxesMotion.h @@ -58,7 +58,7 @@ extern "C" { -#include "utility/BNO055.h" +#include } #include #include "Arduino.h"