diff options
| author | Aaron Tsui <[email protected]> | 2022-12-20 09:11:39 +0800 |
|---|---|---|
| committer | Aaron Tsui <[email protected]> | 2022-12-20 09:12:01 +0800 |
| commit | 849a0e174fa1601236050afb72290174675c585f (patch) | |
| tree | 6d58e4c3f5deb47fdc10daa779ecd03948160ed1 /examples | |
| parent | ebc735008f0b1725b22c944cc5f95fe1aacc665b (diff) | |
add convert_to_celsius function in the adc module
modify RP2040 adc example to get inside biased bipolar diode voltage,
then convert this temperature sensor data into Celsius degree,
according to chapter 4.9.5. Temperature Sensor in RP2040 datasheet.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/rp/src/bin/adc.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/examples/rp/src/bin/adc.rs b/examples/rp/src/bin/adc.rs index 2a9e93732..25e5126b4 100644 --- a/examples/rp/src/bin/adc.rs +++ b/examples/rp/src/bin/adc.rs | |||
| @@ -27,7 +27,12 @@ async fn main(_spawner: Spawner) { | |||
| 27 | let level = adc.read(&mut p28).await; | 27 | let level = adc.read(&mut p28).await; |
| 28 | info!("Pin 28 ADC: {}", level); | 28 | info!("Pin 28 ADC: {}", level); |
| 29 | let temp = adc.read_temperature().await; | 29 | let temp = adc.read_temperature().await; |
| 30 | info!("Temp: {}", temp); | 30 | info!("Temp: {} degrees", convert_to_celsius(temp)); |
| 31 | Timer::after(Duration::from_secs(1)).await; | 31 | Timer::after(Duration::from_secs(1)).await; |
| 32 | } | 32 | } |
| 33 | } | 33 | } |
| 34 | |||
| 35 | fn convert_to_celsius(raw_temp: u16) -> f32 { | ||
| 36 | // According to chapter 4.9.5. Temperature Sensor in RP2040 datasheet | ||
| 37 | 27.0 - (raw_temp as f32 * 3.3 / 4096.0 -0.706)/0.001721 as f32 | ||
| 38 | } \ No newline at end of file | ||
