Skip to main content
2 of 2
Added an image that shows UART configuration
JayB
  • 1
  • 1
  • 2

Unable to read the RS232 attached GPIO pins the same way as USB serial port on Pi3

I maybe new to this, but I have the following configuration in place.

Step 1:

(Device 1){RS232}<=======(RS232 to USB cable)=======>{USB}(Pi)

  • I have an RS232 to USB cable attached to the USB port of the Pi and a device which I have named Device 1 on the other end, and it's feeding data that looks like this(Reading in hex):

    F8 CD 0E 0F 00 11 00 00 1C 6D 01 01 8E A4 01 49 A4 91 02 00 44 38 7A 8B EC

  • Now I disconnect the "RS232 to USB cable".

Step 2:

(Device 1){RS232}<=======(RS232 to GPIO)=======>{Pins: RX TX GND}(Pi)

  • Similarly, I attach RS232 port of Device 1 to the GPIO RX TX pins of the Raspberry Pi 3. When I read the data from GPIO pins, it looks like the following(Reading in hex):

    A0 63 2F EF DD FF FF C7 25 FD FD E3 B7 FD 6F B7 DD FB FF 59 85 00

Results:

  • The data received from the USB connection is correct, whereas the GPIO data is not. I expected both of the results to be the same, but they vary I don't know why?!

Here is my code:

#!/usr/bin/env python
import time
import serial

ser = serial.Serial(
   port='/dev/ttyAMA0',
   #port='/dev/ttyUSB0', #used for step 1
   baudrate=19200,
   parity='N',
   stopbits=1,
   bytesize=8,
   timeout=0.050,
   xonxoff=False,
   rtscts=False,
   dsrdtr=False
)
counter=0

while 1:
   x=ser.readline()
   if x:
       print x
       hex_list = ["{:02x}".format(ord(c)) for c in x]
       print hex_list

Could somebody please tell me what I should do to read the data from GPIO and get the same result as the USB data??

Step 2

JayB
  • 1
  • 1
  • 2