Skip to content

Libmodbus on Raspberry pi

Dhruv Vyas edited this page Sep 14, 2015 · 11 revisions

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

  1. Clone libmodbus master branch by,

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

  1. Enter the directory.

cd libmodbus

  1. ./autogen.sh && ./configure --prefix=/usr && make && sudo make install

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

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

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 conflict with libmodbus 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)

Clone this wiki locally