Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Code to read data from the serial port and plot it.
# -*- coding: utf-8 -*-
from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
from pyqtgraph.ptime import time
import serial
app = QtGui.QApplication([])
p = pg.plot()
p.setWindowTitle('live plot from serial')
curve = p.plot()
data = [0]
def update():
global curve, data
line = raw.readline()
xdata = np.array(data, dtype='float64')
timer = QtCore.QTimer()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):

Thanks for sharing. Just a question: why do you import 'time' from 'pyqtgraph.ptime' ?

ocuflo commented Mar 8, 2015

Think you could help me "pop" the data so the segment in the window scrolls past a fixed time segment instead of continuously appending? I'm able to get past a couple of other obstacles but this one I don't have a clue on. It works fantastically other than this, same with several examples from pyqtgraph BUT I can't seem to get how to control the x axis to show a fixed segment of time....

I am new to Arduino. i currently have an MPU-6050 sensor which gives me accel and gyro values on the serial monitor from the Arduino IDE.
i want to log this data and store it in a csv file. Any leads as to how i can achieve this?


turbinenreiter commented Feb 5, 2017


If you are on linux, you can use picocom to read the serial data and pipe it into a file.

picocom /dev/ttyACM0 > log.csv

Hit ctrl-c if you want to stop logging. You can use tee to see and log the stream at the same time.

If you want to do it in python, you just have to take the above code and write the variable line to a file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment