Skip to content

Commit

Permalink
Merge pull request #3 from TeamSunride/restructure
Browse files Browse the repository at this point in the history
Restructure into library
  • Loading branch information
danverstom authored Jan 21, 2022
2 parents 9e81468 + 86b5c0b commit 98fadcd
Show file tree
Hide file tree
Showing 24 changed files with 231 additions and 148 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: PlatformIO CI

on: [push]

jobs:
build_example:
runs-on: ubuntu-latest
strategy:
matrix:
examples: [
examples/accelmaggyro.cpp,
examples/accgyro.cpp,
examples/accmag.cpp,
examples/acconly.cpp,
examples/euler.cpp,
examples/gyroonly.cpp,
examples/maggyro.cpp,
examples/magonly.cpp,
examples/quaternion.cpp,
examples/interrupts/accelAnyMotionInterrupt.cpp,
examples/interrupts/accelHighGInterrupt.cpp,
examples/interrupts/gyroAnyMotionInterrupt.cpp,
examples/interrupts/gyroHighRateInterrupt.cpp,
examples/interrupts/noMotionInterrupt.cpp,
examples/interrupts/slowMotionInterrupt.cpp
]

steps:
- uses: actions/checkout@v2
- name: Cache pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Cache PlatformIO
uses: actions/cache@v2
with:
path: ~/.platformio
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}

- name: Set up Python
uses: actions/setup-python@v2

- name: Install PlatformIO
run: |
python -m pip install --upgrade pip
pip install --upgrade platformio
- name: Run PlatformIO
run: pio ci --lib "." --board teensy41
env:
PLATFORMIO_CI_SRC: ${{ matrix.examples }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
CMakeListsPrivate.txt
cmake-build-*/
.idea
pyteaplot.py
pyteaplot.py
/test/tmp_pio_test_transport.cpp
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_C_COMPILER_WORKS 1)
set(CMAKE_CXX_COMPILER_WORKS 1)

project("Arduino-BNO055" C CXX)
project("BNO055" C CXX)

include(CMakeListsPrivate.txt)

Expand Down
141 changes: 141 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# Arduino BNO055 Library

![](resources/BNO055.jpg)

*image credit: Adafruit*

PlatformIO / Arduino library designed to make it easy to use
advanced features of the Bosch BNO055 IMU.

