Wednesday 13 May 2015

Picaxe Programming with Pi

You can write Picaxe programs, compile and download to the device using Windows or Linux x86/64.


And it is also possible to use a Raspberry Pi and a few cheap components to develop and load your programs to a Picaxe.


This brief post describes how.


The Picaxe & Pi combo


I've been playing around with an 08M2 Picaxe chip connected to a Raspberry Pi recently, but was getting a bit tired of removing the chip, putting the device in my programming board, editing and downloading from my laptop, and then re-fitting the Picaxe to my Pi connected breadboard in order to test it.

Wouldn't it be nice if it could all be done without removing the Picaxe?

Well it can!

Platform support


So the first problem is that a Pi is ARM based, not x86. But a clever guy/gal (known as fanoush) has come up with a solution which uses Qemu in "user mode", and was kind enough to post on the Picaxe forum.

Fortunately for me, another guy/gal (known as hippy) was kind enough to help me out, as I struggled to get this working. So this bit is 100% not my own work.

You can install the files you need by following hippy's instructions. In a terminal type each of these commands:-

wget http://fanoush.wz.cz/picaxe/picaxe-raspberrypi.tar.gz
wget http://www.picaxe.com/downloads/picaxe.tgz
tar -zxvf picaxe-raspberrypi.tar.gz
tar -zxvf picaxe.tgz -C ./picaxe/i386/compilers


To test that the compiler runs, navigate to: /home/pi/picaxe/bin
{I do this in the file manager, and then press F4 to open a terminal in the right directory}
...and then type:-

./picaxe08m2 -h

The response will start:-

ERROR: ld.so: object '/usr/lib/arm-linux-gnueabihf/libcofi_rpi.so' from /etc/ld.so.preload cannot be preloaded: ignored.

...but if it continues with...


PICAXE-08M2 Compiler
Version 3.1
Copyright (c) 1996-2014
Revolution Education Ltd


...followed by Help info, it is working!

Raspberry Pi serial port


As mentioned in this earlier post, if you want to use the Pi serial port (GPIO pins 8 and 10) you need to free it. So please make the two mods for ttyAMA0 as described in "Configuration".

Upspeak and Downspeak


Upspeak (also known as High Rising Terminal) is a protocol difficulty that old people like me encounter when opening a comms link with a young person (...or anyone from Australasia).

A more serious problem for my Picaxe to Pi comms link is that the Pi uses a Hi going Lo convention, while the Picaxe port is Lo going Hi. So we need a bit of hardware in between to invert the signals on the two comms lines.

The only suitable chip I had to hand was a ULN2003. So I stuck one on a small breadboard with a couple of resistors, a capacitor and a few fly-leads.

Sorry, I forgot to draw the 0.1uF capacitor (pins 1 to 8 of Picaxe)


The ULN2003 is quite a good choice for those that still don't believe that you can connect 5V devices to the Pi gpio. As the outputs are open-collector, you can disconnect R1 from 5V and reconnect to 3.3V.

Don't worry too much about the values for R1 & R2. Anything in the range 4k7 to 10k will be fine.

The magic command


In order to compile and download our Picaxe programs, we need to specify the compiler, the serial port and the name of our Picaxe source file.

So once again, navigate in file manager to:-

 /home/pi/picaxe/bin

...and then create and save your killer app (e.g. KillerApp.bas).

Now hit F4 from file manager, and in the new terminal that opens type:-

./picaxe08m2 -c/dev/ttyAMA0 KillerApp.bas

Note the rather unusual syntax; there is no space between -c and /dev

Barring any source code syntax errors, your code should compile and download.

All systems go!


This method was tested on a PiB+ and a PiB2 both running Raspian Jessie. There is no reason (...that I can think of) why is should not work on any Pi variant with Wheezy or Jessie, for any of the Picaxe/compiler devices.

So, start programming your Picaxe!

No comments:

Post a Comment