rs485 receive problem (Arduino uno for Baumer distance sensor)

Hello.
I’m trying to make measuring system and i already made mechanical stuffs.
And i made some code, it have a problem and i need little help.

Board : Arduino Uno Sensor : Baumer OM-70 ect : MAX-485 What i have : rs485 usb converter

First of all, i minimized the code and checked it works.

In the board, transmitting the command is work(when i transmit the command, sensor’s led was on).
But i can’t get any messages from the sensor.(i want to get the distance information from the sensor).

I tried to check on the terminal, and it works. check my code and let me know how to fix it.

ps.

  • sensor’s condition : 8bit/even parity/1stopbit. (that mean is can’t use softwareserial.)
  • When sensor is received the command, transmit the signal to board.(include start command)(nomally, 8~12 ASCII numbers)

Here is my code

#define SSerialTxControl 10   //RS485 Direction control
#define RS485Transmit    HIGH  
#define RS485Receive     LOW

byte baumer;

void setup()   
{
  
  Serial.begin(57600,SERIAL_8E1); //8bit/even/1 stopbit
  Serial.println("Baumer test");   

  pinMode(SSerialTxControl, OUTPUT);  //TX CONTROL
  delay(10);
  
  digitalWrite(SSerialTxControl, RS485Transmit);  //Transmitting
  delay(10);
  
  Serial.println(":01W010;0;E9C3"); // command : start mesuring 
  delay(10);

digitalWrite(SSerialTxControl, RS485Receive);
 
  if (Serial.available() > 0) {              
  baumer = Serial.read();
  Serial.println(baumer);
  Serial.print("command received");
  delay(10);}
  else
  { Serial.print("start command is not received");}
}


void loop()   
{
  digitalWrite(SSerialTxControl, RS485Transmit);  
  Serial.println(":01R021;09F4");   // command : read value

  digitalWrite(SSerialTxControl, RS485Receive);

 if (Serial.available() > 0) {              
  baumer = Serial.read();
  Serial.println(baumer);
  Serial.print("command received");
  delay(10);
        }
  else
  { Serial.print("read command is not received"); }
  
 delay(500);
}

baumer_sensor.ino (1.17 KB)

void loop()   
{
  digitalWrite(SSerialTxControl, RS485Transmit); 
  Serial.println(":01R021;09F4");   // command : read value

  digitalWrite(SSerialTxControl, RS485Receive);

 if (Serial.available() > 0) {             
  baumer = Serial.read();
  Serial.println(baumer);
  Serial.print("command received");

You use the serial interface for both, the communication with your device and for debugging, so printing information to the serial monitor. Every character that you send to the serial monitor is also sent to your device which probably is very confused by all the crap you send to it.

I'm guessing your issue is that "println" doesn't attach both a carriage return and line feed like a terminal does. Instead, try "print(":01R021;09F4\r\n");"

I'm having issues with a Baumer OM-70, too - but I can't get any response at all. The scope says I'm sending data, but I don't get anything from the sensor... I must have something wrong on the connections.

btravers:
I'm guessing your issue is that "println" doesn't attach both a carriage return and line feed like a terminal does. Instead, try "print(":01R021;09F4\r\n");"

I'm having issues with a Baumer OM-70, too - but I can't get any response at all. The scope says I'm sending data, but I don't get anything from the sensor... I must have something wrong on the connections.

Adding the carriage return and newline (line feed) is exactly what println() does, as compared to print().

Arduino Reference: Serial.println()

I am not entirely sure of the timing requirements for the SSerialTxControl line, but you may have to flush() your serial buffer after you do your println() since those characters take time to clock out. flush() waits until the transmit buffer is empty so you know everything has been sent before you toggle SSerialTxControl.