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

Driver for LIS3MDL Magnetometer #428

Merged
merged 2 commits into from
Jul 7, 2020
Merged
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
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,41 +211,42 @@ can easily configure them for you specific needs.
<td align="center">LIS302DL</td>
<td align="center">LIS3DSH</td>
</tr><tr>
<td align="center">LIS3MDL</td>
<td align="center">LM75</td>
<td align="center">LP503X</td>
<td align="center">LSM303A</td>
<td align="center">LSM6DS33</td>
<td align="center">LTC2984</td>
<td align="center">MAX6966</td>
</tr><tr>
<td align="center">MAX6966</td>
<td align="center">MAX7219</td>
<td align="center">MCP23X17</td>
<td align="center">MCP2515</td>
<td align="center">NOKIA5110</td>
<td align="center">NRF24</td>
<td align="center">TFT-DISPLAY</td>
</tr><tr>
<td align="center">TFT-DISPLAY</td>
<td align="center">PAT9125EL</td>
<td align="center">PCA8574</td>
<td align="center">PCA9535</td>
<td align="center">PCA9548A</td>
<td align="center">PCA9685</td>
<td align="center">SIEMENS-S65</td>
</tr><tr>
<td align="center">SIEMENS-S65</td>
<td align="center">SIEMENS-S75</td>
<td align="center">SK6812</td>
<td align="center">SK9822</td>
<td align="center">SSD1306</td>
<td align="center">SX1276</td>
<td align="center">TCS3414</td>
</tr><tr>
<td align="center">TCS3414</td>
<td align="center">TCS3472</td>
<td align="center">TLC594X</td>
<td align="center">TMP102</td>
<td align="center">TMP175</td>
<td align="center">VL53L0</td>
<td align="center">VL6180</td>
</tr><tr>
<td align="center">VL6180</td>
<td align="center">WS2812</td>
</tr>
</table>
Expand Down
73 changes: 73 additions & 0 deletions examples/nucleo_f042k6/lis3mdl/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* 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/lis3mdl.hpp>

using namespace Board;
using namespace std::chrono_literals;

using I2cSda = GpioA10;
using I2cScl = GpioA9;

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

MODM_LOG_INFO << "LIS3MDL 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::Lis3mdl<I2cMaster1> sensor(0x1E);

// Turn on and configure the magnetometer
bool success = RF_CALL_BLOCKING(sensor.configure(modm::lis3mdl::DataRate::Rate_5_Hz,
modm::lis3mdl::Scale::Scale_8_gauss));


if(!success)
{
MODM_LOG_INFO << "Sensor could not be configured!" << modm::endl;
}

// Set the sensor to continous acquistion and turn on the temperature sensing
success = RF_CALL_BLOCKING(sensor.setMode(modm::lis3mdl::OperationMode::Continous));
if(!success)
{
MODM_LOG_INFO << "Sensor could not be started!" << modm::endl;
}

modm::Vector3f magVector;

while (true)
{
//Read the sensor data and print it out
success = RF_CALL_BLOCKING(sensor.readMagnetometer(magVector));

if(success)
{
MODM_LOG_INFO << "Magnetic Vector:" << modm::endl;
MODM_LOG_INFO << "X: "<< magVector.x << " gauss" << modm::endl;
MODM_LOG_INFO << "Y: "<< magVector.y << " gauss" << modm::endl;
MODM_LOG_INFO << "Z: "<< magVector.z << " gauss" << modm::endl;
MODM_LOG_INFO << modm::endl;
}
else
{
MODM_LOG_INFO << "Sensor could not be read!" << modm::endl;
}
modm::delay(1s);
}
return 0;
}
11 changes: 11 additions & 0 deletions examples/nucleo_f042k6/lis3mdl/project.xml
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/lis3mdl</option>
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:driver:lis3mdl</module>
<module>modm:platform:i2c:1</module>
</modules>
</library>
Loading