B4R Question A little confused about pins and ADC

canalrun

Well-Known Member
Licensed User
Longtime User
Hello,
I just got my Adafruit ESP32 Feather board. I have it up and running with B4R 2.51. I can run my FFT test example. If I change the LED pin number to 13, my blink example runs.

The next step is acquiring data with their ADC #1. I want to use ADC #1 because ADC #2 interferes with Wi-Fi.

From the Adafruit docs I see A3 (GPI0 pin #39) might be a good choice.

I have looked at the B4R Beginner's Guide and an example from Johan Hormaza.

He shows:

B4X:
Private A0 As Pin

  ...

A0.Initialize(35, A0.MODE_INPUT)

For this example does the pin number, 35, represent the GPIO pin number?

I've also seen something like Pin.A0 being used instead of 35. Is something like Pin.A0 mapped to the correct number based on the board selected in B4R Tools- Board Selector?

In my case the analog input pin for A3 is GPIO number 39. Would Pin.A3 resolve to 39? Or am I missing something?

Second:
When using the ESP32 ADC I have seen a bit of discussion that it is nonlinear – the number you get is not a straight division of the reference voltage. These discussions occurred years ago. Has the ADC been made linear since then or has somebody developed a correction table to make it linear?

Third:
I want to sample at a specific rate, say 2000 Hz. Is there any advantage to using a Timer or using something like a Looper waiting for the next sample time in a while loop testing a variable based on Micros? Sample time accuracy is important.

Thanks,
Barry.
 

thetahsk

Active Member
Licensed User
Longtime User
See the Adafruit Docs: GPIO & Analog Pins
https://learn.adafruit.com/adafruit-huzzah32-esp32-feather/pinouts#gpio-and-analog-pins-2-15

Bottom row:
  • A0 - this is an analog input A0 and also an analog output DAC2. It can also be used as a GPIO #26. It uses ADC #2
  • A1 - this is an analog input A1 and also an analog output DAC1. It can also be used as a GPIO #25. It uses ADC #2
  • A2 - this is an analog input A2 and also GPI #34. Note it is not an output-capable pin! It uses ADC #1
  • A3 - this is an analog input A3 and also GPI #39. Note it is not an output-capable pin! It uses ADC #1
  • A4 - this is an analog input A4 and also GPI #36. Note it is not an output-capable pin! It uses ADC #1
  • A5 - this is an analog input A5 and also GPIO #4. It uses ADC #2
  • 21 - General purpose IO pin #21
Top row:
  • 13 - This is GPIO #13 and also an analog input A12 on ADC #1. It's also connected to the red LED next to the USB port
  • 12 - This is GPIO #12 and also an analog input A11 on ADC #2. This pin has a pull-down resistor built into it, we recommend using it as an output only, or making sure that the pull-down is not affected during boot.
  • 27 - This is GPIO #27 and also an analog input A10 on ADC #2
  • 33 - This is GPIO #33 and also an analog input A9 on ADC #1. It can also be used to connect a 32 KHz crystal.
  • 15 - This is GPIO #15 and also an analog input A8 on ADC #2
  • 32 - This is GPIO #32 and also an analog input A7 on ADC #1. It can also be used to connect a 32 KHz crystal.
  • 14 - This is GPIO #14 and also an analog input A6 on ADC #2
There's also an external analog input
  • A13 - This is general purpose input #35 and also an analog input A13, which is a resistor divider connected to the VBAT line
Note you can only read analog inputs on ADC #1 once WiFi has started
 
Upvote 0

thetahsk

Active Member
Licensed User
Longtime User
See the espressif
https://docs.espressif.com/projects...eference/peripherals/adc.html#adc-calibration


The esp_adc_cal/include/esp_adc_cal.h API provides functions to correct for differences in measured voltages caused by variation of ADC reference voltages (Vref) between chips. Per design the ADC reference voltage is 1100mV, however the true reference voltage can range from 1000mV to 1200mV amongst different ESP32s.

ESP32 ADC non-blocking library :
https://esp32.com/viewtopic.php?t=4844
https://github.com/terryjmyers/ESP32analogReadNonBlocking
 
Upvote 0

rodmcm

Active Member
Licensed User
Andreas Spiess on UTube has provided a very comprehensive excel spread sheet of the IO of the ESP32. Unfortunately I cant remember which one he did it on. Its an link in the video decription. I have a copy but a 553kb too large to upload here
 
Upvote 0
Top