woensdag 4 november 2009

Electronic component: The PICAXE

For our project we are going to use a PICAXE, today we are going to learn what the PICAXE is and how to program it. This we will be doing by building a circuit which is sending out an SOS signal in Morse code.

The PIXAXE is a PIC. IC stands for integrated circuit, as we already have learned. PIC stands for programmable integrated circuit. This means that you can write code and upload it onto the chip. Based on input you can set a different output.

For the project I've used an PICAXE 18X, but there are many different types of PICAXE chips. Also different PICs exist, for example the Atmel chips which we will meet later on.

As we are about to program a PIXAXE, we do require some items. I bought them at SparkFun, which seem to be nice guys. For today's circuit, this is what we need:
1 x PICAXE 18X (Some other PICAXEs will be ok too, but you are on your own ;))
1 x PICAXE Serial programmer cable


1 x PICAXE Bread board adapter (instead you might want to get the PICAXE 18 pin power project board, but I found this to be more flexible, although you will have to solder it)


1 x USBtoRS232 converter, as my PC doesn't have a serial port.
 
1 x USB connector cable
 
1 x 9V battery
1 x 4,7 kOhm (I used 2 x 2.2 kOhm + 1 x 330 Ohm in series, as I didn't have one)
1 x green LED

Well, that's about it. Here is the circuit we are going to build:


To imitate the PICAXE Bread board adapter, I've used three signal input symbols. It's pretty straightforward I guess. Note that this is the actual pin layout for the PICAXE 18X:


Ok, once you have connected everything, including the serial and USB cable, we can start programming the PICAXE. As I use Linux I'll be using AXEpad, which is really easy to use. For Windows you will probably have to set up some drivers and download another program. The code for the PICAXE will be the same anyway, so here we go:

main: ' start here
    gosub short ' jump to short
    gosub short ' jump to short
    gosub short ' jump to short
    pause 200 ' wait 200 msec
    gosub long ' jump to long
    gosub long ' jump to long
    gosub long ' jump to long
    pause 200 ' wait 200 msec
    gosub short ' jump to short
    gosub short ' jump to short
    gosub short ' jump to short        
    pause 3000 ' wait 3 sec
    goto main ' jump back to main

short: 
    high 4   ' Set output 4 to ON     

   pause 100 ' wait 100 msec
    low 4   ' Set output 4 to OFF
    pause 100 ' wait 100 msec
    return  ' Jump back to main
     
long:
    high 4  ' Set output 4 to ON
    pause 300 ' wait 300 msec     

    low 4  ' Set output 4 to OFF
    pause 300 ' wait 300 msec
    return  ' Jump back to main


The code is pretty human readable. It looks a bit like BASIC. Just put the code in the editor and upload it the PICAXE. If everything goes OK, you will be seeing a LED that's blinking short-short-shot-long-long-long-short-short-short.

That's it for now. Till next time.

2 opmerkingen: