Hello, I'm beginner to modbus RTU Protocol, and i need to get data from 16 Bit Magnetic Guide Sensor from CCFROBOT. The vendor didn't gave me enough information about the specific application, and only shows me that the output is HEX.
I use
Arduino Mega
16 Bit Magnetic Guide Sensor (A(5) B(6) connected to A+ B-
RS485 to TTL Converter with RX TX connected to Serial1
I try this program that give me hex and making new line each total counter reach 8 bit.
void setup() {
Serial.begin(9600); // Initialize Serial Monitor
Serial1.begin(115200); // Initialize Serial1 for RS485 communication
}
void loop() {
int byteCount = 0; // Initialize byte count
while (Serial1.available()) {
char incomingByte = Serial1.read();
if (incomingByte < 0x10) {
Serial.print("0");
Serial.print(incomingByte, HEX);
Serial.print(" ");
byteCount++;
if (byteCount % 8 == 0) {
Serial.println();
}
}
if (Serial.available()) {
Serial1.write(Serial.read());
}
}
with output shown on image below. i also attach the one and only manual that given by the vendor.
anyone could give me help about what should i do with that output? i'll be helped a lot. thank you
I assume that as you are using Serial1, that you have a MEGA2560 Arduino board.
The manual says the default baud rate is 9600 baud. You should set Serial1 to this baud rate.
The RS485 link is half duplex - i.e. only 1 device can transmit on the bus at once. You control this aspect using the RE and DE signals on the RS485 module via a couple of discrete outputs.
Can you provide a drawing of how you have connected the various pieces together. A hand drawn sketch will do.
Also search the forum for "NPK sensor". It's a soil sensor that also uses RS485 and the modbus protocol. Look at how the comms works and how RE and DE are controlled during transmission.
As far as I can tell, all the information you need is in the manual. It's actually pretty well written. I think perhaps you need to read a bit on the MODBUS protocol to understand what it means?
output mode. The default mode of the module is change output mode;
I'm not sure how you're getting data that at least looks valid with the wrong baud rate, but the device should be sending data out when something changes, so you don't even need to send it commands. The message protocol is on page 5, section 2 under "Slave Reply."