I am using a robodyn mega 2560 with embedded wiznet5500 chip.
I am trying to communicate with an acromag io expander 963EN-4012 via Modbus TCP/IP.
I am building off of an existing Modbus tcpIP client example from the ArduinoModbus Library.
I am trying to read the holding register for the first analog input. When I load this code I do connect to the acromag, however no matter if I connect a thermocouple to the analog input or not I Just read zeros in the serial monitor.
Am i doing something obviously wrong here.
Any insight would be greatly appreciated.
Here is my code.
#include <SPI.h>
#include <Ethernet.h>
#include <ArduinoRS485.h> // ArduinoModbus depends on the ArduinoRS485 library
#include <ArduinoModbus.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(128, 1, 1, 110); //needs to be a similar mask b/c will not connect
//IPAddress ip(192 , 168, 1, 110);
EthernetClient ethClient;
ModbusTCPClient modbusTCPClient(ethClient);
IPAddress server(128,1,1,100); // update with the IP Address of your Modbus server
//IPAddress server(192,168,1,100);
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
pinMode(7, OUTPUT );
digitalWrite(7, HIGH);//reseting ethernet wiznet5500
delay(3000);
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.********************");
}
}
void loop() {
if(!modbusTCPClient.connected()) {
// client not connected, start the Modbus TCP client
Serial.println("Attempting to connect to Modbus TCP server");
if (!modbusTCPClient.begin(server, 502)) {
Serial.println("Modbus TCP Client failed to connect!");
} else {
Serial.println("Modbus TCP Client connected");
}
}
else {
modbusTCPClient.beginTransmission(2,HOLDING_REGISTERS,3010,2);
modbusTCPClient.write(3);
modbusTCPClient.endTransmission();
modbusTCPClient.requestFrom(2,HOLDING_REGISTERS,3010,2);
while(modbusTCPClient.available())
Serial.println(modbusTCPClient.read());
}
}
Here is datasheet for acromag.
https://www.acromag.com/wp-content/uploads/2019/08/963_964EN_718k.pdf#page=21&zoom=180,-407,696