Modbus RTU Slave for ESP8266 ESP32 with Home Assistant control example. 'Client'

Опубликовано: 26 Май 2026
на канале: Progs Pont
9,336
107

There are countless tutorials on how to configure Arduino or ESP devices as a Modbus RTU Master, probably because the most common application is to collect data from commercial devices such as energy meters, solar inverters or other industrial devices that are slaves. One of these tutorials for Home Assistant in ESP is on our channel:
   • Modbus RTU to Home Assistant  with TTL to ...  
This video shows the physical assembly of the hardware.

But if we want to configure one as a slave, either to communicate in an area where our WIFI does not reach, to do tests or simulations. Even by connecting the master to the device on which Home Assistant runs, an installation could be done without WIFI with only RS485 and Modbus protocol.

We have done the slave project with the Arduino IDE. There are several "Mosbus RTU Slave" libraries for Arduino IDE but after doing countless tests with most of them we cannot communicate either because they do not support ESP or because they are old and give errors, in the end after searching a lot on the internet we have found the following library:
smarmengol/Modbus-Master-Slave-for-Arduino https://github.com/smarmengol/Modbus-...
With which we have been able to communicate perfectly.
(Curiosity: searching for bookstores all over the Internet, the author of this one has the location 90 km from ours.)

As we have been doing until now, we have implemented it in an ESP01_Relay that consists of a card with the ESP8266 microprocessor, a 3.3V voltage regulator and a relay.
Although we could use any ESP8266 or ESP32 card.
The card has 4 configurable input or output pins but GPIO0 controls the relay, GPIO1 and GPIO3 are used for TTL communication with the RS485 card, only GPIO2 is free, in which we will connect a DS18B20 temperature sensor.

The 2 most common types of cards for RS485 communication are: The "MAX485 TTL" and the "TTL to RS485 485 to Serial UART"
We use the second one, because the MAX485 needs an extra pin for the Driver Input signal.

Code to paste into Arduino IDE
https://drive.google.com/file/d/1ood2...

Code to paste into ESPHome from Home Assistant
https://drive.google.com/file/d/1t0hu...

Below we leave the link to the 3D support:
https://www.thingiverse.com/thing:620...

"Home assistant" "tutorial" "ESP8266" "ESP01" "Relay" "ESPHome" "esp32" "DS18B20" "dallas" "Modbus" "RTU" "Modbus slave" "Slave" "Arduino IDE" "RS485" "Thermostat" "Host" "Client" #host #client #modbusrtu #slave