0

I’m try to get data from rs485 is not work please advise to me.

1.  Try to connect PC usb485 to DY-MD02 is work.
    Send command “AUTO” or “READ”

2.  Try to Arduino rs485 shield to DY-MD02 is not work.
    Send command “AUTO”

my code

''''

char command[4] = {'A', 'U', 'T', 'O'};

int n = sizeof(command)/sizeof(command[0]);   // Number of elements in an array

String incoming = "";   // for incoming serial string data

void setup()

{

      // initialize serial ports
      Serial.begin(9600);
      pinMode(EN,OUTPUT);
      digitalWrite(EN,HIGH); //Enable high, RS485 shield waiting to transmit data
      Serial.write(command,n); //Test send command Auto,Read to RS485
      delay(500);
}

void loop()

{

      String temp;
      digitalWrite(EN,LOW); //Enable low, RS485 shield waiting to receive data

      while(Serial.available() > 0 )
      {
          temp=Serial.read();
          Serial.println(temp);
          delay(1000); //Delay for some time, waiting for data transmitted
      }

}

''''


if change code to = Serial.readString() not show anything.

please help me Thank

XY-MD02

PC USB485 is OK

Data


to Juraj

Maker tell me can connect with Arduino uno and send manual to me.

see in attach file.

enter image description here enter image description here enter image description here enter image description here enter image description here

  • exact model or datasheet of shield please? does it communicate with Uno over hardware Serial? – Juraj Jun 9 at 14:57
  • model of the shield? – Juraj Jun 10 at 7:49
  • it looks like your serial input doesn't provide end of line characters (\r\n) at the end. readString function fetch the character value step by step and store them in buffer till EOL character are received. After receiving EOL character it returns the string. – Vaibhav Jun 10 at 8:00
  • @Vaibhav, readString doesn't care about line ends. it returns after timeout – Juraj Jun 10 at 18:31
  • I want details about the RS485 shield – Juraj Jun 11 at 5:11
0

i'm tray change this code to readStringUntil, is OK

if(Serial.available() > 0)
  {
    temp = Serial.readStringUntil('\n');
    Serial.println(temp);
    delay(1000); //Delay for some time, waiting for data transmitted
  } 

Thank all for help me ^^

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.