-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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).
- Installing dependancies.
sudo apt-get install -y autoconf libtool
- Clone libmodbus master branch by,
git clone https://github.com/stephane/libmodbus/
- Enter the directory.
cd libmodbus
-
./autogen.sh && ./configure --prefix=/usr && make && sudo make install
-
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)