Introduction: Ethernet Shields V2.0 and Modbus TCP Communication
About using bidirectionnal Modbus TCP communication with the latest Etehernet Shields V2.
Step 1: Comparisons and Settings
It's been many years I use the famous and unexpensive Ethernet shield for Arduino based on W5100. It works fine but the latest shields are faster and low energy consumers. I recently bought 2 type of Ethernet Shield V2:
-the SEEEDUINO (25 EUROS) based on the W5200 and runnig with Ethernet_Shield_W5200 library
-the official Arduino Ethernet Shield V2.0 (30 EUROS) based on the W5500 and running with Ethernet2-1.0.4 library
To establish a good Modbus TCP communication, you need to use the famous "mudbus" library and modify it easily as indicated in the tutorial.
Then the sketch are a little different between these 2 shields but it works fine.
AdvancedHMI can check the communication.
nota: I have got some definition problems with the pdf tutorial and I don't know why. Now it's solved. I give you an Office file.
Step 2: Conclusion
Thanx to all website advised in my tutorial.
Question 3 years ago on Step 2
Using Codesys on a Raspberry PI, I am able to read the Mb.R = 6666. When I try to write a single bit to (7, Mb.R), any bit 1-8 will mak ethe LED come on. Bits 9-16 will not turn on the LED. There is a project by Juan Reyes on GitHub that assigns array of i/o to modbus registers but he uses a W5100 shield library and I cannot seem to get it to work with a w5200 shield. Could you assist in merging to two projects? My end goal is to have a Arduino Mega as my remote i/o and the Raspberry Pi as the Controller.
Nice work on the above!!
Answer 3 years ago
You don't have print the begining of your mega sketch, and if there are some communication problems, I think it comes from the library you use and the running order of the instruction of your sketch. I made recently an instructables with a comparative matrix between various shields vs various boards. Have a look on the sketch between the mega board and the seeduino W5200. You must use the same modified-myself libraries I gave and I think it will work fine with the "mudbus" library (i never try to test others for the moment). Don' forget in the communication: the master (the PY here) read/write to the modbus registers (16 bits) of the slave (mega2560) with an offset of +1: mb9 of the slave is mb10 of the master. Let me know.
Best regards. Manu