Getting the Raspberry Pi to 'Talk' to the Hardware Port Under RISC OS

(© Richard Ashbery - 2015)


This article enables a complete beginner to use their Raspberry Pi to control a sequence of LEDs. No soldering is required. Simply plug the board into the GPI/O Hardware port of the Raspberry Pi, switch on and run a GPI/O module in conjunction with a simple BASIC program to control them.

The Hardware

A small electronics company in Nottingham called Ciseco supply a range of project hardware compatible with the Raspberry Pi. Most projects are built to operate using Python under Wheezy Raspbian so converting them to RISC OS would require a lot of work and programming knowledge. However there is a simple LED board consisting of 8 LEDs that will work. The tutorial has been tested on Raspberry Pi, model B.

Purchase the LED board (Pi-LITEr) for £2.50 from...

The Software

To get the LEDs to do something all we need is Tank's powerful GPIO module and a small BASIC program.

Download Tank's GPI/O Module from...

After de-archiving the zip file double-click on the GPIO module. Typing Help GPIO in a TaskWindow will tell you if module is running. Unless you are familiar with Tank's utilities don't click anything else at this stage.

As it stands the module runs in the background not doing a lot so we have to run a small BASIC program to tell it what GPI/O lines on the Raspberry Pi are needing to be switched on and off.

BASIC Program

Download the program from my website...

After de-archiving run the program and check that LEDs cycle in sequence from D1 to D8 with the cycle repeating indefinitely.

RunningLEDs Program

The program can be divided into two sections.

1. Initialisation routine in lines 220-250. Line 220 checks the GPI/O module has been loaded by the OS and if not outputs a warning message. Lines 240 and 250 set the communication channel for the serial I2C* bus in the ARM processor setting all GPIO pins as outputs.

2. The GPI/O lines for each LED are contained in a DATA statement (line 280). These are read in turn into memory (line 70). Sequencer code (lines 120-170) place each GPI/O line into a SYS "GPIO_WriteData" command which tells the GPI/O module to turn the LED on. After a delay the LED is turned off before the procedure is repeated for the next LED in the series. This is repeated until the eighth GPIO line is set. A REPEAT-UNTIL FALSE loop (lines 110 and 180) ensures the sequence continues permanently unless user forces the sequence to end by pressing the Esc key.

Now you have run the program try modifying it to make the LEDs 'run' in the other direction by altering line 120 to FOR n%=8 To 1 STEP-1. Also try switching LED 1 on, then LED 2 and so on until all are on. A random LED sequence could also be tried.

The GPIO Module

There is StrongHelp file in the GPIO program suite. The introduction section contains examples in BASIC and ASSEMBLER of how the module is used to setup the GPIO lines via software interrupts (SWIs).

When you have run the RunningLEDs program above it is worth going through some of the examples to get an understanding of how the GPIO module works. It covers setting up pins as GPI/O, the pin output state (read or write) and the process of Reading a GPI/O pin and setting its value using a Write command.

Warning: as of 5/1/15 the Manual is missing. I've tried contacting the programmer to get this fixed. By the time you read this tutorial I hope that he has uploaded a copy that works.

Application to Set GPI/O Pins

There is also an application (!GPIOConfig) which enables GPI/O lines to be set into Input or Output mode (remember GPI/O lines are bi-directional). This is useful in that it can be used to test each GPI/O line by simply clicking on the relevant icons.

To display the GPI/O pins use the RISC OS application - Interactive Help.

GPIOConfig Application

*The I2C (I-squared-C) Bus

Only two bi-directional lines are required for the I2C, a Serial Data Line (SDA) operating with 7-bit addressing and a Serial Clock Line (SCL). The bus typically operates at 100kbits and operates in a master/slave capacity. Detailed operation of the bus is beyond the scope of this tutorial. Consult sources like Wikipedia for more information...


This project is an excellent way of getting to grips with some quite tricky concepts. Tanks module takes the difficulty in GPI/O addressing out of the equation. With a little knowledge of BASIC other devices potentially could be controlled all within a RISC OS environment. The alternative is to learn Wheezy Rasbian and then Python to perform the same operations. Having experienced the sluggish response of Linux based OS's I know which I prefer.