Problem send data to pump

I have 2 devices. Device 01 of the manufacturer, well connected to the pump. I use the device 02 connected in series with equipment 01 and pump shaft. I read data the device 01 send for the pump:
Device send frame: 4 40 51 5 and pump answered: 4

This is my Transmission Sequence

But when I disconnect device 01, only connect device 02 and pump. And to send the 4 40 51 5 to the pump , no feedback from the pump .
This is my code:

#include <SoftwareSerial.h>
#define SSerialRX        0  //Serial Receive pin
#define SSerialTX        1  //Serial Transmit pin
 
#define SSerialTxControl 2   //RS485 Direction control
#define RS485Transmit    HIGH
#define RS485Receive     LOW
 
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
int msg1[] = {0x4, 0x40, 0x51, 0x5};
int Received;
int i;
void setup()   
{
  Serial.begin(19200);
  pinMode(SSerialTxControl, OUTPUT);   
  digitalWrite(SSerialTxControl, RS485Receive);  // 
  RS485Serial.begin(19200);   
}
 
void loop()
{ /
  digitalWrite(SSerialTxControl, RS485Transmit);  // 
  for (i = 0; i < sizeof(msg1); i++) {
    RS485Serial.write(msg1[i]);     
    delay(1.7); 
  } // gửi dữ l
  delay(1.7);
  digitalWrite(SSerialTxControl, RS485Receive);  //
  if (RS485Serial.available()) 
  {
   Received = RS485Serial.read();  //gets one byte from serial buffer
   Serial.println(Received, HEX);
  }
}

Thanks.

when you connect multiple devices onto a common network there normally is some form of unique identifier (address) that you would need to send along with your request so that you get a reply from the device you are targeting.

do you know if device 1 and 2 have and address identifier and if yes what are they?

Device 01 is master to control Pump.
My Pump with address: 01
EOT: 4 (Start bit)
SA: 40 (Station address: 40<=>@ <=> 01)
UA: 51 (Method Polling)
ENQ: 5 (Stop bit)
If the pump receives the data (4 40 51 5), it will respond to the data (4)

Get an Arduino that has a spare HardwareSerial port (Mega, Leonardo, Micro) and try HardwareSerial rather than SoftwareSerial.

Don't have any delay()s during sending a message.

...R
Serial Input Basics - simple reliable ways to receive data.

shinsozach:
Device 01 is master to control Pump.
My Pump with address: 01
EOT: 4 (Start bit)
SA: 40 (Station address: 40<=>@ <=> 01)
UA: 51 (Method Polling)
ENQ: 5 (Stop bit)
If the pump receives the data (4 40 51 5), it will respond to the data (4)

what about device 2... that the issue you raise in you original post. what is its address?

Thanks for help.

I'm use Arduino Uno, so i have to change Arduino Mega.

shinsozach:
I'm use Arduino Uno, so i have to change Arduino Mega.

I am not guaranteeing that it will solve the problem, but it might. HardwareSerial works much better than SoftwareSerial.

Have you tried removing the delay()s ?

...R

I have remove delay(), but it not response

You wrote in the first post:"I have 2 devices. Device 01 of the manufacturer, well connected to the pump. I use the device 02 connected in series with equipment 01 and pump shaft. I read data the device 01 send for the pump:".

But your diagram shows device 1 and 2 are connected in parallel to the pump.

Which is it?

Paul

Sorry I'm confused. Yes, it is in parallel.
So when Device 01 sends the pump command, device 02 can read.

shinsozach:
Sorry I'm confused. Yes, it is in parallel.
So when Device 01 sends the pump command, device 02 can read.

Ok, Same with calling the characters sent "bits".

Now, please tell us what RS-485 adapter you are using with the Arduino.

Paul

I'm using TTL UART to RS485 Converter Module

shinsozach:
I'm using TTL UART to RS485 Converter Module
MAX485 - TTL UART to RS485 Converter Module | Core Electronics Australia

That should work. I see Travis gave the only review, perhaps he could stop by and confirm.

Paul

Now, I'm use Mega 2560. But it's not response

#define SSerialTxControl 30   // Pin for MAX485 - HIGH send, LOW receive
#define RS485Transmit    HIGH
#define RS485Receive     LOW
byte msg1[] = {0x04, 0x40, 0x51, 0x05};
int byteReceived;
int i;
void setup()
{
 Serial.begin(19200);   //Serial communication for USB.
 pinMode(SSerialTxControl, OUTPUT);   
 digitalWrite(SSerialTxControl, RS485Receive);  // 
 Serial3.begin(19200,SERIAL_8E1);  //Serial communication for RS48 - 14 pin as Tx and 15 pin as Rx.
}

void loop()
{/*
   digitalWrite(SSerialTxControl, RS485Transmit);
 for (i = 0; i < sizeof(msg1); i++) {
   Serial3.write(msg1[i]);     
 } 
 digitalWrite(SSerialTxControl, RS485Receive);
 */
 digitalWrite(SSerialTxControl, RS485Transmit);
 Serial3.write(0x04);  
// Serial3.flush() ;
 Serial3.write(0x40);   
// Serial3.flush() ;
 Serial3.write(0x51);   
// Serial3.flush() ;
 Serial3.write(0x05);    
// Serial3.flush() ; 
 digitalWrite(SSerialTxControl, RS485Receive);
 if (Serial3.available()) //When you receive some data 
 {
   byteReceived = Serial3.read();
   Serial.println(byteReceived, HEX);
}
}

Out of interest, other than going through the datasheet/manual to get the message set, did not sniff the rs485 network when Device1 was connected to see what was ACTUALLY transmitted?

There might just be more to it that just those few bytes which could be why you are not getting any response...

This is the communication between Device 01 and the pump.



I use Arduino Mega2560. This is my code when not connected to the pump

#define SSerialTxControl 2   //RS485 Direction control
#define RS485Transmit    HIGH
#define RS485Receive     LOW
byte msg1[] = {0x4};
byte Received;
int i;
void setup()   
{
  Serial.begin(19200);
  Serial1.begin(19200);   
}
void loop()
{ 

  Serial1.write(msg1[0]);      
  if (Serial1.available()) 
  {
   Received = Serial1.read();  //gets one byte from serial buffer
   Serial.println(Received); 
  }
}

My serial monitor:

There is something wrong with sending data: send: 0x4 but display :
0
4
16

Thanks all.
i use delay(10) then it response

digitalWrite(SSerialTxControl, RS485Receive);
delay(10);