preliminary UART setup for CO2 sensor
This commit is contained in:
parent
48d8ef95d6
commit
fab4ac1af7
3 changed files with 32 additions and 0 deletions
7
firmware/Cargo.lock
generated
7
firmware/Cargo.lock
generated
|
|
@ -637,6 +637,7 @@ dependencies = [
|
|||
"esp-idf-svc",
|
||||
"esp-idf-sys",
|
||||
"log",
|
||||
"mh-z19",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -946,6 +947,12 @@ version = "2.7.5"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0"
|
||||
|
||||
[[package]]
|
||||
name = "mh-z19"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08e20228a4dda61bd521e7316780ba2ec8d88170e4999fbd641c1da98e2eea28"
|
||||
|
||||
[[package]]
|
||||
name = "minimal-lexical"
|
||||
version = "0.2.1"
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ esp-idf-svc = "0.51"
|
|||
bme280 = "0.5.1"
|
||||
esp-idf-hal = "0.45.2"
|
||||
esp-idf-sys = { version = "0.36.1", features = ["binstart"] }
|
||||
mh-z19 = "0.3.3"
|
||||
|
||||
# --- Optional Embassy Integration ---
|
||||
# esp-idf-svc = { version = "0.51", features = ["critical-section", "embassy-time-driver", "embassy-sync"] }
|
||||
|
|
|
|||
|
|
@ -6,8 +6,11 @@ use esp_idf_hal::{
|
|||
ADC2,
|
||||
},
|
||||
delay::Delay,
|
||||
gpio,
|
||||
i2c::{I2cConfig, I2cDriver, I2cError},
|
||||
prelude::Peripherals,
|
||||
uart::{config, UartDriver},
|
||||
units::Hertz,
|
||||
};
|
||||
|
||||
struct InitResult<'s, I2C> {
|
||||
|
|
@ -113,6 +116,27 @@ fn init<'a>() -> InitResult<'a, I2cDriver<'a>> {
|
|||
|
||||
log::info!("ADC2 channel driver@GPIO4 initialized!");
|
||||
|
||||
//set up mh-Z19B CO2 sensor
|
||||
let tx_pin = peripherals.pins.gpio5;
|
||||
let rx_pin = peripherals.pins.gpio6;
|
||||
|
||||
//obtain UART connection
|
||||
let uart_config = config::Config::new().baudrate(Hertz(115_200));
|
||||
let uart = match UartDriver::new(
|
||||
peripherals.uart1,
|
||||
tx_pin,
|
||||
rx_pin,
|
||||
Option::<gpio::AnyIOPin>::None,
|
||||
Option::<gpio::AnyIOPin>::None,
|
||||
&uart_config,
|
||||
) {
|
||||
Ok(uart_drv) => uart_drv,
|
||||
Err(error) => {
|
||||
log::error!("Error initializing UART connection: {error}.");
|
||||
panic!();
|
||||
}
|
||||
};
|
||||
|
||||
InitResult {
|
||||
bme280: bme280,
|
||||
no2_adc: adc_channel_driver,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue