I want to get the values of (say- PV, SV, etc) from PID controller through Modbus to the Arduino using RS485 module. I have tried "Simple Modbus Library", but dont know how to work on for reading the register values (Say- 40001, etc) to the arduino from this PID Controller module through MODBUS.
Please Help
If you read throught the documentation for the library, you will have a better idea of what to do.
The registers at 4000, 40000 are holding registers, so you will use functions related to these for reading and writing.
You don't detail what Arduino you are using or the EIA-485 module you are using, I assume they are both compatiable?
You say you have tried with the SimpleModbus library, but again, you don't specify which one and which version, and you don't say what results you obtained with it so far?
If you post your code (in code brackets) then that might help us.
There is no need to say 'Please Help', that's the whole reason you are posting, right ?
I have also tested simple modbus library example for communicating two arduino's using RS485 module on modbus for controlling the LED brightness by sending the PWM value from other arduino on MODBUS, and this worked fine for me.
But now i want to communicate and read the "process value(PV)" and "set value(SV)" from yudian PID model ai-526 to my arduino.
Haven't see any code you have tried, so it's not possible to know where your problem is.
Below is an example that will request 5 holding registers starting at the first location of holding registers and print them out to the serial console.
You need to know what baud rate and at what starting location your data is available in the PID controller, I haven't check. Also set the correct pin for your EIA-485 Tx/Rx direction control.
Try this and adapt it and see what is different to your own program.
#include <SimpleModbusMaster.h>
#define RS485TxEnable 11 // RS485 modbus direction control pin:
#define baud 9600 // modbus port speed:
#define timeout 1000 // modbus timeout in mSec:
#define polling 500 // modbus scan rate in mSec:
#define retry_count 10
#define TOTAL_NO_OF_REGISTERS 5 // number of registers to poll for:
enum
{
PACKET1,
// PACKET2,
TOTAL_NO_OF_PACKETS // leave this last entry
};
Packet packets[TOTAL_NO_OF_PACKETS]; // array of Packets to be configured
unsigned int regs[TOTAL_NO_OF_REGISTERS]; // master register array
long previousMillis = 0;
long interval = 1200;
unsigned long currentMillis;
int good_count = 0;
void setup() {
Serial.begin(9600); // start the serial port
modbus_construct(&packets[PACKET1], 1, READ_HOLDING_REGISTERS, 1, 5, 0); // initialize packet 1:
modbus_configure(&Serial1, baud, SERIAL_8N2, timeout, polling, retry_count, RS485TxEnable, packets, TOTAL_NO_OF_PACKETS, regs);
}
void loop() {
modbus_update();
currentMillis = millis();
if (currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
Serial.print("Exception errors: ");
Serial.println(packets[PACKET1].exception_errors);
Serial.print("Failed requests: ");
Serial.println(packets[PACKET1].failed_requests);
Serial.print("Successful requests: ");
Serial.println(packets[PACKET1].successful_requests);
for(int i = 0; i < 5; i++)
{
Serial.print("Successful Count: ");
Serial.println(good_count++);
Serial.print("Reg: ");
Serial.print(i);
Serial.print(" Value: ");
Serial.println(regs[i]);
}
}
}
AriefXaloka, welcome to the forums, but please be more clear and specific with your question and statements so we can understand you better.
The library user 'KAPIL2910 ' is using is linked and described if you care to read the thread, it is all there for you, open your eyes.
You write:
still problem at communication error
Can you understand how useless and unhelpful this information is for everyone. Like I mentioned, be clear and specific about anything you care to write here, or people just will not have time to help you.