Hi Guys this might be an easy one....
I am trying to test an analog read input and failing hard on something so easy.
>>> p = Pin(0)
>>> adc = ADC(p)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid Pin for ADC
What is the proper way to get this? Any call to the ADC(var) in other attempts like ADC(0) states it expects a Pin object.
There also don't seem to be and well named examples for the analog pins in the repo - something I could contribute once I solve this.
Let me know !
ESP32 - ADC - Invalid Pin
Re: ESP32 - ADC - Invalid Pin
Here's an example:
On the pyboard, pin X1 maps to CPU pin A0 which maps to adc channel 0 (ADC123_IN0 in the datasheet). So all of the following should be equivalent:
Code: Select all
import pyb
pot = pyb.ADC('X1')
while True:
x = pot.read()
print(x)
pyb.delay(1000)
Code: Select all
pot = ADC(0)
pot = ADC('X1')
pot = ADC('A0')
pot = ADC(pyb.Pin('A0'))
pot = ADC(pyb.Pin('X1'))
pot = ADC(pyb.Pin.cpu.A0)
pot = ADC(pyb.Pin.board.X1)
-
- Posts: 3
- Joined: Thu Sep 07, 2017 9:11 pm
Re: ESP32 - ADC - Invalid Pin
Thx Dave!
I am however on the Adafruit ESP32 Huzzah. I managed to figure it out after I posted lol. Seems there is a delay in post authorization. I do that a fair bit (answering my own questions hehe)
import machine, neopixel
from time import sleep
np = neopixel.NeoPixel(machine.Pin(4), 120,bpp=3,timing=1)
adc = machine.ADC(machine.Pin(36))
The Above worked for me ... I was trying to control some neopixels with a potentiometer which is now working.
I figured it out by looking at the github port...
https://github.com/micropython/micropyt ... hine_adc.c
STATIC const madc_obj_t madc_obj[] = {
{{&machine_adc_type}, GPIO_NUM_36, ADC1_CHANNEL_0},
{{&machine_adc_type}, GPIO_NUM_37, ADC1_CHANNEL_1},
{{&machine_adc_type}, GPIO_NUM_38, ADC1_CHANNEL_2},
{{&machine_adc_type}, GPIO_NUM_39, ADC1_CHANNEL_3},
{{&machine_adc_type}, GPIO_NUM_32, ADC1_CHANNEL_4},
{{&machine_adc_type}, GPIO_NUM_33, ADC1_CHANNEL_5},
{{&machine_adc_type}, GPIO_NUM_34, ADC1_CHANNEL_6},
{{&machine_adc_type}, GPIO_NUM_35, ADC1_CHANNEL_7},
};
I restricted to one of those Pins Channel 0 / 36 and all cruised through.
Thanks for the assistance!
Hailing from Edmonton, AB!
I am however on the Adafruit ESP32 Huzzah. I managed to figure it out after I posted lol. Seems there is a delay in post authorization. I do that a fair bit (answering my own questions hehe)
import machine, neopixel
from time import sleep
np = neopixel.NeoPixel(machine.Pin(4), 120,bpp=3,timing=1)
adc = machine.ADC(machine.Pin(36))
The Above worked for me ... I was trying to control some neopixels with a potentiometer which is now working.
I figured it out by looking at the github port...
https://github.com/micropython/micropyt ... hine_adc.c
STATIC const madc_obj_t madc_obj[] = {
{{&machine_adc_type}, GPIO_NUM_36, ADC1_CHANNEL_0},
{{&machine_adc_type}, GPIO_NUM_37, ADC1_CHANNEL_1},
{{&machine_adc_type}, GPIO_NUM_38, ADC1_CHANNEL_2},
{{&machine_adc_type}, GPIO_NUM_39, ADC1_CHANNEL_3},
{{&machine_adc_type}, GPIO_NUM_32, ADC1_CHANNEL_4},
{{&machine_adc_type}, GPIO_NUM_33, ADC1_CHANNEL_5},
{{&machine_adc_type}, GPIO_NUM_34, ADC1_CHANNEL_6},
{{&machine_adc_type}, GPIO_NUM_35, ADC1_CHANNEL_7},
};
I restricted to one of those Pins Channel 0 / 36 and all cruised through.
Thanks for the assistance!
Hailing from Edmonton, AB!
Re: ESP32 - ADC - Invalid Pin
Is there a way to create A0 = GPIO26 (ADC2_CHO) as an analog pin for the ESP32 using the machine module? I am trying to use this pin for analog input on the ESP32 Huzzah because the physical location matches the ADC pin of the ESP8266 Huzzah and I’ve already wired up a LDR on a featherwing proto board that uses that pin. In inspecting machine_adc.c, I see that only the ADC1 channels 0 – 7 (GPIO pins 32 – 39) are defined.
Thank you for your advice!
Thank you for your advice!
Re: ESP32 - ADC - Invalid Pin
Hi!
MicroPython for ESP32 only allows ADC1 as mentioned here: On the ESP32 ADC functionality is available on Pins 32-39
Adafruit ESP32 Huzzah exposes ADC2 but also pins 32 & 33 for ADC1https://learn.adafruit.com/adafruit-huz ... er/pinouts It should be possible to use one of these.
MicroPython for ESP32 only allows ADC1 as mentioned here: On the ESP32 ADC functionality is available on Pins 32-39
Adafruit ESP32 Huzzah exposes ADC2 but also pins 32 & 33 for ADC1https://learn.adafruit.com/adafruit-huz ... er/pinouts It should be possible to use one of these.
Re: ESP32 - ADC - Invalid Pin
Thank you, JumpZero. I was hoping for a software solution so that I could swap the LDR-soldered feather proto board between the Huzzah ESP8266 and ESP32. Rather than rewiring the proto board so that the ESP32 can access the LDR voltages via ADC1, I might make one that has a VEML7700 lux sensor. That way, I can then use i2c pins that are compatible with the ESP8266 and ESP32 to get the light levels with either ESP. I see that paulouf34 has very kindly recently shared a library for that light sensor (link to description below).
viewtopic.php?t=5777
viewtopic.php?t=5777
-
- Posts: 847
- Joined: Mon Nov 20, 2017 10:18 am
Re: ESP32 - ADC - Invalid Pin
Lobo port also has access to the ADC2 see https://github.com/loboris/MicroPython_ ... o/wiki/adc
You will need to read the docs to see the restriction on ADC2
You will need to read the docs to see the restriction on ADC2