Live Plot data by reading COM port data



  • 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



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



  • @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.


Log in to reply
 

Pycom on Twitter