Accessing ADC pins not specifically called out on the ESP32 Huzzah pin map


#1

I am trying to access ADC pins on teh Huzzah32 module which are not assigned as ADCs on the Zerynth pinmap. How can I do this?

For example, I tried:
inputAnalog = D26
sleep(5000)
for i in range(5):
print(analogRead (D26))
print()
sleep(100)

which compiled but then threw a Guru Meditation Error.

Thanks,

Tomm


#2

Hi tomm,

in the Zerynth pinmap (IO view) of the Huzzah32 you can see that several pins have the ADC label; those marked are the Zerynth Supported ADC channels.

You can call the analogWrite method on (A2, A3, A4, D33.ADC, D34.ADC); D25 and D26 pins are marked as DAC (Digital-to-Analog converter) even if in the board serigraphy are called A0 and A1.

Note: before you can use the analogWrite method you have to define the pin as input through the pinMode(pin, INPUT) method (where pin must be one of A2, A3, A4, D33, D34).

To use each Zerynth Supported device always refer to Zerynth Pinmap.
Let me know if this can help you :slight_smile:


#3

Matteo,

Thanks for the clarification. Unfortunately, we are porting existing HW which uses other pins (Huzzah A0 through A5) with dedicated ADC preamp stages connected to them on our PCBA. We must use these pins or redesign our hardware, which is a pain at this point.

Tomm


#4

Hi tomm,

as you can see here (official esp32 documentation), the Esp32 has 2 ADC driver (ADC1 - Supported by Zerynth - and ADC2) but ADC2 channels (attached to D25/D26 - A0/a1 of huzzah32 serigraphy) has some restrictions in its usage: for example, ADC2 cannot work when Wi-Fi is enabled.

In which kind of application are you going to develop?
feel free to ask me any questions :slight_smile:


#5

Matteo,

Thanks much. The docs are clear:

Since the ADC2 is shared with the WIFI module, which has higher priority, reading operation of adc2_get_raw() will fail between esp_wifi_start() and esp_wifi_stop(). Use the return code to see whether the reading is successful.

Luckily, we do not use the WiFi during ADC capture so A0 and A1 (from the Huzzah) should be OK to use. Now, how do we access them in Zerynth? Do we have to change the driver somehow?

Thanks,

Tomm


#6

Hi tomm,

ADC2 (with Wi-Fi disabled) in Zerynth will be supported soon.
Stay tuned for new updates :slight_smile:


#7

How soon? Need is immediate.

Tomm


#8

Hi @tomm,

our sales team will contact you ASAP to help you with this urgent development.


#9

Thanks. We are spending resources now in solving this issue on our own. Before I use your team’s time here are some questions I want to resolve.

I have tried to fix the code in library for enabling ADC2 on Adafruit Huzzah32 board.
I think zerynth library set const values like ADC0 ~ ADC7. so that I am thinking if ADC0 is ADC1 channel and ADC1 is ADC2 channel which we need?
what files I tried to fix is "zerynth2/dist/r2.1.1/vhal/xtensa-lx6/esp32/vhal_adc.c and adc.h.

I added adc2_configure function and adc2_getdata function like zerynth implemented for adc1.
I tried with that, but it is still not working. May I know which file I missed to be needed to fix as well?
Also I think I should pass ADC1 value to adc init function, but zerynth didn’t find ADC1 value. where should I define the ADC1 value?
Thanks.


#10

Hi @tomm,

I made the sales team contact you because unfortunately this feature cannot be added by a user: your analysis is correct, you would need to edit the vhal_adc.c source file, but the adc2_* functions from Espressif SDK are not currently exposed by the Zerynth Virtual Machine (including all the SDK functions, even those not actually used by our drivers would make the VM too heavy).
To make the second adc work a new virtual machine is required.

Please, let me know if I can help you in another way.


#11

Thanks for checking on this. the feature of using the available ADC resources from adc2 are a required item for continued use of Zerynth by my company. This is blocking migration from our existing code base used in development to Zerynth as our production candidate.

Tomm


#12

Hi…i am a new user here. As per my knowledge you can call the analogWrite method on A2, A3, A4, D33.ADC, D34.ADC D25 and D26 pins are marked as DAC even if in the board serigraphy are called A0 and A1.


#13

It seems to be working fine and now we can access D25, D26 and D4 as adc inputs on our board. How can I set adc params like adc_atten and sample intervals, etc? This is not obvious to me.

Thanks,

Tomm


#14

Found it:l vhal_adc.c. Now the new issue is the adc2 pins are clipping at 2 volts so we cannot read a 3.3V full scale input. Any guidance here would be appreciated. We have verified it is clipping at the ADC input pin and that Vdd is 3.3. Using a Huzzah32 so assumption is that the WROOM32 module on it has VDD_A tied to VDD_33 as on the schematics from espressif.

Tomm


#15

Hi @tomm,

that’s strange, I have tested the ADC2 at various voltage levels and with the default configuration (ADC_ATTEN_11db) it seems to work correctly on the full 0-3.3V range.
Are you sure for the full range to correctly arrive at the pin or to not have somehow edited VDD_A voltage level?

Thank you


#16

I was not aware that VDD_A could be edited. Where does that happen? Perhaps the new code inadvertently changed it.

Tomm


#17

The issue is in my board, not the ESP32. I just checked the output of my ADC pre conditioning circuit and it is clipping without the Huzzah32 installed.

Tomm


#18

OK, stupid designer (me) caused problem. OP AMPs tied to 3.3V rail instead of 5V rail. Clipping occurs at approx 1.5V below the power supply per the spec. This is 1.8V. That I’m seeing ~2V is not surprising as the 1.5V is not a controlled MIN or MAX in TI’s spec. Will report back when cuts and jumps are made and measurements completed.

Tomm


#19

Wired the parts to Vcc (5V) and all is fine.

Tomm


#20

I am going to change clock_div for ADC sample rates.
I found the function “adc_set_clk_div(uint8_t clk_div)” at “esp32/driver” path, which can be changed clock to read adc data.
Where file should I put the function on ?

Should I put this function on vhal_adc.c file?