D12 Analog Input on ESP32 DevKit C

I am trying to use D12 as a analog input on an ESP32 DevKit C board and I get this error, “Guru Meditation Error: Core 0 panic’ed (LoadProhibited). Exception was unhandled.”

This happens on all that Dx pins that according to the diagram support analog input.

The code is just a modified example:

import streams
import adc # import the adc module

#create a serial port stream with default parameters
streams.serial()

pinMode(D12,INPUT_ANALOG)

i = 1
while i != 0:

#read the input on analog pin 0
sensor_value = adc.read(D12)

#convert the analog reading (which goes from 0 - 4095.0) to a voltage (0 - 3.3V):
voltage = sensor_value * (3.3 / 4095.0)

#print out the raw and converted values:
print("sensor raw value:", sensor_value,"Voltage:",voltage)

sleep(300)
print(i)
i = i-1

What an I doing wrong? Is analog input only supprted on the Ax pins?

Probably your selected pin (D12) ,even though according to zerynth studio it’s an analog pin, is only digital. Try to change pin and choose an analog one (Ax pin). If an analog pin is not present physically on your board but zerynth suggests there are analog pins just use a pin corresponding to one of the analog pins.

Alessandro1, thanks for the response. I know the Ax pins work, that is not the issue. Either I am not initializing the digital pins correctly, or the documentation is in error. If it is the latter than it has been like that for a long time and should be updated. If I’m not doing something correctly, than I would like to know that as well.

Hi @NBT
If the pin is marked as ADC-enabled in Zerynth pinmap, then It should work with ADC peripheral.
in the read() method, When you use a digital pin for ADC, use the ADC initialization. adc.read(D12.ADC)

I’ll make sure to state that in the documentation. :smile:

Here is the code:
import streams
import adc # import the adc module

#create a serial port stream with default parameters
streams.serial()

pinMode(D12,INPUT_ANALOG)

i = 1
while i != 0:

#read the input on analog pin 0
    sensor_value = adc.read(D12.ADC)
    
    #convert the analog reading (which goes from 0 - 4095.0) to a voltage (0 - 3.3V):
    voltage = sensor_value * (3.3 / 4095.0)
    
    #print out the raw and converted values:
    print("sensor raw value:", sensor_value,"Voltage:",voltage)
    
    sleep(300)
    print(i)
    i = i-1

adc.read(D12.ADC) - that’s eaht I was missing. Thanks!