Skip to content

Commit

Permalink
[examples] Add example for STTS22H temperature sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-durand committed May 8, 2021
1 parent 0be2de2 commit 9e7ec34
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
55 changes: 55 additions & 0 deletions examples/nucleo_f103rb/stts22h/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2021, Christopher Durand
*
* 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/temperature/stts22h.hpp>

using namespace Board;
using namespace std::literals;

using I2cMaster = I2cMaster1;

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

I2cMaster::connect<GpioB7::Sda, GpioB6::Scl>();
I2cMaster::initialize<Board::SystemClock, 100_kHz>();

MODM_LOG_INFO << "Welcome to STTS22H Test" << modm::endl;

modm::stts22h::Data data{};
modm::Stts22h<I2cMaster> sensor{data, 0x3f};

bool success = RF_CALL_BLOCKING(sensor.initialize());
if(!success)
{
MODM_LOG_ERROR << "Initialization failed" << modm::endl;
}

modm::PeriodicTimer timer{500ms};
while (true)
{
if (timer.execute())
{
LedD13::toggle();

RF_CALL_BLOCKING(sensor.readTemperature());
MODM_LOG_INFO << "temperature: " << data.getTemperatureFractional();
MODM_LOG_INFO << " [1/100th °C]" << modm::endl;
}
}

return 0;
}
12 changes: 12 additions & 0 deletions examples/nucleo_f103rb/stts22h/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<library>
<extends>modm:nucleo-f103rb</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_f103rb/stts22h</option>
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:processing:timer</module>
<module>modm:platform:i2c:1</module>
<module>modm:driver:stts22h</module>
</modules>
</library>

0 comments on commit 9e7ec34

Please sign in to comment.