Code Monkey home page Code Monkey logo

ada_raspio's Introduction

Raspberry Pi GPIO in Ada

Access the general purpose input/output ports of your raspberry pi in Ada.

Install BCM2835

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

Usage

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;

Using gnatmake

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.

Autogenerate C bindings

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.