B4R Question Analog reading with the ESP32

Gerardo Tenreiro

Active Member
Licensed User
Hello again, I continue advancing in my project and with each step I take a new problem appears.
On this occasion the analog reading of two pins.
The example program is this:
Private Sub AppStart
Serial1.Initialize(9600)
Log("AppStart")

' Configura Entradas Analogicas
ADC1.Initialize(36,ADC1.MODE_INPUT)
ADC2.Initialize(39,ADC2.MODE_INPUT)
' Lanza Tarea
T_C.Initialize("T_C_Tick",500)
T_C.Enabled = True

End Sub


Private Sub T_C_Tick
Dim Dl1 As UInt
Dim DL2 As UInt
' Lee Entradas
Dl1 = ADC1.AnalogRead
DL2 = ADC1.AnalogRead
' Presenta Resultados
Log("Dl1= ", NumberFormat(Dl1,4,0)," ... Dl2= ", NumberFormat(DL2,4,0))

End Sub
In the output log there is always a ZERO value in both channels and the ESP32 stops working at random times, every hour or every 10 minutes it stops and the values stop appearing in the log.
attached log
1684262368469.png


El esquema electrido de las entradas analogicas es dividir entre 10 la tension, os adjunto esquema

1684262444576.png

and the connection to the ESP32
1684262513009.png

As always, thank you very much for your help and I will continue looking for the solution.
thank you so much
 

teddybear

Well-Known Member
Licensed User
Hello again, I continue advancing in my project and with each step I take a new problem appears.
On this occasion the analog reading of two pins.
The example program is this:

In the output log there is always a ZERO value in both channels and the ESP32 stops working at random times, every hour or every 10 minutes it stops and the values stop appearing in the log.
attached log
View attachment 142072

El esquema electrido de las entradas analogicas es dividir entre 10 la tension, os adjunto esquema

View attachment 142073
and the connection to the ESP32
View attachment 142074
As always, thank you very much for your help and I will continue looking for the solution.
thank you so much
What is the voltage range of 1,2pin of J1901?J
 
Upvote 0

embedded

Active Member
Licensed User
Longtime User
Hello again, I continue advancing in my project and with each step I take a new problem appears.
On this occasion the analog reading of two pins.
The example program is this:

In the output log there is always a ZERO value in both channels and the ESP32 stops working at random times, every hour or every 10 minutes it stops and the values stop appearing in the log.
attached log
View attachment 142072

El esquema electrido de las entradas analogicas es dividir entre 10 la tension, os adjunto esquema

View attachment 142073
and the connection to the ESP32
View attachment 142074
As always, thank you very much for your help and I will continue looking for the solution.
thank you so much
These pin does not work well with ADC....Please Shift to other pins...for more details please read datasheet.....

Try this on GOOLGE....

sensVP and sensVN pins ON ESP32​

 
Upvote 0

Gerardo Tenreiro

Active Member
Licensed User
These pin does not work well with ADC....Please Shift to other pins...for more details please read datasheet.....

Try this on GOOLGE....

sensVP and sensVN pins ON ESP32​

The low noise amplifier in the ESP32 is removed from the specs and documentation as it never really worked well. As such, you can't use those pins for low voltage measurements. You can still use them as ADC pins, but they have the same range as other ADC pins.

In the link it clearly says that they can be used with the ADC normally. that is my case. I want to measure a voltage from 0 to 1V on the pins that with the voltage divider I can have a voltage from 0 to 8 Volts on the input terminals J1901
I cannot change the pins since the PCB cards are made and in the testing process, although they are prototypes, they are large cards with a high manufacturing cost.
Before deciding on these pins, I did some tests on the breadboard with an ESP32 WROOM 32 of 4mb and it worked correctly. the only difference now is that the ESP32 WROOM 32 is 16mb and a different version.
Thank you very much for the help.
 
Upvote 0

embedded

Active Member
Licensed User
Longtime User
Do one thing....remove the esp32 chip....and measure the voltage across those pin. Placed your multimeter ground to the ADC1 Near ground. Did you find any voltage there. As shown in second picture of your post. JL301
 
Upvote 0

Gerardo Tenreiro

Active Member
Licensed User
Do one thing....remove the esp32 chip....and measure the voltage across those pin. Placed your multimeter ground to the ADC1 Near ground. Did you find any voltage there. As shown in second picture of your post. JL301
The voltage measured at pin 36 and 39 is 0.5V. I generate this tension with a tension injector and it is totally stable. The voltage measurements are made with a reliable multimeter.
I am totally sure that the voltage on the analog input pins is approximately 0.5V. It would have to give a value of approximately 500 quantants.
It is not an error of precision or wrong measurement, it is a problem of reading = 0 continuously.
It doesn't matter what voltage you have on the analog input pins
 
Upvote 0

embedded

Active Member
Licensed User
Longtime User
Your code looks ok...Please measure voltage between ADC Pin and ESP32 Ground...if it is found ok...Then your esp32 That ADC Port is damage ....change with new one and try it.
 
Upvote 0

embedded

Active Member
Licensed User
Longtime User
Test your code on my es32board....me also getting same 00 result everytime.....please look it...https://www.esp32.com/viewtopic.php?t=23693
 
