PICAXE on Ubuntu

August 16, 2013

The PICAXE is a programmable microcontroller. You'll need a special USB cable (http://spiratronics.com/product-39355.html) from your computer to program it, and the following circuit to test it. Supply it with clean 5v power, preferably supplied by a 7805 voltage regulator. The documentation states there should be a 100nF and a 100uF capacitor across the supply lines on both sides of the 7805.

PicAxeTest

Software

Install AXEpad on to your system. Run it by executing LinAXEpad.

Next, connect it to the circuit above using the USB cable and apply power. Click the Program button in AXEpad and it will try and upload a blank program to the PIC.

I got an error because /dev/ttyUSB0 didn't exist. This is because by default Ubuntu doesn't recognise the USB cable. Type this into a command shell:

$ sudo modprobe ftdi_sio vendor=0x0403 product=0xbd90

This will temporarily make the connection work - you will have to do this after each reboot. You should now have a ttyUSB0 in /dev. and the Program button should work.

To make this permanent, add the following in /etc/udev/rules.d/99-axe027.rules

# /etc/udev/rules.d/99-axe027.rules
# contains axe027 udev rules to patch default
# FTDI product id to AXE027 product id (0xbd90)

ATTR{idProduct}=="bd90", ATTR{idVendor}=="0403",RUN+="/sbin/modprobe -q ftdi_sio product=0xbd90 vendor=0x0403"

First Program

Type the following program into the editor and use Program to upload it to the PICAXE.

main:
  for b0 = 1 to 5
    high 1
    pause 200
    low 1
    pause 200
  next
  pause 1000
  goto main

This will make the LED connected to pin 6 flash on and off five times, and then repeat the same sequence again after a waiting a second.

Take care to use b0 for the varaible name. The PICAXE 08M has 16 bytes of variable storage, numbered from b0 to b15. These can also be addressed in two byte words using w0 to w7. Bytes can hold 0 to 255, words can hold 0 to 65535.

These variables are held in RAM, and are therefore lost when power is removed. The program itself is held in non volatile memory and so is retained across power cycles, even when the USB cable is disconnected.

PICAXE 08M2

Here is the pinout for the chip we're using, a PICAXE 08M2.

PicAxe08M2

Note that pin 6 is C.1 - this is the number 1 referred to from the code in high 1 and low 1. Our test circuit also has an LED on pin 5 - C.2 - we can control this using high 2 and low 2.

main:
  for b0 = 1 to 5
    high 1
    low 2
    pause 200
    low 1
    high 2
    pause 200
  next
  low 1
  low 2
  pause 2000
  goto main

References

Tags: pic picaxe axepad ubuntu