I am trying to talk to Arduino Uno over RS485, i am unable to receive anything, i receive complete garbage values. I am using Software UART on Arduino and Hardware on Raspi. code on Raspi is as below, please ignore comments.
import serial import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) GPIO.setup(7,GPIO.OUT) def get_temp_val(): # function for getting some value. ser=serial.Serial('/dev/ttyAMA0',9600) #enable the serial port ser.close() ser.open() while True: #loop for reapeated actions. GPIO.setup(7,1) #enable transmit mode on MAX485 time.sleep(4) val=raw_input("enter something:") ser.write(val) time.sleep(.5) GPIO.setup(7,0) #switch the MAX485 to receive mode. time.sleep(4) temp=ser.read(ser.inWaiting()) print "received data is", temp GPIO.cleanup() get_temp_val()
EDIT : one way communication from arduino to raspberry pi was achieved, baudrate=9600. I am using ADM485(0-5v logic) chip for RS485 interface. I am giving input to raspi through a voltage divider to make sure that pins are not damaged. But i am unable to send from raspi to arduino. Whats my apprehension is whether 3.3v logic from pi to ADM485 is culprit? Should i use any booster to make 3.3v pi logic to 5v.