I am using the Arduino Modbus Library on a Nano set-up as a modbus server and am unable to read or write to input registers but can read and write to coils. I have my computer set-up as the Client and I'm using python with the minimalmodbus library. I'm also using this USB to RS485 device and this RS485/TTL device on the arduino Nano end. The code on the Nano is as follows:
#include <ArduinoRS485.h>
#include <ArduinoModbus.h>
void setup() {
Serial.begin(9600);
ModbusRTUServer.begin(1, 9600);
ModbusRTUServer.configureCoils(0x00, 3);
ModbusRTUServer.coilWrite(0,1);
ModbusRTUServer.coilWrite(1,1);
ModbusRTUServer.coilWrite(2,0);
ModbusRTUServer.configureInputRegisters(0x00, 3);
ModbusRTUServer.inputRegisterWrite(0, 10);
ModbusRTUServer.inputRegisterWrite(1, 104);
ModbusRTUServer.inputRegisterWrite(2, 57759);
}
void loop() {
ModbusRTUServer.poll();
if (ModbusRTUServer.coilRead(0)) {
for (size_t i = 1; i <= 3; i++) {
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
}//for
ModbusRTUServer.coilWrite(0,0);
}//if
}
If coil 0 is 1 the built in LED will flash 3 times and then the coil gets set back to 0. I pretty much followed the Arduino Modbusy Library examples to write the coils and registers. I'm a little confused as to why the coils and the input registers start with 0x00? Should the input register start at 40000 and that should be in hex? Clarification on what's happening here would be really appreciated. Trying to figure things out by going through the code, but clearly haven't figured things out yet.
In python I'm using the following to code to make the light blink and read from one of the coils and it works fine.
import minimalmodbus
devise0 = minimalmodbus.Instrument('/dev/cu.usbserial-AR0K3VZ7', 1)
devise0.serial.baudrate = 9600
n = devise0.read_bit(1,1)
devise0.write_bit(0,1)
print(n)
But when I run this line of code in python:
m = devise0.read_register(0,1)
print(m)
I get the following error:
IllegalRequestError: Slave reported illegal data address
Again, any help would be greatly appreciated.
-RG