-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (c) 2020, Benjamin Carrick | ||
* | ||
* 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/driver/inertial/lsm6ds33.hpp> | ||
|
||
using namespace Board; | ||
using namespace std::chrono_literals; | ||
|
||
using I2cSda = GpioA10; | ||
using I2cScl = GpioA9; | ||
|
||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
LedD13::setOutput(); | ||
|
||
MODM_LOG_INFO << "LSM6DS33 demo" << modm::endl; | ||
|
||
I2cMaster1::connect<I2cSda::Sda, I2cScl::Scl>(); | ||
I2cMaster1::initialize<SystemClock, 400_kBd>(); | ||
|
||
// Create a sensor object with the adress of the sensor built onto the Pololu AltIMU-10 v5 | ||
modm::Lsm6ds33<I2cMaster1> sensor(0x6B); | ||
|
||
// Turn on and configure the acceleration sensor | ||
bool accSuccess = RF_CALL_BLOCKING(sensor.configureAccelerationSensor(modm::lsm6ds33::AccDataRate::Rate_13_Hz, | ||
modm::lsm6ds33::AccScale::Scale_16_G)); | ||
// Turn on and configure the gyroscope | ||
bool gyroSuccess = RF_CALL_BLOCKING(sensor.configureGyroscope(modm::lsm6ds33::GyroDataRate::Rate_13_Hz, | ||
modm::lsm6ds33::GyroScale::Scale_125_dps)); | ||
|
||
if(!(accSuccess && gyroSuccess)) | ||
{ | ||
MODM_LOG_INFO << "Sensor could not be configured!" << modm::endl; | ||
} | ||
|
||
modm::Vector3f accVector; | ||
modm::Vector3f gyroVector; | ||
|
||
while (true) | ||
{ | ||
//Read the sensor data and print it out | ||
accSuccess = RF_CALL_BLOCKING(sensor.readAcceleration(accVector)); | ||
gyroSuccess = RF_CALL_BLOCKING(sensor.readGyroscope(gyroVector)); | ||
if(accSuccess && gyroSuccess) | ||
{ | ||
MODM_LOG_INFO << "Acceleration Vector:" << modm::endl; | ||
MODM_LOG_INFO << "X: "<< accVector.x << " g" << modm::endl; | ||
MODM_LOG_INFO << "Y: "<< accVector.y << " g" << modm::endl; | ||
MODM_LOG_INFO << "Z: "<< accVector.z << " g" << modm::endl; | ||
MODM_LOG_INFO << modm::endl; | ||
|
||
MODM_LOG_INFO << "Spin Rates Vector:" << modm::endl; | ||
MODM_LOG_INFO << "X: "<< gyroVector.x << " deg/s" << modm::endl; | ||
MODM_LOG_INFO << "Y: "<< gyroVector.y << " deg/s" << modm::endl; | ||
MODM_LOG_INFO << "Z: "<< gyroVector.z << " deg/s" << modm::endl; | ||
MODM_LOG_INFO << modm::endl; | ||
|
||
} | ||
else | ||
{ | ||
MODM_LOG_INFO << "Sensor could not be read!" << modm::endl; | ||
} | ||
modm::delay(1s); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<library> | ||
<extends>modm:nucleo-f042k6</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/nucleo_f042k6/lsm6ds33</option> | ||
</options> | ||
<modules> | ||
<module>modm:build:scons</module> | ||
<module>modm:driver:lsm6ds33</module> | ||
<module>modm:platform:i2c:1</module> | ||
</modules> | ||
</library> |