-
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 rp2040 Pico simple ADC
- Loading branch information
cocasema
committed
Aug 18, 2022
1 parent
0695646
commit 490e868
Showing
2 changed files
with
69 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,57 @@ | ||
/* | ||
* Copyright (c) 2022, Nikolay Semenov | ||
* | ||
* 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/io/iostream.hpp> | ||
#include <modm/platform.hpp> | ||
|
||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
|
||
using Led = Board::LedGreen; | ||
Led::setOutput(true); | ||
|
||
Uart0::connect<GpioOutput0::Tx>(); | ||
Uart0::initialize<Board::SystemClock, 115200_Bd>(); | ||
|
||
modm::IODeviceWrapper<Uart0, modm::IOBuffer::BlockIfFull> loggerDevice; | ||
modm::IOStream out(loggerDevice); | ||
|
||
Adc::connect<GpioInput26::In0, GpioInput27::In1, GpioInput28::In2, GpioInput29::In3>(); | ||
Adc::initialize(); | ||
Adc::enableTemperatureSensor(); | ||
|
||
while (true) | ||
{ | ||
out.printf("---\r\n"); | ||
for (uint8_t ch = 0; ch < (uint8_t)Adc::Channel::Ch3; ++ch) | ||
{ | ||
auto value = Adc::readChannel((Adc::Channel)ch); | ||
out.printf("ADC Channel %u %f V | 0x%04x %u\r\n", ch, Adc::convertToVoltage(value), | ||
value, value); | ||
} | ||
{ | ||
auto value = Adc::readChannel(Adc::Channel::Ch3); | ||
out.printf("ADC VSYS %f V | 0x%04x %u\r\n", 3.f * Adc::convertToVoltage(value), | ||
value, value); | ||
} | ||
{ | ||
auto value = Adc::readChannel(Adc::Channel::Temperature); | ||
out.printf("ADC Int Temp %.4f C | 0x%04x %u\r\n", Adc::convertToTemperature(value), | ||
value, value); | ||
} | ||
modm::delay(250ms); | ||
Led::toggle(); | ||
} | ||
|
||
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:rp-pico</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/rp_pico/adc_simple</option> | ||
</options> | ||
<modules> | ||
<module>modm:io</module> | ||
<module>modm:platform:adc</module> | ||
<module>modm:platform:uart:0</module> | ||
<module>modm:build:scons</module> | ||
</modules> | ||
</library> |