Raspberry pi notes : Libmodbus on Raspberry Pi

Raspberry Pi has gained popularity in recent days and a lot of enthusiasts / hobbyist would like to implement libmodbus on RPi to host a modbus master / slave. Here is “how to install libmodbus” guide on RPi (Raspbian).

1.Installing dependancies.

`sudo apt-get install -y autoconf libtool`

2. Clone libmodbus master branch by,

`git clone https://github.com/stephane/libmodbus/`

3. Enter the directory.

`cd libmodbus`

4. `./autogen.sh && ./configure –prefix=/usr && make && sudo make install`

5. To test the libmodbus, try examples under tests folder.

To compile code, use, gcc -o filename filename.c `pkg-config –libs –cflags lidmodbus`

Additional notes :

If you’re using linux distros (other than debian based), such as Arch Linux or PiDora, you must use relevant package manger options in step #1. (like pacman or yum)

In order to use native RPi serial port for RTU mode, you MUST disable serial console by using sudo raspi-config as it conflicts with modes RTU communication.

Native serial port is listed as ttyAMA0 under /dev/ directory.

If you’re using UART to RS485 chip like 75176 or anything similar, you would like to check the libmodbus raspberry pi fork which makes use of a GPIO to enable rx-tx. (Link : https://github.com/dhruvvyas90/libmodbus)

Leave a Reply

Your email address will not be published. Required fields are marked *