Go Down

Topic: Serial communication to a python program (Read 2639 times) previous topic - next topic

zenseidk

Hello all,

I have a rather strange situation. I have in the past made a bunch of WORKING Python programs that reads serial data and trends it on a matplotlib graph in Python.

The data is formatted as a comma separated string, as in: "data,data,data,..."

Arduino example:

Serial.print(data1);
Serial.print(",");
Serial.print(data2);
Serial.print(",");
Serial.print(data3);
Serial.print(",");
...
Serial.println(datan);


From the python side I would read, decode and strip the incoming string with:

self.serialString = self.arduino.readline().strip().decode("UTF-8")

This used to work in the past, but for some strange reason, it doesn't work any more.
Now, I have tried on several machines that used to run the code, but none work.
That kind of rules out a Python or Pyserial version issue, as I tried on machines that would run it in the past.

The console gives me this error:

Arduion is type: <class 'serial.serialposix.Serial'>
Serial<id=0x7fb48cba9eb8, open=True>(port='/dev/ttyUSB0', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=1, xonxoff=False, rtscts=False, dsrdtr=False)
opening serial port
Traceback (most recent call last):
  File "mainMplGraph.py", line 312, in updateFigure
    self.incomingData = self.arduino.readline().decode("UTF-8").strip()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfa in position 1: invalid start byte
opening serial port
Traceback (most recent call last):
  File "mainMplGraph.py", line 312, in updateFigure
    self.incomingData = self.arduino.readline().decode("UTF-8").strip()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfa in position 1: invalid start byte

I tried using the line self.serialString = self.arduino.readline().decode("UTF-8").strip()

too as suggested on stackexchange, but it does not work either.

Has something changed in the way the arduino Serial library formats data in recent times?

Does anyone have a suggesting as to what can be the issue? Should I post more of the code?

Thanks

zenseidk

Okay, I found a simple old program that actually worked with just a one variable graph and an LCD.

I think the problem is in my parsing function or in the serial object settings in python.

Robin2

Are you saying that programs that worked in the past do not work now even though there have been NO changes to the program code?

OR

Are you saying that a system that worked in previous times does not work in a new program?

If it is the latter, the first thing to do is to check the former.

If the old programs still work then you have a problem in your new program.

If the old programs no longer work you have to investigate what has changed on your PC. For example were the programs written for Python 2.x and are you now trying to run them with Python 3.x

There is not much point speculating further until you have checked this out.

If that does not help you to find the problem please post the complete Python and the Arduino programs.

It may help to try this simple Python - Arduino demo. It was written with Python 2.7


...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up