-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Looking for API to read ADC value on Pico #42
Comments
I think the method you are looking for is See https://github.com/rp-rs/rp-hal/blob/main/rp2040-hal/examples/adc.rs#L113 for an example. |
Thanks @jannic. So, I've got, use rp_pico::entry;
use panic_halt as _;
use rp_pico::hal::prelude::*;
use rp_pico::hal::pac;
use rp_pico::hal;
...
let mut adc = hal::adc::Adc::new(pac.ADC, &mut pac.RESETS);
let mut adc_pin_0 = hal::adc::AdcPin::new(pins.gpio26.into_floating_input());
...
loop {
let pin_adc_counts: u16 = adc.read(&mut adc_pin_0).unwrap();
delay.delay_ms(2000);
}
} But I'm getting this error for
And this error for its arg
|
You are missing |
Thank you @jannic. So, I was trying to use what I think is the higher level |
|
The name conflicts with the public trait method OneShot::read. This isn't an issue with correct programs, as rustc just uses the visible function when called from other crates. But if you forget importing OneShot, you get a confusing error message: ``` error[E0624]: method `read` is private --> rp2040-hal/examples/adc.rs:116:45 | 116 | let temp_sens_adc_counts: u16 = adc.read(&mut temperature_sensor).unwrap(); | ^^^^ private method | ::: /home/jan/rp2040/rp-rs/rp-hal/rp2040-hal/src/adc.rs:302:5 | 302 | fn read(&mut self, chan: u8) -> u16 { | ----------------------------------- private method defined here | = help: items from traits can only be used if the trait is in scope help: the following trait is implemented but not in scope; perhaps add a `use` for it: | 15 + use cortex_m::prelude::_embedded_hal_adc_OneShot; | ``` Note that the references method in line 302 is not the one that should be called, and also has different parameters. (This was noticed in rp-rs/rp-hal-boards#42)
Thanks, looking forward to getting my Pico to test this out! |
The name conflicts with the public trait method OneShot::read. This isn't an issue with correct programs, as rustc just uses the visible function when called from other crates. But if you forget importing OneShot, you get a confusing error message: ``` error[E0624]: method `read` is private --> rp2040-hal/examples/adc.rs:116:45 | 116 | let temp_sens_adc_counts: u16 = adc.read(&mut temperature_sensor).unwrap(); | ^^^^ private method | ::: /home/jan/rp2040/rp-rs/rp-hal/rp2040-hal/src/adc.rs:302:5 | 302 | fn read(&mut self, chan: u8) -> u16 { | ----------------------------------- private method defined here | = help: items from traits can only be used if the trait is in scope help: the following trait is implemented but not in scope; perhaps add a `use` for it: | 15 + use cortex_m::prelude::_embedded_hal_adc_OneShot; | ``` Note that the referenced method in line 302 is not the one that should be called, and also has different parameters. (This was noticed in rp-rs/rp-hal-boards#42)
If you like, come to the rp-rs matrix room at https://matrix.to/#/#rp-rs:matrix.org. Nice place to talk, ask questions, share your projects etc. |
I have a 0-3.25V input wired to
GPIO26
(ADC0
). Where is the API to read an analog value (0-4095)? I think I'm looking for something like,let adc_pin_0 = pins.gpio26.into_analog_input();
Update: is it
into_floating_input()
?The text was updated successfully, but these errors were encountered: