Access the general purpose input/output ports of your raspberry pi in Ada.
This is a binding to the BCM2835 C library. Install that as follows:
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.68.tar.gz
tar zxvf bcm2835-1.68.tar.gz
cd bcm2835-1.68/
./configure
make
sudo make check
sudo make install
You could import the code using traditional methods, such as by git submodule, but alire is better:
alr init raspberry_example --bin
cd raspberry_example
alr with raspberry_bsp
Modify src/raspberry_example.adb, for example:
with Ada.Text_IO;
with Raspio.GPIO;
procedure Raspberry_Example is
use Raspio.GPIO;
begin
Raspio.Initialize;
declare
Button : constant Raspio.GPIO.Pin_Type :=
Raspio.GPIO.Create
(Pin_ID => GPIO_P1_07, Mode => Input,
Internal_Resistor => Pull_Down);
begin
loop
if Raspio.GPIO.Read (Button) = On then
Ada.Text_IO.Put_Line ("Ow!");
end if;
end loop;
end;
end Raspberry_Example;
If like me, you have trouble getting gprbuild and alire working on the raspberry pi,
you can also just use gnatmake directly. The example program above is also included,
as src/ow.adb. So if you have gnat installed (sudo apt install gnat
) then you can just:
make
./ow
And connect a button to GPIO pin 7.
To autogenerate C bindings in the same way as this library, you can follow these instructions.
If you found a C program which you want to re-implement in Ada, first find the header locations with:
gcc -H -fsyntax-only test.c
And then feed those in to the g++ binding generator program like this:
g++ -c -fdump-ada-spec -C /usr/local/include/bcm2835.h