Upvote 0

Gerardo Tenreiro

Active Member
Licensed User
Your code looks ok...Please measure voltage between ADC Pin and ESP32 Ground...if it is found ok...Then your esp32 That ADC Port is damage ....change with new one and try it.
I have 5 prototypes built and 7 ESP32s available, none of which give a value other than 0 for the ADC measurement. It is not very likely that all ESP32 is bad. I lean more towards something in the ESP32 model itself. It is the first time that I use ESP32 WROOM 32 16mB from Version 1.0 and the key may be in the ESP32 version.
Thank you very much for the help
Test your code on my es32board....me also getting same 00 result everytime.....please look it...https://www.esp32.com/viewtopic.php?t=23693
It helps me to know that it doesn't just happen to me and these ESP32s.
Regarding the link, it deals with another topic, not with using pins 36 and 39 as analog inputs, or so it seems to me.
Thank you
 
Upvote 0

Minicz

New Member
Licensed User
Longtime User
Try this:
ADC1.Initialize(ADC1.A0, ADC1.MODE_INPUT) 'for GPIO36
ADC2.Initialize(ADC2.A3, ADC2.MODE_INPUT) 'for GPIO39
In my case ESP32 analog input GPIO34 works good as A6
 
Upvote 0

Gerardo Tenreiro

Active Member
Licensed User
Try this:
ADC1.Initialize(ADC1.A0, ADC1.MODE_INPUT) 'for GPIO36
ADC2.Initialize(ADC2.A3, ADC2.MODE_INPUT) 'for GPIO39
In my case ESP32 analog input GPIO34 works good as A6
Thanks, I try the code and I get the same result, all the readings have a value of 0.
Verified that in PIN34 and 39 I have 0.5 Vcc.
It is the same initial code with the change in the two lines that you suggest.
#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 600
#End Region
'Ctrl+Click to open the C code folder: ide://run?File=%WINDIR%\System32\explorer.exe&Args=%PROJECT%\Objects\Src

Sub Process_Globals
Public Serial1 As Serial

Public ADC1 As Pin ' Pin de la Entrada Analogica 1
Public ADC2 As Pin ' Pin de la Entrada Analogica 2
Public DAC1 As Pin
Public DAC2 As Pin

Public V_DAC As Byte


Public T_C As Timer
End Sub

Private Sub AppStart
Serial1.Initialize(9600)
Log("AppStart")

' Configura Entradas Analogicas
'ADC1.Initialize(36,ADC1.MODE_INPUT)
ADC1.Initialize(ADC1.A0, ADC1.MODE_INPUT) ' for GPIO36
'ADC2.Initialize(39,ADC2.MODE_INPUT)
ADC2.Initialize(ADC2.A3, ADC2.MODE_INPUT) ' for GPIO39

DAC1.Initialize(25,DAC1.MODE_OUTPUT)
DAC2.Initialize(26,DAC2.MODE_OUTPUT)

' Lanza Tarea
T_C.Initialize("T_C_Tick",500)
T_C.Enabled = True

End Sub


Private Sub T_C_Tick
Dim Dl1 As UInt
Dim DL2 As UInt


DAC1.AnalogWrite(V_DAC)
DAC1.AnalogWrite(255-V_DAC)
V_DAC = V_DAC + 1
If V_DAC > 255 Then V_DAC = 0

' Lee Entradas
Dl1 = ADC1.AnalogRead
DL2 = ADC1.AnalogRead
' Presenta Resultados
Log("Dl1= ", NumberFormat(Dl1,4,0)," ... Dl2= ", NumberFormat(DL2,4,0)," ... V_DAC= ", NumberFormat(V_DAC,3,0))

End Sub


1684824506083.png


Thank you very much, to see if we find the correct key to be able to use the analog inputs of the ESP32 in a correct way.
 
Upvote 0

Minicz

New Member
Licensed User
Longtime User
In my working program (a few years ago) I I had:
#StackBufferSize: 1200 ' for 600 ESP32 may crash more offen.
I used GPIO34 and it is analog A6. 34 and above can only be inputs pins and they need resistor to VCC.
Try other pins then GPIO36 and GPIO39.
GPIO35 is analog A7 in B4R. GPIO33 - A5, GPIO32ia A4
 
Upvote 0

Gerardo Tenreiro

Active Member
Licensed User
In my working program (a few years ago) I I had:
#StackBufferSize: 1200 ' for 600 ESP32 may crash more offen.
I used GPIO34 and it is analog A6. 34 and above can only be inputs pins and they need resistor to VCC.
Try other pins then GPIO36 and GPIO39.
GPIO35 is analog A7 in B4R. GPIO33 - A5, GPIO32ia A4
I have set it to 2000 because I have many routines and they jump a lot between one and the other.

#StackBufferSize: 2000
But this is not the problem, the problem is that the 16mb ESP32 WROOM 32 is not working the same as the other ESP32. I have another ESP32 DEV32 that does read the analog inputs of the pins. The same code is these ESP32 always returns value = 0
It's like you need to initialize it in a different way in your code.
Thanks for the help and I'll keep looking for a solution.
 
Upvote 0
Top