I'm doing a sanity check with some write/ read data operation on serial port, on my raspi-3. My data are read nicely for the 2nd/3th time, but after that, the data are corrupted, as if there was a misalignement of data.
The idea here is to transmit data to my usb to ttl converter (mine is a ft232r breakout), then reading it back on the ttyUSB0.
So I write data to /dev/ttyS0 (as suggested) instead of /dev/ttyAMA0 because /dev/ttyAMA0 is already taken by the bluetooth module. The data is transmited to TX pin of raspi and get back to the RX pin on my ft232r, then read back on the ttyUSB0 file. When I launch my read code, it outputs the data nice the 2 / 3 third time. After that, I only get corrupted data. If I relaunch my read program, it work nice again, the 2/3 time, and corrupted data again.
Here my read.py code:
#!/usr/bin/env python import time import serial ser = serial.Serial( port='/dev/ttyUSB0', baudrate = 9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=1 ) while True: for line in ser.read(): print line
And my write.py:
#!/usr/bin/env python import time import serial import io ser = serial.Serial( port='/dev/ttyS0', baudrate = 9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=1 ) while 1: ser.write('hello\n') time.sleep(1)
Now my output are:
What is strange is that the first output are ok. So this is not a baud problem.But after that, my data is not encoded as expected, I always get the same ouput(��p�nn6�), so I don't know where is the problem.
I'm asking this question because I have bad soldered my rx / tx pin of my ft232r. And the tx pin is kind of floating. So I was wondering if it could be a hardware problem. But since I can get the first output nicely formed, I'm guessing this is not this case. Can someone help me understanding the problem? I'm totally lost. Thanks.
edit Thank to Milliway, it appears that it is a baudrate problem. Enabling uart in boot/config wasn't enought. You have to add this extra line at the end of /boot/config.txt:
You have to add the rate the clock frequency of the raspi board. The solution is here: http://raspberrypi.stackexchange.com/questions/45570/how-do-i-make-serial-work-on-the-raspberry-pi3/45571#45571