Wednesday, February 3, 2016

Codesys Pi Modbus Client polling a Modbus Server in an ESP8266 Huzzah

I've had a couple of these Adafruit ESP8266 Huzzahs laying around, but I hadn't had the time to mess with them.

I took the time tonight, and I'm glad I did.

Using the Arduino IDE, I flashed a "sketch" onto the Huzzah, that not only gives me the ability to run Arduino libraries, but I found a Modbus Server library that works with it from here:

https://github.com/andresarmento/modbus-esp8266

It worked!  I was able to set up a Modbus client on the Codesys running on the Pi, and could poll a running counter coming in on register 0.

Adafruit ESP8266 Huzzah running Arduino sketch with Modbus server library
This may not be so useful with the robot, but is super useful for remote sensing duties.  I would like to try using this for a "smart" metal detecting coil array, that houses the electronics on the coil, and transmits via Modbus TCP to my PLC over Wifi.  Think smart house with central PLC controller and a mesh of sensors feeding data.

Heres a screenshot.  Note the latency difference in numbers... I can speed this up somewhat, but I will have to tweak it.

Codesys online displaying values from Huzzah connected over Wifi via Modbus TCP

3 comments:

Alejandro Cordero said...


James, my name is Alejandro. I am trying to connect a RASPBERRY PI through wifi by modbus TCP / IP, with a NODECPU ESP8266. How would you configure both devices, the idea is to use the ESP8266 as a remote IO of 5 readings and 5 outputs.
From already thank you very much!

Alejandro Cordero said...

Sorry Rapberry PI whit Codesys!!

James Belcher said...

Sorry, just saw this. Go to my github repository here

https://github.com/fixstuff/MDRobot

I have a project there with codesys on the pi, and i2c on a Teensy. Ill add the sourve code for the huzzah if its nit on that.