Raspberry PI3 — Setup Modbus Connection (RS232 to TTL — UART)

Raspberry PI3 — Modbus connection (RS232 to TTL — UART) 2023In this guide, I will show you how to set up your raspberry PI3 to communicate with Modbus through the TTL serial port (and the RS232 communication module)By default, on a new Raspberry Pi IOS…


This content originally appeared on Level Up Coding - Medium and was authored by Fabio Chiarani

Raspberry PI3 — Modbus connection (RS232 to TTL — UART) 2023

In this guide, I will show you how to set up your raspberry PI3 to communicate with Modbus through the TTL serial port (and the RS232 communication module)

By default, on a new Raspberry Pi IOS installation, UART0 (asynchronous serial communication protocol) is reserved for the “Logon Shell”.

To use UART0 for other applications, you need to turn-off that connection to the Logon Shell through the native configuration. So, in the terminal of your raspberry enter:

  • sudo raspi-config

Choose interfacing options, select serial, and answer:

  • NO to “Would you like a login shell to be accessible over the serial?”

and

  • YES to “Would you like the serial port hardware to be enabled?”

select finish then reboot with sudo shutdown -r now

Now there is one more step to complete the configuration. After the device starts up, edit the file config.txt, using the shell command:

  • sudo nano /boot/config.txt

Add these two lines at the bottom of the file:

enable_uart=1

dtoverlay=disable-bt

Double-check your spelling, then SAVE the file as you EXIT.

Then, the second file you need to edit is the file cmdline.txt , so with the command:

  • sudo nano /boot/cmdline.txt

which it should look like this:

console=tty1 root=PARTUUID=ede33e1e-02 rootfstype=ext4 fsck.repair=yes rootwait

you should remove console=/dev/ttyAMA0,115200if present.

Double-check your spelling, then SAVE the file as you EXIT. Then reboot with sudo shutdown -r now

At this point, you should be good to go. You can read data from dev/serial0 port!!

if you got permissions error try: sudo usermod -a -G tty pi

To connect the Raspberry to Modbus I used a MAX3232 RS232 to TTL converter found on Amazon for about ten euros.

Before starting wiring be sure to know where to connect the pin! In the Raspberry PI3 the UART pinout are the GPIO14 and GPIO15 . Please always double-check the official documentation and datasheet for the correctness of your wiring on your hardware!

Raspberry PI3 documentation UART pin
RS232 to TTL wiring
Raspberry GPIO wiring

At a high level, this is an outline of how I successively handled the data obtained:

As a library for reading the serial port on the raspberry, I used modbus-serial (nodejs). There are other good alternatives such as py-modbus, or handling the communication in C.

The port used for communication is the /dev/serial0 !

If you like my article, please don’t forget to click 👏👏👏 to recommend it to others 👏👏👏.

Feel free to ask questions, make comments, or propose a better solution. Don’t forget to follow me on Twitter and GitHub!


Raspberry PI3 — Setup Modbus Connection (RS232 to TTL — UART) was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding - Medium and was authored by Fabio Chiarani


Print Share Comment Cite Upload Translate Updates
APA

Fabio Chiarani | Sciencx (2023-02-21T16:17:33+00:00) Raspberry PI3 — Setup Modbus Connection (RS232 to TTL — UART). Retrieved from https://www.scien.cx/2023/02/21/raspberry-pi3-setup-modbus-connection-rs232-to-ttl-uart/

MLA
" » Raspberry PI3 — Setup Modbus Connection (RS232 to TTL — UART)." Fabio Chiarani | Sciencx - Tuesday February 21, 2023, https://www.scien.cx/2023/02/21/raspberry-pi3-setup-modbus-connection-rs232-to-ttl-uart/
HARVARD
Fabio Chiarani | Sciencx Tuesday February 21, 2023 » Raspberry PI3 — Setup Modbus Connection (RS232 to TTL — UART)., viewed ,<https://www.scien.cx/2023/02/21/raspberry-pi3-setup-modbus-connection-rs232-to-ttl-uart/>
VANCOUVER
Fabio Chiarani | Sciencx - » Raspberry PI3 — Setup Modbus Connection (RS232 to TTL — UART). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/02/21/raspberry-pi3-setup-modbus-connection-rs232-to-ttl-uart/
CHICAGO
" » Raspberry PI3 — Setup Modbus Connection (RS232 to TTL — UART)." Fabio Chiarani | Sciencx - Accessed . https://www.scien.cx/2023/02/21/raspberry-pi3-setup-modbus-connection-rs232-to-ttl-uart/
IEEE
" » Raspberry PI3 — Setup Modbus Connection (RS232 to TTL — UART)." Fabio Chiarani | Sciencx [Online]. Available: https://www.scien.cx/2023/02/21/raspberry-pi3-setup-modbus-connection-rs232-to-ttl-uart/. [Accessed: ]
rf:citation
» Raspberry PI3 — Setup Modbus Connection (RS232 to TTL — UART) | Fabio Chiarani | Sciencx | https://www.scien.cx/2023/02/21/raspberry-pi3-setup-modbus-connection-rs232-to-ttl-uart/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.