1

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:

https://thepihut.com/products/adafruit-usb-to-ttl-serial-cable?utm_medium=cpc&utm_source=googlepla&variant=758600325&gclid=CJ2U9b2hgs4CFYkp0wodn3kKwg

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.

Tom Lee
  • 33
  • 1
  • 5

1 Answers1

2

First of all make sure that You have properly connected Your UART-USB converter. +5V should not be connected, make sure if Rx & Tx wires are connected properly (sometimes it is misleading).

If You have RPi3 You have a common problem. in RPi3 BT4 has been connected on PCB to UART, what makes communication by UART mainly impossible, unless You will try to shout down BT module. That may be the issue.

For more information check: How do I make serial work on the Raspberry Pi3

Lukasz
  • 61
  • 3