Computing stuff tied to the physical world

Using an LPC824 the Arduino way

Now that the basic compile-and-upload mechanism is working in the IDE for Tinker Pico boards, the next task is to get some basic runtime support. It’s all about adding files to the cores/lpc8xx folder, some of it copied over from other platforms, and some of it specific to the LPC8xx internal hardware registers. Here’s an Arduino.h file to get started:

    #ifndef Arduino_h
    #define Arduino_h

    #include <stdlib.h>
    #include <string.h>
    #include "WString.h"
    #include "HardwareSerial.h"

    const int INPUT = 0;
    const int OUTPUT = 1;

    const int LOW = 0;
    const int HIGH = 1;

    extern "C" {
        extern void setup ();
        extern void loop ();

        extern void pinMode (int pin, int mode);
        extern int digitalRead (int pin);
        extern void digitalWrite (int pin, int level);
        extern void delay (int ms);
        extern unsigned millis ();


And here is a first version of main.cpp with some very basic definitions:

    #include "Arduino.h"
    #include "LPC8xx.h"

    volatile unsigned msCounter;

    extern "C" void SysTick_Handler () {

    int main () {
        while (true)
        return 0;

    void pinMode (int pin, int mode) {
        if (mode == OUTPUT)
            LPC_GPIO_PORT->DIR0 |= 1<<pin;
            LPC_GPIO_PORT->DIR0 &= ~(1<<pin);

    int digitalRead (int pin) {
        return LPC_GPIO_PORT->B0[pin];

    void digitalWrite (int pin, int level) {
        LPC_GPIO_PORT->B0[pin] = level != 0;

    unsigned millis () {
        return msCounter;

    void delay (int ms) {
        unsigned start = msCounter;
        while (msCounter - start < ms)

These files are sufficient to build and run the very minimal 01.Basics => Blink demo included as part of the standard Arduino IDE, for example.

The above SysTick_Handler() code automatically gets linked into the LPC824 interrupt dispatch vector at the start of flash memory, simply by having the proper namemagic!

The serial port is another story, This requires some LPC8xx-specific code, obviously – but also a slew of Arduino-related (or rather Wiring-related, Arduino’s predecessor) classes and definitions, to support all the different Arduino Serial.print() functions.

A first serial implementation has been added, but this is just the start. To support “Wire” (Arduino’s I2C library wrapper) and “SPI” (Arduino’s SPI wrapper) will take more work. And then there is “analogRead” (ADC input), “analogWrite” (PWM output). These API’s have been based on fairly ad-hoc and old code in the ATmega implementation – the big challenge will be to bring all of the LPC824’s peripherals into this world in a flexible way.

[Back to article index]