-
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.
[examples] Add example for STTS22H temperature sensor
- Loading branch information
1 parent
0be2de2
commit 9e7ec34
Showing
2 changed files
with
67 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,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; | ||
} |
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,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> |