Sunday 26 May 2013

7. Making the Cube Work - Using a PICAXE chip to control the cube

Continuing our story of our 8x8x8 LED cube, having made it you now have two choices:
  • You can run it automatically from the pre-programmed ATmega module (the one with the jumper on the 2-pin header and the chip marked MEGA328P) or...
  • You can run it 'manually' either from your PC or from your own microcontroller using the other ATmega module via a cable.
Running it automatically doesn't take any thought so I won't cover it here.  This section is about programming it yourself.

The 'Serial' Module
If you insert the serial module and power up the cube then all the LEDs should light up.  This is a useful way to test that all your LEDs are working.

Switching on the power with the 'Serial' module inserted

If you wish you can connect the cube to a PC via the supplied USB lead (having installed the USB drivers) and then run the 3D8S_Alpha software to control it.  The USB lead can normally provide sufficient power so you don't need to worry about a separate power lead.

The UART
The PCB has a connector called P2 which is a TTL UART interface - that is to say that it can accept serial communication similar to (but not the same as) standard RS232.

(If you want to run your board from a standard RS232 device (like an old PC) then you will need a 'level shifter' (like this) to convert from RS232 to TTL.)

The UART is ideal for connecting to development boards/kits like Arduino and PICAXE.  We use PICAXE, a system that is programmed in the BASIC programming language so that's what we will discuss here.


There are lots of different ways to use one of the range of PICAXE chips to control the cube.  We happened to have a 'Picaxe Experimenter Board' lying around so we decided to use that.  The board is designed to accept 14, 18 and 28-pin chips - we decided to use a PICAXE '28X1' chip although almost any of them would work.

As you can see from the picture above, connecting it up was not very complicated!  The connections required were:
  • 5 volts power to the PICAXE board
  • 5 volts power to the cube (it's not shown in the picture but they are actually running off the same supply)
  • A connection from ground on the PICAXE board to the ground pin of the UART (on connector P2 on the cube's PCB) - just to be safe.
  • A connection from 'IN6' on the PICAXE chip to the SERIN pin on P2.  (IN6 happens to be the pin on this particular PICAXE chip that has the high speed serial comms out.  We need to be able to send the data at 57600 baud.
 Programming the PICAXE Chip
We found that the best way to program the PICAXE chip was to use 64 bytes of the 'scratchpad' memory area to store what we wanted to appear on the cube.  We then wrote a little subroutine to send these memory locations to the cube via the high speed serial port.

Here is our first program.  I puts zeroes into all the 64 memory locations and then sends these to the cube, i.e. it switches all the LEDs off:


I'm please to say that this works fine.  We'll try to add some more of our code over the next few days.


1 comment:

  1. on my board there is no label for p2 could you explane where it is and what the pins are 1234, thanks craig

    ReplyDelete