lcd now displays the temperature.
This commit is contained in:
parent
23369dcf9b
commit
dda09ca009
|
@ -5,7 +5,7 @@ version = "0.1.0"
|
|||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
cortex-m = "0.7"
|
||||
cortex-m = {version = "0.7"}
|
||||
cortex-m-rt = "0.7"
|
||||
embedded-hal = { version = "0.2.5", features = ["unproven"] }
|
||||
|
||||
|
@ -17,6 +17,7 @@ panic-probe = { version = "0.3", features = ["print-defmt"] }
|
|||
rp-pico = "0.8"
|
||||
max31855 = "0.1.0"
|
||||
hd44780-driver = "0.4.0"
|
||||
embedded-alloc = "0.5.1"
|
||||
|
||||
# cargo build/run
|
||||
[profile.dev]
|
||||
|
|
38
src/main.rs
38
src/main.rs
|
@ -1,6 +1,8 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate alloc;
|
||||
use alloc::format;
|
||||
use bsp::{
|
||||
entry,
|
||||
hal::{
|
||||
|
@ -9,7 +11,9 @@ use bsp::{
|
|||
},
|
||||
};
|
||||
use core::fmt::Write;
|
||||
use cortex_m::delay::Delay;
|
||||
use defmt_rtt as _;
|
||||
use embedded_alloc::Heap;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use embedded_hal::spi::MODE_0;
|
||||
use panic_probe as _;
|
||||
|
@ -30,6 +34,19 @@ use bsp::hal::{
|
|||
use hd44780_driver as hd44780;
|
||||
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]
|
||||
fn main() -> ! {
|
||||
let mut pac = pac::Peripherals::take().unwrap();
|
||||
|
@ -51,6 +68,14 @@ fn main() -> ! {
|
|||
.ok()
|
||||
.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 pins = bsp::Pins::new(
|
||||
|
@ -106,12 +131,10 @@ fn main() -> ! {
|
|||
pins.gpio20.into_push_pull_output(), //d6
|
||||
pins.gpio21.into_push_pull_output(), //d6
|
||||
&mut delay,
|
||||
).unwrap();
|
||||
|
||||
lcd.reset(&mut delay).unwrap();
|
||||
lcd.clear(&mut delay).unwrap();
|
||||
lcd.write_str("lcd initalized", &mut delay).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
write_lcd(&mut lcd, &mut delay, "Starting");
|
||||
loop {
|
||||
led_pin.set_high().unwrap();
|
||||
external_led_pin.set_low().unwrap();
|
||||
|
@ -120,7 +143,10 @@ fn main() -> ! {
|
|||
external_led_pin.set_high().unwrap();
|
||||
delay.delay_ms(500);
|
||||
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)),
|
||||
};
|
||||
}
|
||||
|
|
BIN
wiring.fzz
BIN
wiring.fzz
Binary file not shown.
Loading…
Reference in a new issue