Update ESP8266 Industrial Modbus TCP IP V2.0

 There have been numerous applications in the ESP8266, I have taken as a goal to integrate this module into one of the industrial protocols most commonly used Modbus TCP IP, it would be good to have a node or sensor that sends data or a driver, OPC, PAC, PLC, HMI or SCADA.

A long time ago I found a group of people in forums.adafruit already had an advance and example have been implemented and improvements suggested by ibbba for the contribution.
The programming code for ESP8266 in this case was implemented in Arduino IDE versions 1.6.4 above. These 2 tutorials indicate connection and basic programming ESP8266 01 and 03 modules.


Programming ESP8266 01 with Arduino IDE 


Programming ESP8266 03 with Arduino IDE 

ESP8266 12E NodeMCU

PLC Panasonic ESP8266 pdacontrol


Previous tests library ModbusTCPSlave
ESP8266 – 01 Modbus Slave TCP IP (Ethernet) for Industrial Applications


In previous tests with the library Original ModbusTCPSlave, it had two drawbacks of application:
Code Execution
properly functioning communication modbus tcp, but do not run the code in the routine void loop, as a temporary solution the library for ESP8266 amending stop the connection and reconnect again, the problem with this method is time reconnection can make the teacher while accepting the data indicate error in data reception.
Serial port
Originally ESP8266 the serial port was used as a debug port in hexadecimal, I have made changes to the library so that Serial can be used freely.

Update September  2016
VIDEO Update ESP8266  Industrial Modbus TCP IP   V2.0

Update December 2016

Video Tutorial NodeMCU  ESP8266 12E   Modbus TCP/IP Control I/O  ADC PWM


With the new modifications it has been omitted disconnection allowing a constant flow of communication if stop the connection between the ESP8266 and modbus tcp master mandatory.


He has implemented Ticker library created and documented by igrr, it is an object to call a given function with a certain period. Each Ticker calls a function. You can have as many as you like tickers, the only memory limitation.

Important note: When creating tickers consider not create any delay would affect both modbus communication protocol, such as the execution of that function.



the connection between the ESP8266 and a simulator configured as master Modbus tcp was made.
-initially The Ticker Parada is created.


call the function value is created and defined 2 Holding Registers:

Mb.MBHoldingRegister[0] =  Holding Registers 1
Mb.MBHoldingRegister[1] =  Holding Registers 2

Mb.MBHoldingRegister[0]  send a random(0,51) value to the Modbus Master and validate the upgrade value.

 Mb.MBHoldingRegister[1]  is used for reading a value sent from the Modbus Master and from the serial terminal validate the update.

modbus routine Mb.Run();  is executed; and execute the Ticker Parada.attach_ms(25,valor); every 25ms doing the value created in the function.

Taking this example as a basis, they could perform management functions for I / O similar and digital, load and others, taking only into account not implement any delay.



Industrial software integration with OPTO 22

Arduino + ESP8266 + Software Opto22 example Scada Industrial

Where to buy ?

Downloads Github

Code  ESP8266_Industrial_ModbusTCP_V2

Improved version for ADC and PWM I / O control

Code & Library Arduino IDE ESP8266 Control I/O 


Arduino Mega 2560 Oled Display I2C Master Modbus RTU Scada Industrial Connection
Arduino + ESP8266 + Software Opto22 example Scada Industrial

Youtube Channel


You may also like...

5 Responses

  1. Unknown says:

    Hello I'm looking solusion to connect esp8266 witch modbus on bard witch codesys and I cant configure it. In modbu docementation Holding regisers start from 40001 and You in Yours example seve random value to 0 register. Can you give me some advice how to configure it.

    • PDAControl says:

      Hi, The modbus protocol usually has a variation in their records or an offset position registration example 40001 = [0] or 40001 = [1] the 40001 can be located in any of the records [0] or [1 ] is an offset of +/- 1 record almost all devices occurs, I suggest try some TCP modbus simulator.

      Holding Register [0] === 40001
      Holding Register [1] === 40002
      Holding Register [2] === 40003


      Holding Register [1] === 40001
      Holding Register [2] === 40002
      Holding Register [3] === 40003


  2. B.K.NZOKO says:

    Hello! I am very interested in what you are doing. I would like just like to say that before seeing what you did on your triacommand site, I managed to run the ModbusTCPSlave without Tiker Library. Also, if you find this interesting, I would be happy to intrduce it to you. I say that with great caution.

    However I would like to migrate this work to realize a server MODBUS TCP OPC UA. A bit like what did in this video: https://WWW.youtube.com/watch?v=EBnWfGH6I8o (Connection ESP8266 with Server OPC-UEA Iconics – Kepware), Please can you help me?

    • PDAControl says:

      Excellent, I tested the ESP8266 with Modbus Maestro simulators without any complications.
      Which OPC server do you use?
      Have you connected your opc server with other modbus TCP / IP devices?

      You must have the ip address of the ESP8266 and normally configure your OPC server, either Keepserver Iconics matrikon etc …


Leave a Reply