Skip to content

Commit

Permalink
[examples] Add BNO055 example
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Jul 11, 2019
1 parent 1a0cff7 commit a8edbe8
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ make gdb

## Interesting Examples

We have a lot of examples, <!--examplecount-->189<!--/examplecount--> to be
We have a lot of examples, <!--examplecount-->190<!--/examplecount--> to be
exact, but here are some of our favorite examples for our supported development
boards:

Expand Down
120 changes: 120 additions & 0 deletions examples/nucleo_f411re/imu_bno055/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// coding: utf-8
/*
* Copyright (c) 2019, Niklas Hauser
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------

#include <modm/board.hpp>

#include <modm/processing.hpp>
#include <modm/driver/inertial/bno055.hpp>
#include <modm/debug.hpp>
using namespace modm::literals;

// Set the log level
#undef MODM_LOG_LEVEL
#define MODM_LOG_LEVEL modm::log::DEBUG

/**
* Example to demonstrate a MODM driver for imu sensor VL53L0X
*
* This example uses I2cMaster1 of STM32F401
*
* SDA PB9
* SCL PB8
*
* GND and +3V are connected to the sensor.
*/

using namespace Board;

using MyI2cMaster = I2cMaster1;
// using MyI2cMaster = BitBangI2cMaster<Board::D15, Board::D14>;

modm::bno055::Data data;
modm::Bno055<MyI2cMaster> imu(data);

class ThreadOne : public modm::pt::Protothread
{
public:
bool
update()
{
PT_BEGIN();

MODM_LOG_DEBUG << "Ping the device from ThreadOne" << modm::endl;

// ping the device until it responds
while (true)
{
// we wait until the device started
if (PT_CALL(imu.ping())) {
break;
}
PT_WAIT_UNTIL(timer.execute());
}

MODM_LOG_DEBUG << "Device responded" << modm::endl;

while (true)
{
if (PT_CALL(imu.configure())) {
break;
}

PT_WAIT_UNTIL(timer.execute());
}

MODM_LOG_DEBUG << "Device configured" << modm::endl;

while (true)
{
PT_WAIT_UNTIL(timer.execute());
PT_CALL(imu.readData());
MODM_LOG_INFO << (int)imu.getData().heading() << modm::endl;
}

PT_END();
}

private:
modm::ShortPeriodicTimer timer{100};
};

ThreadOne one;

// ----------------------------------------------------------------------------
int
main()
{
Board::initialize();
LedD13::setOutput();

// Board::D13::setOutput(modm::Gpio::Low);
MyI2cMaster::connect<Board::D15::Scl, Board::D14::Sda>();
MyI2cMaster::initialize<Board::SystemClock, 400_kHz>();

MODM_LOG_INFO << "\n\nWelcome to BNO055 demo!\n\n" << modm::endl;

modm::ShortPeriodicTimer tmr(500);

// Board::D15::setOutput();

while (1)
{
one.update();
if(tmr.execute()) {
LedD13::toggle();
// Board::D15::toggle();
}

}

return 0;
}
15 changes: 15 additions & 0 deletions examples/nucleo_f411re/imu_bno055/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<library>
<extends>modm:nucleo-f411re</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_f411re/bno055</option>
</options>
<modules>
<module>modm:debug</module>
<module>modm:driver:bno055</module>
<module>modm:platform:gpio</module>
<module>modm:platform:i2c:1</module>
<module>modm:platform:i2c.bitbang</module>
<module>modm:processing:protothread</module>
<module>modm:build:scons</module>
</modules>
</library>

0 comments on commit a8edbe8

Please sign in to comment.