0

I am currently working on serial communication between RPi and PIC. I am new to Raspberry Pi and python world.... okay following is my code:

from serial import *
from time import *
import RPi.GPIO as GPIO

q='1'

GPIO.setmode(GPIO.BOARD)
GPIO.setup(18,GPIO.OUT)
GPIO.output(18,GPIO.LOW)

ser = Serial("/dev/ttyS0",9600)
for x in range (0,20):
     GPIO.output(18,GPIO.HIGH)
     sleep(0.001)
     ser.write(q)
     print('input is '+q)
     GPIO.output(18,GPIO.LOW)
     sleep(1.1)
     deta=ser.read()
     print('OutPt is '+deta)

I am using GPIO pin as an enable pin for RS485 driver. I transmit 1 and should receive the same for 20 iterations but I get a bunch of garbage first then 1 and again garbage and again 1. In between 1's their are two or four garbage values as delay is varied. I have read different solutions like interrupt, threading, etc. but I can't wrap my head around any of them. Is their any simple solution?

Dougie
  • 5,381
  • 11
  • 22
  • 30

0 Answers0