I'm trying to send some data serially to my PC from an RPi 3, but I'm receiving gibberish most of the time. I have already performed the prerequisites: disabled Bluetooth and enabled GPIO 14 and 15 to use UART0/ttyAMA0 (more info here and here).
I am using a USB to TTL converter - connected to GPIO 14 (TXD0), 15 (RXD0), and Ground).
The Python test code I'm using to send data from the Pi is as follows:
import serial
port = serial.Serial("/dev/serial0", baudrate=9600, timeout=20000,bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE, stopbits = serial.STOPBITS_ONE)
while True:
port.write('A')
And on the receiving end, I'm using a MATLAB script:
clear all;
clc;
if ~isempty(instrfind) //Check for any open serial port objects and close them
fclose(instrfind);
delete(instrfind);
end
rpiserial=serial('COM4','BaudRate',9600, 'DataBits', 8, 'StopBits', 1, 'Parity', 'none');
fopen(rpiserial);
pause(0.1)
y = fscanf(rpiserial, 'c')
fclose(rpiserial);
Most of the times after running the MATLAB script I get gibberish on the receiving PC end. How do I fix this?