-
Notifications
You must be signed in to change notification settings - Fork 7
AgPi: Agents on Raspberry Pi
WiringPi is a C library which provides APIs to access the GPIO pins and other peripherals of Raspberry Pi. Thanks to the efforts of Midhul Verma and Nikhil Teja Alamanda, a WiringPi-Prolog wrapper was created as a part of the AgPi project. Through this wrapper, Tartarus agents can access the different peripherals of a Raspberry Pi, such as GPIO pins, PWM, I2C, etc.
WiringPi-Prolog wrapper source code is maintained here.
- Make sure the latest version of Raspbian OS (or any Debian based OS) is installed on Raspberry Pi. The OS can be downloaded from the following link.
- Install SWI-Prolog on the Raspberry Pi OS (as root user) using the command:
% sudo apt-get install swi-prolog
- Download/Copy the WiringPi-Prolog tar file (click here) onto the Raspberry Pi.
- Unzip the WiringPi-Prolog zip file using the command:
$ unzip <file_name>
- Check the swi-prolog installation directory. Generally the location is ‘/usr/lib/swi-prolog’. To confirm, use the following commands on the terminal:
$ swipl
?- file_search_path(swi, X).
- Copy the wipi folder from the unzipped folder (step 4) to the folder returned in step 5.
- Come out of the superuser (root) mode if still in it. You can do this by closing all the terminals which are currently running and then starting a new terminal.
- Go to your working directory (the folder where you will be working with your project files).
- Copy the ‘platform_pi.pl’ (provided here) file in this directory.
- Now start prolog with sudo permission (very important):
$ sudo swipl
- Consult the
platform_pi.pl
using:?- consult('platform_pi.pl').
This will load all of the Tartarus predicates. - Execute the command:
?- start_peripherals.
This will start the Peripheral Interface. Make sure no errors occur during this step. - Now the peripheral interface is ready, and you can use WiringPi-Prolog predicates to control the GPIO pins.
Below is the pin mapping between AgPi and Raspberry pins. The column wPi is the one which we use and its equivalent pin is under the column BCM. A physical hardware layout is also shown in the below figure.
Since AgPi is a wrapper over WiringPi, the commands used in WiringPi are same as in AgPi but just comes with a flavor of Prolog. The predicates available with AgPi are: