Sunday, 7 October 2012

sending dynamic text from the Pi to the LoL Shield via Gertboard

Getting fixed scrolling text on the LoL Shield from the uploaded arduino program is one thing (see previous posting), but we really want to get the text delivered into the program dynamically. This is where the serial GPIOs on the Pi can help out.

I wrote a small arduino program to read characters from the serial port and display them on the LoL Shield. Note that I had to edit the Charlieplex.cpp file from the LoLShield library to remove a (apparently unused) Serial.end() call. Line 373 on my copy.

Once the program is uploaded to your ATmega on the Gertboard, you can deliver text via serial on the Pi using any method you like, e.g. interactively via one of:

  • minicom ama0
  • screen /dev/ttyAMA0 9600
(Press return to tell the program you've finished entering your characters.)

Alternatively, you can send your text programmatically via a python, C, bash script by writing to the /dev/ttyAMA0 device, e.g.:

  • $ echo 'weeee!' > /dev/ttyAMA0 
Remember, when sending/receiving serial data between the Pi and the Gertboard's ATmega, you must connect the GP14-15 pins in J2 to the MCTX and MCRX pins just above them.

// displays text sent via serial e.g.
// echo 'weeee!' > /dev/ttyAMA0
#include "Charliplexing.h"
#include "Myfont.h"
#include "Arduino.h"

unsigned char buffer[140];
int c;
int i = 0;
int len;

void setup() {

void doMsg() {
    Myfont::Banner(len, buffer);

void loop() {
    if(Serial.available()) {
        int c =;
        if(c != -1) {
            if(c == '\n' || c == '\r') {
                buffer[i] = '\0';
                len = i;
                i = 0;
            } else {
                buffer[i++] = c;
    } else {
        if(len > 0) {

No comments:

Post a Comment