[SOLVED] MKR Ethernet TCP Connection with Horsepower Sensor

Hello everyone -

I’ve had a few years experience with programming Arduino microcontrollers, but I still consider myself a novice. I’m currently using the MKR 1400 GSM with an MKR ETH shield to capture data from the LittleFuse MP8000 horsepower sensor. The MKR board/shield and sensor are connected via Ethernet cable. The sensor’s programming guide explicitly states:

“The RJ45 jack on the side of the MP8000 is the interface for MODBUS TCP and Ethernet/IP. The user can access the MP8000 via a network or via a direct connection.”

The sensor’s point-to-point configuration guide (attached) provides the IPv4 ip address and subnet mask in order to make the direct connection.

You can probably tell where I’m going with this. When I set up an Ethernet Client to connect to the Modbus TCP Server, it fails. I’ve tried all sorts of combinations of client/servers, ports, and Ethernet libraries to get the two to pair, but nothing gives.

Code here:

#include <SPI.h>
#include <Ethernet.h>
#include <ArduinoRS485.h> 
#include <ArduinoModbus.h>

//Enter a MAC address and IP address for your controller below.
//The IP address will be dependent on your local network.
//gateway and subnet are optional:
byte MKRETHmac[] = { 0xEC, 0xF4, 0xBB, 0x40, 0x33, 0x1D };
byte MKRETHip[] = { 10, 106, 0, 1 };
byte MP8000mac[] = { 0x00, 0x21, 0x6F, 0x00, 0x49, 0xB5 }; 
byte MP8000ip[] = { 10, 106, 0, 1 };
byte MP8000subnet[] = { 255, 255, 0, 0 };
byte gateway[] = { 192, 168, 0, 1 };
byte dns[] = { 1, 1, 1, 1 };

EthernetClient ethernetclient;
ModbusTCPClient modbusTCPclient(ethernetclient);

void setup() {

Serial.begin(9600);
  
//disable the SD card
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);

//initialize the ethernet shield
Ethernet.init(5); // MKR ETH shield
Ethernet.begin(MKRETHmac, MKRETHip, dns, gateway, MP8000subnet);
   
delay(3000);
  
// Open serial communications and wait for port to open:
while (!Serial); {}

//Start Modbus TCP and Ethernet client connections
modbusTCPclient.begin(MP8000ip, 502);
delay(1000);
ethernetclient.connect(MP8000ip, 502);

if (ethernetclient.connected()) {
    Serial.println("Ethernet Client Connected!");
    char c = ethernetclient.read();
    Serial.print(c);
    } else {
       Serial.println("Ethernet client failed to connect!");
       Serial.print("Local IP Address: ");
       Serial.println(Ethernet.localIP());
       Serial.print("DNS Server IP Address: ");
       Serial.println(Ethernet.dnsServerIP());
       Serial.print("Gateway Address: ");
       Serial.println(Ethernet.gatewayIP());
       Serial.print("Subnet Mask Address: ");
       Serial.println(Ethernet.subnetMask());
       }

if (modbusTCPclient.connected()) {
    Serial.println("Modbus TCP client connected!");
    } else {
       Serial.println("Modbus TCP client failed to connect!");
       Serial.println(modbusTCPclient.lastError());
       }
}

void loop() {}

and serial monitor output here:

Ethernet client failed to connect!
Local IP Address: 10.106.0.1
DNS Server IP Address: 1.1.1.1
Gateway Address: 192.168.0.1
Subnet Mask Address: 255.255.0.0
Modbus TCP client failed to connect!

Any help?

MP8000_Point_to_Point_Configuration.pdf (927 KB)

did you try it over a switch or router?

byte MKRETHip[] = { 10, 106, 0, 1 };
byte MP8000ip[] = { 10, 106, 0, 1 };

The Arduino and the MP8000 cannot use the same IP address. I would configure the MP8000 to 10.106.0.2.

In point to point mode, the gateway and dns should be left unspecified since they are not used.

I have never used MODBUS so that is all I can comment on.

@Juraj I’m trying the connection over direct Ethernet cable between the MP8000 and MKR ETH shield. Picture of setup attached.

@gbafamily that was my initial thought, too. I plugged my laptop into the MKR ETH shield to find its IP address and then did the same for the MP8000. Using those IP Addresses made no difference.

cjtate14:
@Juraj I’m trying the connection over direct Ethernet cable between the MP8000 and MKR ETH shield. Picture of setup attached.

@gbafamily that was my initial thought, too. I plugged my laptop into the MKR ETH shield to find its IP address and then did the same for the MP8000. Using those IP Addresses made no difference.

for direct connection:

  1. use crossed cable
  2. you are responsible to set the IP addresses in this network with two devices

Problem solved! The MP8000 just needed a firmware update. Lights on the sensor changed to indicate data transmission and the serial monitor reported successful connection.

Thanks for the help anyway!