ESP32 In MicroPython: Analog Input
Written by Mike James & Harry Fairhead   
Tuesday, 17 October 2023
Article Index
ESP32 In MicroPython: Analog Input
Calibration
How Fast?

How Fast?

A rough estimate of how fast each of the read methods are is easy to get:

from machine import ADC,Pin
import time
adc = ADC(Pin(32),atten=ADC.ATTN_11DB)
t = time.ticks_us()
for i in range(10000):
    pass
print(time.ticks_diff(time.ticks_us(), t)/10000)
t = time.ticks_us()
for i in range(10000):
    m=adc.read()
print(time.ticks_diff(time.ticks_us(), t)/10000)
t = time.ticks_us()
for i in range(10000):
    m=adc.read_u16()
print(time.ticks_diff(time.ticks_us(), t)/10000)
t = time.ticks_us()
for i in range(10000):
    m=adc.read_uv()
print(time.ticks_diff(time.ticks_us(), t)/10000)

The two raw read methods take about 49μs and the calibrated method read_uv takes about 50μs which puts the maximum sampling rate at about 20kHz. Reducing the accuracy to 9-bits reduces the time taken by about 1μs.

In Chapter but not in this extract

  • The Hall Effect Sensor
  • Internal Temperature Sensor
  • Digital to Analog
  • Touch Sensors

 

Summary

  • The ESP32 has two 12-bit ADCs, but only one is available for general use and it provides six easy-to-use channels.

  • The calibration voltage is available as a value stored in the eFuse memory. MicroPython makes use of this to correct the measurement.

  • The read_uv method is corrected and at around 50μs per sample isn’t much slower than the alternatives.

  • An onboard Hall effect sensor uses two of the ADC inputs.

  • The onboard temperature sensor has its own analog input and is really only useful for measuring the processor temperature.

  • There are two 8-bit ADC channels which use GPIO25 and GPIO26.

  • Using a lookup table you can generate wave forms at 400Hz to 10kHz, depending on resolution.

  • The ADC class doesn’t support many of the more advanced features of the ADC hardware but you can use the sine wave generator directly.

  • There are also ten touch sensors. These are capacitive sensors and do not require contact with the GPIO line.

Programming the ESP32in MicroPython

By Harry Fairhead & Mike James

esppython360

Buy from Amazon.

Contents

       Preface

  1. The ESP32 – Before We Begin
  2. Getting Started
  3. Getting Started With The GPIO 
  4. Simple Output
  5. Some Electronics
  6. Simple Input
  7. Advanced Input – Interrupts
  8. Pulse Width Modulation
       Extract:
    PWM And The Duty Cycle
  9. Controlling Motors And Servos
  10. Getting Started With The SPI Bus
  11. Using Analog Sensors
       Extract:
    Analog Input
  12. Using The I2C Bus
       Extract
    : I2C, HTU21D And Slow Reading 
  13. One-Wire Protocols
  14. The Serial Port
  15. Using WiFi
     Extract:
    WiFi 
  16. Sockets
     Extract:
    Client Sockets
     Extract:
    SSL Client Sockets
  17. Asyncio And Servers
     Extract:
    Asyncio ***NEW!
  18. Direct To The Hardware
     Extract:
    Using Hardware Registers 

<ASIN:187196282X>

espbook

 

Comments




or email your comment to: comments@i-programmer.info

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner



Last Updated ( Tuesday, 17 October 2023 )