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

    Live Plot data by reading COM port data

    Scheduled Pinned Locked Moved Guides
    live plotcom port
    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.
    • T Offline
      ThomasP
      last edited by

      Hi all,

      I'm using LoPy with Pysense connected to the Pc via USB.

      Is there a way to read the accelerometer data sent by the Pysense and plot it with Spyder for example ?
      I would like to use matplotlib library and use the data from the COM port to make a live plot.

      This is the code I use :

      import serial
      import time
      ser=serial.Serial(port='COM4',baudrate=9600)
      
      while True:
          print("try")
          time.sleep(10)
          s=ser.read(100) #reading up to 100 bytes
          print(s)
      
      ser.close()
      

      And I get "access denied". When the Pysense is sending data, I can't read it because the port is already in use.
      SerialException: could not open port 'COM4': PermissionError(13, 'Access denied.', None, 5)

      So I guess while Atom is using the port Spyder can't access to it ? Am I right ?

      How should I do that ?
      Is there an easier way to print data ? I don't have SD card and I don't want to use one.

      Cheers,
      ThomasP

      robert-hhR 1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @ThomasP
        last edited by

        @thomasp said in Live Plot data by reading COM port data:

        So I guess while Atom is using the port Spyder can't access to it ? Am I right ?

        Close Atom, when you want to read form the serial port on the PC. You may also use a WiFi connection and sockets.

        1 Reply Last reply Reply Quote 0
        • T Offline
          ThomasP
          last edited by

          That was quick.
          I just wanted to make sure I was doing it properly.
          Works great. Thank you.

          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