I know this isnt specific but could you suggest some causes for the following issue:

Mega2560 sends values to Raspi 3 and Raspi 3 receives prints them accordingly (arduino also prints out the values it sends). However, at every occasional instances, garbage data is printed on Raspi terminal while the right data is still printed on the serial monitor for Arduino for a baudrate of 115200 for both.

Any helpful suggestions would be appreciated

  • 2
    Code? Wiring? ... ?
    – Majenko
    Nov 7 '17 at 17:06

This answer will also be not so specific, but you can try:

  • Check all wiring (use a multimeter/analyzer)
  • Reduce the data rate
  • Find out if there is a pattern whenever garbage is created (depending on values?)
  • Check (if possible) for errors (overrun/parity)
  • Play with the parity setting/stop bits to see if it makes a difference

I often have this issue with my data-loggers. They use Nano or Uno to send readings to the Pi3 Python programs. My Arduinos send data every 60 seconds. Then the Pi adds a date and time stamp and appends it to the day's data file

Invariably, in my case, it happens that I might get some garbage as I start the program, and then it runs fine after that. I solved the garbage part by flushing the input buffer. Then I also make sure my data is of the expected length, which depends on how many variables it is sending.

Once I applied a little Python Fu the issue has ceased to be a problem.

Here is a generic representation of my solution:

import serial
ser = serial.Serial("/dev/ttyUSB0",9600)
while True :
    linein = ser(readlin)
    if len(linein<10) : continue
    if len(linein>50) : continue

Not the answer you're looking for? Browse other questions tagged or ask your own question.