readline() on command line? Easily misaligned!

[ Elia: python and GNUplot ] [ stackExchange ]

[ python print formatting ]

I recall reading about programmers who like working in immediate windows, to try a few ideas out first. And there are programmers who do scripting (bash, perl, python, Tcl, and so forth…), and there are programmers who call plotting routines in low-level languages. Honestly, I wanted to try all of these out at some point, and now I have to do each of these together!

Looks like python’s serial library is popular in the arduino community, and this is the typical program that gets everyone going:

import serial
ser = serial.Serial('/dev/ttyACM0', 57600)
while 1:
        textln = ser.readline()

This does print out the serial data coming out of the arduino (after perhaps one reset), and the data packet (from the MPU-6050) needs to be parsed, thrown into a file (buffer), and plotted next. For parsing, I thought it would be nice to just get to python’s command window equivalent:

>>> python
>>> include serial
>>> ser = serial.Serial('/dev/ttyACM0', 57600)
>>> print(serial.readline())

Initially, I would keep entering in the print command, and the packet numbers would increment sequentially. That’s wrong, because I should have missed a lot of packets in between the enters! Then, they get messed up, as the ‘\n’ character seems to keep getting lost.

Now I am getting long long delays too.

Screen Shot 2015-03-21 at 5.42.23 PM Screen Shot 2015-03-21 at 5.42.59 PM Screen Shot 2015-03-21 at 5.42.44 PM


One thought on “readline() on command line? Easily misaligned!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s