I found this very useful. I was trying to get the ESP8266 to work with a MAX485 in Esphome, and the remote device was never responding. I purchased one of the logic analyzers you used for checking the serial protocol, and I found that as well as the modbus serial data being sent to the MAX485, the debug log was also sent to the serial port - this was even though I wasn't using serial to view the log, and I was applying OTA updates. I have spent weeks trying different things and testing , and the logic analyser identified this in a few minutes. Well worth the £10. the MAX485 is now working across the other uart on GPIO13 and GPIO15
Hi ! good to see your video! I was seeing for a material to understand ESP-32 and MODBUS and it's nice to find it to not reinvent the well and lost a lot of time.Thanks
Great video, I'm going to add the CRC check and ModBus error code checking. Most devices run at 9,600 / 19,200 / 38,400 baud over ModBus. A lot of slave devices also need a "quiet time", that is a delay between polls of 5 /10 / 20mS.
Great video! However everyone should keep in mind that the 120 microseconds might work with a baudrate of 115200 (or whatever that was) but we'd need much more with 9600 baud. It would be awesome if we could just wait until the buffer is flushed...
Modicon plc had developed in 1979 modbus and it is still used a lot. now to read modbus RS485 registers and go thru an esp32 bluetooth to a smart cell-phone like remotexy? thanks 🥳 yes, this is very useful when using so many esp32 spinoff pcb modules with home IOT and industrial PLCs 😊
I've gone crazy with that for a month at work, my buffer is a ADM2582E and it happens the same thing because i designed with a 10k resistor pull up in A and pull down in B 10k is too much high and sometimes modbus signal for long distances go down below 5V, so pull down and pull up R is seen by buffer as an open circuit, then buffer force the pin randomly up or down, so the solution is a 5K resistor for me instead of 10K,put like you did. Seems a common problem for modbus communication buffers
This is very useful, thank you for sharing it. Have you considered doing the same video using the rp2040. I assume that the rp2040 would be faster than the esp32. Is there an alternative to using blocking code for the delay.
Hi, I can't remember how the ESP32 works, but more often than not, there are ways around blocking. I did a project a few days ago where I could peek into the buffer to see how many bytes were in it before trying to read. This would completely stop the block as you wouldn't read if you know that nothing is there.
Hi Antony, I have been struggling for quite sometime with the modbus.. This solution could work for me, but I am not sure how you have arrived at the CRC. I am getting so many solutions or CRC, have tried multiple algorithms but unable to get what you are getting which is 126 for MSB and 244 for LSB. which polynomial has been used? I have tried A001 and 8005
Reason for the problem is straight forward and has nothing to do with a particular microcontroller, in this case ESP32. Transmission of data bytes to the RS485 Modbus is done by separate UART hardware on the microcontroller. When you write a byte to a serial port, you transfer this byte from microcontroller to the UART transceiver inside the ESP32. UART transceiver will then transmit this byte out to the RS485 modbus transceiver during the certain time period dependent on the baudrate. So, if you look at the last byte that you transfer to UART transceiver and then immediately follow with changing the mdDeRE pin LOW. UART transceiver will take longer to actually transmit that complete byte to RS485 transceiver than what it takes to set mdDeRe pin low. Or if you can imagine it in another simplistic way as a bit time. To change mdDeRe pin takes 1 bit-time. To Transmit one data byte takes 8 bit-times (as 1 byte=8 bits). Obviously there is some other detailed timing involved in the whole internal data processing. But hopefully you can see why mdDeRe pin goes low before the last byte if fully transmitted.
hi, I am trying to send data from pro mini to esp 32 but esp32 is not getting any data,showing response timed out. if i put uno instead of esp32 its working fine.
I havent found any one doing such communication so i wanted to try it with two different micro controllers communicating via modbus.Thanks for your response,still iam trying on it if you can suggest any help regarding this ,thanks in advance.
The Arduino Pro Mini will work with Modbus Master but the ESP32 won't work with any known library. The only solution which I know is my one. If it is not working, you need to know why it's not working. Do you have a logic analyser? You're going to need one!
I found this very useful. I was trying to get the ESP8266 to work with a MAX485 in Esphome, and the remote device was never responding. I purchased one of the logic analyzers you used for checking the serial protocol, and I found that as well as the modbus serial data being sent to the MAX485, the debug log was also sent to the serial port - this was even though I wasn't using serial to view the log, and I was applying OTA updates. I have spent weeks trying different things and testing , and the logic analyser identified this in a few minutes. Well worth the £10. the MAX485 is now working across the other uart on GPIO13 and GPIO15
I'm seeing a similar problem. Thanks for commenting on this.
Hi ! good to see your video! I was seeing for a material to understand ESP-32 and MODBUS and it's nice to find it to not reinvent the well and lost a lot of time.Thanks
Great video, I'm going to add the CRC check and ModBus error code checking. Most devices run at 9,600 / 19,200 / 38,400 baud over ModBus. A lot of slave devices also need a "quiet time", that is a delay between polls of 5 /10 / 20mS.
Great video! However everyone should keep in mind that the 120 microseconds might work with a baudrate of 115200 (or whatever that was) but we'd need much more with 9600 baud.
It would be awesome if we could just wait until the buffer is flushed...
Thanks Antony. I learned alot from this video and part 2.
Modicon plc had developed in 1979 modbus and it is still used a lot. now to read modbus RS485 registers and go thru an esp32 bluetooth to a smart cell-phone like remotexy? thanks 🥳
yes, this is very useful when using so many esp32 spinoff pcb modules with home IOT and industrial PLCs 😊
I've gone crazy with that for a month at work, my buffer is a ADM2582E and it happens the same thing because i designed with a 10k resistor pull up in A and pull down in B 10k is too much high and sometimes modbus signal for long distances go down below 5V, so pull down and pull up R is seen by buffer as an open circuit, then buffer force the pin randomly up or down, so the solution is a 5K resistor for me instead of 10K,put like you did.
Seems a common problem for modbus communication buffers
Hi Anthony! Tks for sharing your solution.
Do you got any issues with parity bits and start/stop bits over the ModBus communication line?
This is very useful, thank you for sharing it.
Have you considered doing the same video using the rp2040. I assume that the rp2040 would be faster than the esp32.
Is there an alternative to using blocking code for the delay.
Hi, I can't remember how the ESP32 works, but more often than not, there are ways around blocking. I did a project a few days ago where I could peek into the buffer to see how many bytes were in it before trying to read. This would completely stop the block as you wouldn't read if you know that nothing is there.
Anthony, how do I read the values received? Thank you
The way you put the terminating resistor it is not Ground to A it is VCC to A
Thank you for the solution!
Question since your saying 2 times differently. The 680Ohm from vcc (5v) to A? BR
Any idea how to make ESP32 or Arduino as a Slave and recieve data from Modbus RTU over RS485?
Hi Antony, I have been struggling for quite sometime with the modbus.. This solution could work for me, but I am not sure how you have arrived at the CRC. I am getting so many solutions or CRC, have tried multiple algorithms but unable to get what you are getting which is 126 for MSB and 244 for LSB.
which polynomial has been used? I have tried A001 and 8005
Do you have Part 3 of "How to make MODBUS work with ESP32 - Arduino - RS485 "
hi can you make something how to get data on a mod address.. like how NPK sensor work.
Excellent project
Thanks! :-)
Reason for the problem is straight forward and has nothing to do with a particular microcontroller, in this case ESP32.
Transmission of data bytes to the RS485 Modbus is done by separate UART hardware on the microcontroller.
When you write a byte to a serial port, you transfer this byte from microcontroller to the UART transceiver inside the ESP32.
UART transceiver will then transmit this byte out to the RS485 modbus transceiver during the certain time period dependent on the baudrate.
So, if you look at the last byte that you transfer to UART transceiver and then immediately follow with changing the mdDeRE pin LOW.
UART transceiver will take longer to actually transmit that complete byte to RS485 transceiver than what it takes to set mdDeRe pin low.
Or if you can imagine it in another simplistic way as a bit time.
To change mdDeRe pin takes 1 bit-time.
To Transmit one data byte takes 8 bit-times (as 1 byte=8 bits).
Obviously there is some other detailed timing involved in the whole internal data processing.
But hopefully you can see why mdDeRe pin goes low before the last byte if fully transmitted.
Yes, that's what this video is about. :-)
Thanks for the explication.
Why don't you carry on using the library for everything else and just hook your de and re to another pin which you digitally write?
Nice work!
Hi can this be done with schnider energy meter to read holding register with esp mcu
Hi, what is the command to read contents of a RS485 register? Thanks
it should be better if you provide wiring diagram instead of pointing the wire
Interesting, thanks. Audio is a bit choppy though
Thanks, I'll have to look into it. It seems to be the screen recoridng software. :-(
Thanks so much !!
can i use board rate 500000 bps ?
Hi can you provide this code
will this code work with Nodmcu 8266
Either it does or it doesnt
Thx
hi, I am trying to send data from pro mini to esp 32 but esp32 is not getting any data,showing response timed out. if i put uno instead of esp32 its working fine.
Why would you send data from APM to ESP32 via Modbus?
I havent found any one doing such communication so i wanted to try it with two different micro controllers communicating via modbus.Thanks for your response,still iam trying on it if you can suggest any help regarding this ,thanks in advance.
Hi, it is possible, but it's hard work. It does work though just like in my video...
I have used your method of working and also traditional method like modbus master library and modbus library for slave its not working
The Arduino Pro Mini will work with Modbus Master but the ESP32 won't work with any known library. The only solution which I know is my one. If it is not working, you need to know why it's not working. Do you have a logic analyser? You're going to need one!
maybe you should fix your audio first ! Very annoying !