I am trying to control a raspberry pi running linux using a Windows PC by sending data over a serial port.
I have followed the following guide:
http://www.instructables.com/id/Read-and-write-from-serial-port-with-Raspberry-Pi/
And I have got the following code to read data (run on the pi):
#!/usr/bin/env python
import time
import serial
ser = serial.Serial(
port='/dev/ttyAMA0',
baudrate = 9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
counter=0
while 1:
x=ser.readline()
print(x)
And this code to send data to the pi (from the PC):
#!/usr/bin/env python
import time
import serial
ser = serial.Serial(
port='COM6',
baudrate = 9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
counter=0
while 1:
ser.write(('Write counter: %d \n'%(counter)).encode('utf-8'))
time.sleep(1)
counter += 1
I am using the UART cable from Adafruit:
I have installed the correct drivers and python libraries, but when I run the code the pi does not read any data. No errors are displayed.
Can anyone point me in the right direction on this issue? The eventual goal is to control LEDS wired to the Pi from an application running on the PC by sending the Pi some data, and having it run the data through a program to determine which LEDs to light.
/dev/ttyS0
. – goldilocks Jul 20 '16 at 15:13