Problem communicating between arduino and RPi via RS485 bus.

Hi. I am trying to communicate between Arduino and RPi via RS485 bus. But when I try to read data from arduino, nothing is received on the RPi side, it just keeps printing blank spaces.
I have tried with low baudrate as suggested in some posts.
I am using arduino pro mini (Atmega 328).

Here is the arduino code.

void setup () {
  pinMode(3, OUTPUT);                 //RS485 pin
  delay(50);
  digitalWrite(3, LOW);               //Enabling in receive mode
  Serial.begin(4800);    
  delay(100);
} 

void loop() {
if (Serial.available())
{
 digitalWrite(3, HIGH);               //Enabling transmit 
 delay(5);
 Serial.println('hello'); 
 delay(20);
 digitalWrite(3, LOW);                //Disabling transmit
 delay(5);
}
}

Here is the python code.

import serial
import RPi.GPIO as gpio

RS485_pin = 2;
gpio.setmode(gpio.BCM);
gpio.setup(RS485_pin, gpio.OUT);
gpio.output(RS485_pin, gpio.LOW);	

ser = serial.Serial('/dev/ttyAMA0',  4800, timeout =1)
ser.flushInput();
ser.flushOutput();

while 1:    
    data = ser.readline()
    print (data,'\n')

shreyagrawal_28:
Hi. I am trying to communicate between Arduino and RPi via RS485 bus. But when I try to read data from arduino, nothing is received on the RPi side, it just keeps printing blank spaces.
I have tried with low baudrate as suggested in some posts.
I am using arduino pro mini (Atmega 328).

Here is the arduino code.

void setup () {

pinMode(3, OUTPUT);                 //RS485 pin
 delay(50);
 digitalWrite(3, LOW);               //Enabling in receive mode
 Serial.begin(4800);    
 delay(100);
}

void loop() {
if (Serial.available())
{
digitalWrite(3, HIGH);               //Enabling transmit
delay(5);
Serial.println('hello');
delay(20);
digitalWrite(3, LOW);                //Disabling transmit
delay(5);
}
}

Instead of your fixed delays on the write use:

unsigned long deadtime=0;
void loop(){
if(Serial.availabe()){
  deadTime = millis();  // require 50ms of inactivity on the bus before switching to TX
  char ch=Serial.read(); // do something with the input
  //
  }
else {
  if(millis()-deadtime>50){ // serial bus has been inactive for over 50 ms
    digitalWrite(3, HIGH);               //Enabling transmit 
    Serial.println('hello'); 
    Serial.flush();  // make sure all data has actually exited the TX pin before switching to RX
    digitalWrite(3, LOW);                //Disabling transmit back into RX mode
    deadTime = millis(); // restart dead counter
    }
}

It also look like your Arduino code was waiting for a byte from Serial() before it would send?

Chuck.