Introducing Pasduino, the Pascal AVR Arduino library

Writing Pascal applications for an Arduino is simple, but doing everything on your own is less then ideal. Pasduino to the rescue!

Arduino board with some sensors

It has been a while since my prior post. There were elections in the Netherlands, which always take much of my time as a volunteer for a political party. But even politicians need to relax sometimes, so in a spare moment I decided to find out how difficult it would be to develop the software for my AVR-based Arduino boards using Freepascal.

That was easier then I thought. But as soon as I wanted to do something real, like turning on a LED or sleep for a while… things were way more complicated than I was used to in the Arduino IDE.

Then I found the original sources of the Arduino-AVR libraries, and even a site that explains in detail how it all works. So I decided to try if it would be difficult to port all this to Freepascal.

Hardest part was to figure out how deal with the different Arduino boards. The original Arduino software differentiates between the processor type and variants. The variants define how the board is wired and which features it has.

At the moment only the standard (Uno) and Leonardo variants are supported, as these are the only ones I am using right now.

My attempt led to a new FreePascal AVR-Arduino librarry called Pasduino. Using it, the famous blink-example looks like this:

program Blink;

{$mode objfpc}


  // Set internal LED to output.
  PinMode(LED_Builtin, Output);

  while True do
    // Turn OFF internal LED.
    DigitalWrite(LED_Builtin, Low);
    // Wait for a second

    // Turn ON internal LED.
    DigitalWrite(LED_Builtin, High);
    // Wait for 5 seconds

I’ve build a few applications using Pasduino for my home-automation system. It works quite well. At first I had difficulties with the memory usage, but as soon I discovered that dynamic constant arrays use more memory then static arrays, and that enums by default use 4 bytes of memory (solution: {$PACKENUM 1}) all problems where gone. But it still shows that the quality of the AVR-assembly generated by Freepascal is far from ideal. Which makes it more difficult to write more complex stuff.

But in the end things will only become better when we join forces so I hope Pasduino is useful to others, and as always, help and patches are welcome.