2

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

Majenko
106k5 gold badges82 silver badges139 bronze badges
asked Jun 9, 2019 at 13:27
7
  • exact model or datasheet of shield please? does it communicate with Uno over hardware Serial? Commented Jun 9, 2019 at 14:57
  • model of the shield? Commented Jun 10, 2019 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. Commented Jun 10, 2019 at 8:00
  • @Vaibhav, readString doesn't care about line ends. it returns after timeout Commented Jun 10, 2019 at 18:31
  • I want details about the RS485 shield Commented Jun 11, 2019 at 5:11

2 Answers 2

1

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 ^^

answered Jun 11, 2019 at 13:44
0

I will suggest try to use Modbus Master library it will help you get the data from sensor. The issue with the code is you are only sending the command but while interfacing with modbus there is a packet/ frame which you need to form and then send it the packet/frame format is in the below diagramModbus Packet

I will prefer use an Arduino Mega or other arduino which have more than 1 Serial port for communication. I also faced a similar issue but it was resolved after digging a little bit you can have a look at the issue here

answered Oct 18, 2020 at 7:09

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.