lcd now displays the temperature.

This commit is contained in:
Gabe Venberg 2023-11-28 20:48:53 -06:00
parent 23369dcf9b
commit dda09ca009
3 changed files with 35 additions and 8 deletions

View file

@ -5,7 +5,7 @@ version = "0.1.0"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
[dependencies] [dependencies]
cortex-m = "0.7" cortex-m = {version = "0.7"}
cortex-m-rt = "0.7" cortex-m-rt = "0.7"
embedded-hal = { version = "0.2.5", features = ["unproven"] } embedded-hal = { version = "0.2.5", features = ["unproven"] }
@ -17,6 +17,7 @@ panic-probe = { version = "0.3", features = ["print-defmt"] }
rp-pico = "0.8" rp-pico = "0.8"
max31855 = "0.1.0" max31855 = "0.1.0"
hd44780-driver = "0.4.0" hd44780-driver = "0.4.0"
embedded-alloc = "0.5.1"
# cargo build/run # cargo build/run
[profile.dev] [profile.dev]

View file

@ -1,6 +1,8 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
extern crate alloc;
use alloc::format;
use bsp::{ use bsp::{
entry, entry,
hal::{ hal::{
@ -9,7 +11,9 @@ use bsp::{
}, },
}; };
use core::fmt::Write; use core::fmt::Write;
use cortex_m::delay::Delay;
use defmt_rtt as _; use defmt_rtt as _;
use embedded_alloc::Heap;
use embedded_hal::digital::v2::OutputPin; use embedded_hal::digital::v2::OutputPin;
use embedded_hal::spi::MODE_0; use embedded_hal::spi::MODE_0;
use panic_probe as _; use panic_probe as _;
@ -30,6 +34,19 @@ use bsp::hal::{
use hd44780_driver as hd44780; use hd44780_driver as hd44780;
use max31855::{Max31855, Unit}; use max31855::{Max31855, Unit};
#[global_allocator]
static HEAP: Heap = Heap::empty();
fn write_lcd<T: hd44780_driver::bus::DataBus>(
lcd: &mut hd44780::HD44780<T>,
delay: &mut Delay,
string: &str,
) {
lcd.reset(delay).unwrap();
lcd.clear(delay).unwrap();
lcd.write_str(string, delay).unwrap();
}
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
let mut pac = pac::Peripherals::take().unwrap(); let mut pac = pac::Peripherals::take().unwrap();
@ -51,6 +68,14 @@ fn main() -> ! {
.ok() .ok()
.unwrap(); .unwrap();
//initalize the heap
{
use core::mem::MaybeUninit;
const HEAP_SIZE: usize = 1024;
static mut HEAP_MEM: [MaybeUninit<u8>; HEAP_SIZE] = [MaybeUninit::uninit(); HEAP_SIZE];
unsafe { HEAP.init(HEAP_MEM.as_ptr() as usize, HEAP_SIZE) }
}
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
let pins = bsp::Pins::new( let pins = bsp::Pins::new(
@ -106,12 +131,10 @@ fn main() -> ! {
pins.gpio20.into_push_pull_output(), //d6 pins.gpio20.into_push_pull_output(), //d6
pins.gpio21.into_push_pull_output(), //d6 pins.gpio21.into_push_pull_output(), //d6
&mut delay, &mut delay,
).unwrap(); )
.unwrap();
lcd.reset(&mut delay).unwrap();
lcd.clear(&mut delay).unwrap();
lcd.write_str("lcd initalized", &mut delay).unwrap();
write_lcd(&mut lcd, &mut delay, "Starting");
loop { loop {
led_pin.set_high().unwrap(); led_pin.set_high().unwrap();
external_led_pin.set_low().unwrap(); external_led_pin.set_low().unwrap();
@ -120,7 +143,10 @@ fn main() -> ! {
external_led_pin.set_high().unwrap(); external_led_pin.set_high().unwrap();
delay.delay_ms(500); delay.delay_ms(500);
match spi.read_thermocouple(&mut thermometer_spi_csn, Unit::Celsius) { match spi.read_thermocouple(&mut thermometer_spi_csn, Unit::Celsius) {
Ok(v) => writeln!(uart, "Temp: {} \r", v).unwrap(), Ok(v) => {
writeln!(uart, "Current: {} \r", v).unwrap();
write_lcd(&mut lcd, &mut delay, &format!("{:02.2} C", v))
}
Err(e) => defmt::error!("error reading temp {}", defmt::Debug2Format(&e)), Err(e) => defmt::error!("error reading temp {}", defmt::Debug2Format(&e)),
}; };
} }

Binary file not shown.