preliminary UART setup for CO2 sensor
This commit is contained in:
parent
48d8ef95d6
commit
fab4ac1af7
3 changed files with 32 additions and 0 deletions
|
|
@ -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