Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Analog fast plotting

    Scheduled Pinned Locked Moved Discussion
    wipy
    3 Posts 2 Posters 1.1k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R Offline
      robmarkcole
      last edited by

      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-hhR 1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @robmarkcole
        last edited by

        @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
        R 1 Reply Last reply Reply Quote 0
        • R Offline
          robmarkcole @robert-hh
          last edited by

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

          1 Reply Last reply Reply Quote 0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better ๐Ÿ’—

          Register Login
          • 1 / 1
          • First post
            Last post

          Pycom on Twitter

          Pycom