Computing stuff tied to the physical world

Writing code for the Tinker Pico

The final step is what it’s all about: writing software for the LPC824 µC on the Tinker Pico. For this, we’ll need a compiler “toolchain” and some runtime code to handle the basics.

For the compiler toolchain, this will depend on which operating system you’re using. On recent versions of Linux Ubuntu (any platform), installing a toolchain can be as simple as:

    [sudo] apt-get install gcc-arm-none-eabi

For Windows and Mac OSX, there is the GCC ARM Embedded site, maintained by ARM, with regularly updated versions of the toolchain for all the major platforms. This older article should get you going (note that the latest gcc release is now 4.9.3, not 4.8.4). If you prefer Eclipse and are using Windows, then there’s an excellent article series by @SevenW.

And lastly, we need some runtime code. For now, we’ll use the code developed for the Embello project earlier this year. To get the Embello code, you need to have git installed:

    git clone https://git.jeelabs.org/jcw/embello.git

Ok – finally – it’s time to upload our first code. Here’s what we need to blink an LED:

#include "embello.h"

Pin<13> led;

int main () {
  tick.init(1000);
  led.setOutput();

  while (true) {
    led.toggle();
    tick.delay(500);
  }
}

You can probably guess the meaning of most of these lines. The “tick” object is pre-defined in Embello, with tick.init(1000) specifying a clock running at 1000 Hz, 1 ms/count.

The Pin<13> notation uses C++ templates. The “13” value acts as parameter which alters the type and definition of the “led” variable. It’s more efficient than run-time parameters.

The LED has to be connected as shown in the previous article: a 1 kΩ resistor between pin 3 (GPIO 13) and the long lead of the LED, and the other side of the LED tied to ground.

Here is a sample build + upload run, started by typing make in the proper location:

$ cd embello/explore/1541-tinker/blink
$ make
mkdir -p build/obj
arm-none-eabi-g++ -mthumb -mcpu=cortex-m0plus [etc...]
arm-none-eabi-size build/firmware.elf
   text    data     bss     dec     hex filename
    392       0       8     400     190 build/firmware.elf
uploader  /dev/tty.usbserial-* build/firmware.bin
found: 8242 - LPC824: 32 KB flash, 8 KB RAM, TSSOP20
hwuid: 07200207679C61AE4377A053850200F5
flash: 01C0 done, 392 bytes

That’s it – the LED should be blinking now.

Note that the USB port was found automatically since there was only one. To force make to upload to a specific USB port, you can type something like this before typing “make”:

    export TTY=/dev/ttyUSB0

Here is a second demo, sending messages to the serial port:

#include "embello.h"

int main () {
  tick.init(1000);
  serial.init(115200);
  printf("[hello]\n");

  while (true) {
    tick.delay(500);
    printf("%u\n", tick.millis);
  }
}

The “serial” object is pre-defined in Embello, it can be used for interrupt-driven serial I/O. This example is also included in the Embello project:

$ cd embello/explore/1541-tinker/hello
$ make
mkdir -p build/obj
arm-none-eabi-g++ -mthumb -mcpu=cortex-m0plus [etc...]
arm-none-eabi-size build/firmware.elf
   text    data     bss     dec     hex filename
   1528       4       8    1540     604 build/firmware.elf
uploader -s /dev/tty.usbserial-* build/firmware.bin
found: 8242 - LPC824: 32 KB flash, 8 KB RAM, TSSOP20
hwuid: 07200207679C61AE4377A053850200F5
flash: 0600 done, 1532 bytes
entering terminal mode, press <ESC> to quit:

[hello]
500
1000
1500
<esc>

If you don’t have a working compiler toolchain installed just yet, you can still try these out, because the binary build results are included in Embello on GitHub. For the blink demo:

    cd embello/explore/1541-tinker/blink
    uploader /dev/tty.usbserial-* build/firmware.bin

And likewise, for the hello serial demo (note the extra “-s” argument to uploader):

    cd embello/explore/1541-tinker/hello
    uploader -s /dev/tty.usbserial-* build/firmware.bin

That’s it for now. While these trivial examples won’t be that exciting, they do serve as good baseline tests to make sure everything is working – the compiler toolchain, the upload tool, the FTDI hookup, and of course the Tinker Pico board itself.

[Back to article index]