Analog fast plotting



  • Hi all
    I am reading an analog input on my Wipy, printing out the value and plotting the values on my Mac via serial. I would like to know what is the fastest rate at which I can read/plot in this way?

    My analysis: https://github.com/robmarkcole/Useful-python-for-medical-physics/blob/master/Experiments in ipython notebooks/Serial/Read from serial 26-9-2017.ipynb

    My wipy code:

    import pycom
    import machine
    from machine import Pin
    
    # Piezo sensor
    adc = machine.ADC()
    apin = adc.channel(pin='P16',attn=3)
    
    while True:
      print(apin()/1000)


  • @robert-hh thank you for your insight, will explore those options.
    Cheers!



  • @robmarkcole There are a few limiting factors, one of them is the serial transmission at 115200 Baud, which is about 10000 characters/second. If your messages with the test values are 10 bytes long each (dont forget the CCR-LF), then it's about 1000 messages/second. The other factor is the Python script itself to capture the analog data and send it. For better precision, that capturing should be done by a timer interrupt, writing to a circular buffer. But that would result in a 300µs jitter. The fastest timer interrupt you can set is 1 ms, or 1000 samples/s.
    I've done a similar thing on a ESP8266, which included communication with an external I2C ADC (ADS1115) and updates to a local SPI OLED every second. The fastest I could get was 250 samples/s. Since the ESP32 is somewhat faster, in total at least 500 samples/s seem achievable.
    If communication speed is the limiting factor, you can set the UART to faster speed, like 460800 Baud, if the MAC can handle that.
    Other options:

    • Set up a WiFi link, which is faster.
    • Use binary data transmission instead of printable characters and do the pretty print at the Mac

Log in to reply
 

Pycom on Twitter