Hey!
I'm pretty new to the world of embedded programming, and even newer to physical electronics, so I'm more than a little worried I perma-fried my new board!
I've put together a repository that I hope will explain my setup and code: https://github.com/tecywiz121/esp32-adc
The summary is that I'm trying to build a plant monitoring device with a couple sensors, and while I was developing yesterday I was able to read values from the Huzzah32's battery voltage pin and from the photoresistor. I moved on to coding up the 1-Wire temperature sensor, and when I came back to put it all together, the values I read from ADC2 are always the minimum. The battery voltage still works as far as I can tell.
I've checked that there's voltage going across the photoresistor, and if I put the pin in digital mode it switches from high to low if I put a bright light on it. That makes me think I somehow screwed up the ADC itself?
Thanks!
ESP32 ADC2 worked yesterday, doesn't today with same-ish code
-
- Posts: 3
- Joined: Thu Mar 31, 2022 4:55 am
-
- Posts: 9591
- Joined: Thu Nov 26, 2015 4:08 am
Re: ESP32 ADC2 worked yesterday, doesn't today with same-ish code
Are you using WiFi now? ADC2 is incompatible with WiFi.
-
- Posts: 3
- Joined: Thu Mar 31, 2022 4:55 am
Re: ESP32 ADC2 worked yesterday, doesn't today with same-ish code
I don't believe so, unless I need to explicitly disable it. This is the entirety of my code:
Code: Select all
use embedded_hal::adc::nb::OneShot;
use esp_idf_sys as _;
use esp_idf_hal::prelude::*;
use esp_idf_hal::adc::{self, PoweredAdc};
use esp_idf_hal::gpio::Pin;
fn main() {
esp_idf_sys::link_patches();
let p = Peripherals::take().unwrap();
let mut pin = p.pins.gpio14.into_analog_atten_11db().unwrap();
let config = adc::config::Config::new().calibration(true);
let mut adc = PoweredAdc::new(p.adc2, config).unwrap();
unsafe {
esp_idf_sys::gpio_set_pull_mode(pin.pin(), esp_idf_sys::gpio_pull_mode_t_GPIO_PULLUP_ONLY);
}
loop {
let value = nb::block!(adc.read(&mut pin)).unwrap();
println!("Value: {}", value);
std::thread::sleep(std::time::Duration::from_secs(1));
}
}
-
- Posts: 3
- Joined: Thu Mar 31, 2022 4:55 am
Re: ESP32 ADC2 worked yesterday, doesn't today with same-ish code
Switching to embedded-hal 0.2.7 fixed it!
Who is online
Users browsing this forum: No registered users and 109 guests