Developed by [Tom Danvers](https://github.com/TomD53)

## Features

- Power mode configuration
- Operation mode configuration
- Sensor reset
- Sensor self test
- Methods to read from all operation modes, converted to useful units
- Burst read of all data
- Sensor configuration (set G range, sample rate, power mode -
this requires reading of the datasheet)
- View sensor calibration
- Implementation of all interrupts
- `AccelHighGInterrupt`
- `AccelSlowNoMotionInterrupt`
- `AccelAnyMotionInterrupt`
- `GyroHighRateInterrupt`
- `GyroAnyMotionInterrupt`

## TODO

- Sensor configuration could be improved / made more intuitive. You need to work out what value to write to the
config register by reading the datasheet.
- Axis remap is not implemented (yet)
- Calibration parameters cannot yet be saved and re-applied after a sensor restart

## Examples

Refer to the [examples directory](examples)

To run an example (in PlatformIO), modify platformio.ini to support your board/framework, and then run the following:

pio ci "examples/accgyro.cpp" --lib "." -c "platformio.ini"

### Read from accelerometer

```cpp
#include <Arduino.h>
#include "BNO055.h"

const byte I2C_ADDRESS = 0x28;

BNO055 sensor(I2C_ADDRESS, &Wire);

void setup() {
Wire.begin();
sensor.begin();
sensor.setOperationMode(ACCONLY);
}

void loop() {
Vector<double> accelVector = sensor.getRawAcceleration();
Serial.println((String)accelVector.getX() + "," + (String)accelVector.getY() + ","
+ (String)accelVector.getZ() + ",");
}
```
### Register Accelerometer High G interrupt
```cpp
#include <Arduino.h>
#include "BNO055.h"
const byte I2C_ADDRESS = 0x28;
BNO055 sensor(I2C_ADDRESS, &Wire);
// define our callback (known as an ISR, or interrupt service routine) to be called when the interrupt is
// detected. Note that ISRs have various limitations.
void myCallback() {
digitalWrite(3, !digitalRead(3));
}
void setup() {
// begin I2C communication
Wire.begin();
// reset the sensor to remove any existing configuration
sensor.resetSystem();
// we need to be in configmode to set up the interrupt.
// this is not necessary as we just called sensor#resetSystem however it is here for completeness
sensor.setOperationMode(CONFIGMODE);
// define the configuration of our interrupt
BNO055::AccelHighGInterrupt interrupt(
sensor,
(new BNO055::Interrupt::EnabledAxes)->enableX().enableY().enableZ(),
myCallback,
2);
// write the configuration to the BNO055
interrupt.setup();
// enable this interrupt
interrupt.enable();
// route this interrupt to the INT pin on the sensor
interrupt.mask();
// enter the ACCONLY operation mode (note that the above code must run in COMFIGMODE)
sensor.setOperationMode(ACCONLY);
pinMode(3, OUTPUT);
}
void loop() {
// we constantly clear the interrupt on the sensor. Not an ideal solution and not efficient, but
// works for this example
sensor.clearInterrupt();
}
```

## Documentation

Most/all methods are documented well in [`BNO055.h`](src/BNO055.h).

Refer to the [examples directory](examples) and also the [unit test](test/test_BNO055.cpp) for usage examples.

The best way of understanding how things work is to [read the datasheet](datasheet.pdf)

## Unit testing

This project contains some automated unit tests that you can run to check that everything works.
You need to do this with PlatformIO.

If you aren't using a Teensy 4.1, modify the configuration in `platformio.ini`

To run the unit tests, run ```pio test```

![](resources/test_result.png)

3 changes: 3 additions & 0 deletions commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Run an example and upload / monitor it

pio ci "examples/accgyro.cpp" --lib "." -c "platformio.ini"
2 changes: 1 addition & 1 deletion examples/interrupts/accelAnyMotionInterrupt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void setup() {

BNO055::AccelAnyMotionInterrupt anyMotionInterrupt(
sensor,
(new BNO055::Interrupt::AxesSetting)->enableX().enableY().enableZ(),
(new BNO055::Interrupt::EnabledAxes)->enableX().enableY().enableZ(),
myCallback,
2);
anyMotionInterrupt.setup();
Expand Down
2 changes: 1 addition & 1 deletion examples/interrupts/accelHighGInterrupt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void setup() {
// define the configuration of our interrupt
BNO055::AccelHighGInterrupt interrupt(
sensor,
(new BNO055::Interrupt::AxesSetting)->enableX().enableY().enableZ(),
(new BNO055::Interrupt::EnabledAxes)->enableX().enableY().enableZ(),
myCallback,
2);

Expand Down
2 changes: 1 addition & 1 deletion examples/interrupts/noMotionInterrupt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void setup() {

BNO055::AccelSlowNoMotionInterrupt slowNoMotionInterrupt(
sensor,
(new BNO055::Interrupt::AxesSetting)->enableX().enableY().enableZ(),
(new BNO055::Interrupt::EnabledAxes)->enableX().enableY().enableZ(),
myCallback,
2, BNO055::AccelSlowNoMotionInterrupt::NO_MOTION);
slowNoMotionInterrupt.setup();
Expand Down
2 changes: 1 addition & 1 deletion examples/interrupts/slowMotionInterrupt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void setup() {

BNO055::AccelSlowNoMotionInterrupt slowNoMotionInterrupt(
sensor,
(new BNO055::Interrupt::AxesSetting)->enableX().enableY().enableZ(),
(new BNO055::Interrupt::EnabledAxes)->enableX().enableY().enableZ(),
myCallback,
2, BNO055::AccelSlowNoMotionInterrupt::SLOW_MOTION);
slowNoMotionInterrupt.setup();
Expand Down
39 changes: 0 additions & 39 deletions include/README

This file was deleted.

46 changes: 0 additions & 46 deletions lib/README

This file was deleted.

19 changes: 19 additions & 0 deletions library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "Arduino-BNO055",
"version": "1.0.0",
"description": "PlatformIO / Arduino library designed to make it easy to use advanced features of the Bosch BNO055 IMU.",
"keywords": "arduino, sensor, BNO055, adafruit, interrupt, IMU",
"repository":
{
"type": "git",
"url": "https://github.com/TeamSunride/Arduino-BNO055"
},
"authors":
[
{
"name": "Tom Danvers",
"url": "https://tdanvers.com/",
"maintainer": true
}
]
}
17 changes: 6 additions & 11 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:teensy41]
; the parameters below will be specific to your board/platform/environment
platform = teensy
board = teensy41
framework = arduino
upload_protocol = teensy-cli
extra_scripts = extra_script.py
test_port = COM3
test_port = COM3

; the parameters below are required
test_build_project_src = true
targets=upload, monitor
Binary file added resources/BNO055.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/test_result.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 98fadcd

Please sign in to comment.