Modbus tcp/ip on arduino uno r4

Hi, everyone. I have been working on this simple modbus TCP/IP project on Arduino uno r4 Wi-Fi board. Previously, I did a similar project in RTU and succeeded. The task is simple, I want to read my holding registers value from arduino r4 wifi as the slave to update when I short my jumper wire to A0, A1 and A2 on my PC (Qmodmaster).

Well, I have been working on my code past few days and come to realize most modbus tcp libraries are not compatible for this board. For example, I have used the

  1. mudbus.h :frowning:mudbus/Mudbus/Mudbus.h at master · luizcantoni/mudbus · GitHub)

So, I have decided that I just make use of the inbuilt ESP 32 module and try access the wifi, just pull out the IP address and Voila should be seeing some values at my Qmodmaster. However, this is what I have ended up at.



my code

#ifdef ESP8266
 #include <ESP8266WiFi.h>
#else  //ESP32..
 #include <WiFi.h>
#endif
#include <ModbusIP_ESP8266.h> // Use ModbusIP_ESP32.h for ESP32

// Replace with your network credentials
const char* ssid = "yolo";
const char* password = "******";

// Modbus Registers Offsets
const int PIN_ADD = 100;
// Used Pins
const int Pin1 = 0; 
// GPIO1 (TX) is not recommended, use another GPIO

// ModbusIP object
ModbusIP mb;


void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Attempt to connect to WiFi network
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  
  
  Serial.println("");
  //IPAddress ip = WiFi.localIP();
  Serial.println("WiFi connected.");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  // Start Modbus TCP server
  mb.server();
  //pinMode(Pin, OUTPUT);
  //mb.addCoil(PIN_COIL);
  
  Serial.println("Modbus TCP Server started.");

  //pinMode(A0, INPUT_PULLUP);
  //pinMode(A1, INPUT_PULLUP);

  mb.addHreg(PIN_ADD);

}

bool IsConnected = false;
void loop() {
  
    
     mb.task();
   
    
    mb.Hreg(PIN_ADD, analogRead(Pin1));  // Initiate Read Hreg from Modbus Server
    delay(10);

}

  



Hello there.
I have replicated the same issue using Modbus poll simulator. I'm also using the UNO R4 WiFi.
I have used Wireshark and the Modbus Poll view tool to see the Tx raw data sent by the master but the UNO R4 WiFi seems not to respond at all. Have you figured out this issue on your side?