Tuesday, July 27, 2010

PICAXE - Who, what, where and how-to for Halloween Props

Just posted this over at GoE, thought I would put it up on my blog as well. Please provide any feedback you may have, thanks!


Who is the PICAXE for?

The PICAXE can be used by ANYONE wanting to have some type of electronic control of a display, prop or that haunted concoction of your wildest dreams… OK, maybe that THAT dream.

You don’t have to have a lot of experience with electronics to use it (although it will help if you do) and while you can get PICAXE starter kits that are completely built there will still be some simple soldering to connect inputs & outputs directly to the board or to solder connectors that you can then plug our inputs and outputs to (highly suggested).

The bottom line is that using this How-To you should have the knowledge to get started using a PICAXE to build some simple displays or props, or get started down the path to learning how to put together more complicated versions.

What is PICAXE?

OK, this next section is probably more ‘techy’ than necessary, so skip it if you really aren’t interested. You can always come back to it later.

The PICAXE chips are Integrated Circuits (IC’s) with a BASIC programming language pre-loaded. They can then be programmed using free programming tools (for both PC & Mac) to perform various tasks based on that programming. It’s kinda like having a really small computer that can do some specific thing or groups of things. The best examples I can think of are the electronic toys that can interact at some level with the environment around them, reacting to things that happen (being talked to or touched).

The PICAXE microcontrollers were created by Revolution Education out of the UK as a way to teach schoolchildren about electronics & programming. There are many other types of microcontrollers out there, but the focus of this how-to will be specifically on the PICAXE system of microcontrollers since it’s what I know and use. Simple enough… Blah, blah.

Which PICAXE to use

Well, that really depends on what you are planning to do with it. The number of inputs and outputs you will need drive you to the chip you should get. Honestly, it’s best to start small (and cheap) and since all the PICAXE chips use the same programming language/cable you can start with a small platform (with less inputs & outputs and memory) upgrade to something larger as your needs grow.

The simplest version has (08M) has a total of 4 ‘pins’, 3 can be either an input or an output while the 1 remaining can act only as an input. The 18 pin version has a total of 5 inputs and 8 outputs… And so on.

Here is a handy chart with some of the details for reference (taken from RevEd website)

PICAXE Type

IC Size

Memory

(lines)

I/O Pins

Outputs

Inputs

ADC

PICAXE-08M

8

80-220

5

1-4

1-4

3

PICAXE-18X

18

600-1800

14

9

5

3

PICAXE-20X2

20

1000-3200

18

1-17

1-17

0-9

PICAXE-28X1

28

1000-3200

23

9-17

0-12

0-4

So, figure out how many ways you want a particular display or prop triggered. This will give you the number of inputs you would need. How many things do you want to trigger, that’s how many outputs you need… That’s the simple explanation, once we get into the details of what exactly an input and an output is you will be able to better answer these questions for yourself.

Where to buy it

I’ll assume most everyone reading this is in the US and my purchasing advice will be based on that assumption.

I personally use Sparkfun.com, they have LOTS of other goodies (like sensors, motors, servos, etc) and getting it all at once/in one place can save on shipping & handling. Other options I am familiar with include phanderson.com, robotshop.com, hvwtech.com and solarbotics.com. You could also take the Google route.

Sparkfun doesn’t carry the whole PICAXE lineup but has the most of the popular kits & chips are. Other on-line sellers may have more options that you cannot find at Sparkfun to fit a unique need.

How much $$$

The cost of a PICAXE 08M (proto board, chip and battery pack) is under $10 (as of 07/2010), the PICAXE 18X is about $20 from Sparkfun.

If you don’t already have the USB Programming Cable, that’s the biggest initial cost at $26. The cable can be used for any of the chips, so as long as you don’t lose the cable you are good to go. The starter pack is a bit more ($15 for the 08M) and it includes a CD with all necessary programs & a battery holder.

You can get packs/kits/chips cheaper elsewhere, so if price is important shop around. Don’t forget about shipping charges either, it’s small stuff but it still costs a few dinero’s to get it delivered.

I’m not aware of any retail locations for PICAXE, but hobby shops with a focus on robotics may have some or be able to get some from their supplier. Doesn’t hurt to ask and supporting the local hobby shops is never a bad idea.

The Basics

I realize that some may still be scratching their heads, asking what is an ‘input’ and an ‘output’ and how do I know which is which… Let’s see if this helps. Honestly, the manual on the RevEd website goes into this stuff as well and I consider it a great first resource, you can find it here: http://www.rev-ed.co.uk/picaxe/

Go the ‘Datasheets’ tab and download Section 1 – Getting Started. It’s a PDF and it’s FREE. It’s a good idea to download at least the first 2, since I will reference them.

Input

As we haunters may know it, an input is the ‘trigger’ that sets off our prop or display. Perhaps it’s a proximity sensor which will trigger when anything in the area moves, or a light/dark sensor that will trigger when light appears or disappears on that sensor. Or sound or even a manual pushbutton. Below are some examples of each:

  1. Light/Dark – a photoresistor can detect an increase or decrease in existing or manufactured light levels, your program can use changes to trigger something.
  2. Proximity – a PIR (motion sensor) can detect when there is movement within an area (the area depends on the PIR on how you use it), your program can use changes to trigger something.
  3. Switches - a mat switch can detect when it’s stepped on, a manual switch can be pressed by you and yes… your program can use this to trigger something. There are other switches, but this is good enough for now.
  4. Sound - a microphone can detect a threshold of sound, like something talking, yelling, screaming or whatever… well, you know the rest.

Output

An output is what we haunters are trying to trigger. Again, lots of options but know that PICAXE boards cannot supply all the power to run motors, solenoids and whatnot all on there own. But, if you can light up an LED the rest will come.

  1. LED –Lot’s of options here, various sizes and colors. Pick the ones you want, take note of how much power they consume (Volts = V & milliamps = mA). Depending on how many you are using you can power them right from the board or supplemental power can be provided to light even more. A single pin max’s out at ~20mA, which is about the same amount as one LED. The max for the whole chip/board tops out at ~90mA across all pins. That means you’ll need an output pin to trigger a MOSFET or relay; which in turn will provide the juice to that which you are trying to trigger.
  2. Motor – Most, if not all motors will need more power than can be provided by the chip/board on it’s own. But if you can light a single LED then you can get a motor to run.
  3. Servo – Servo’s are generally really small motors built into a unit that can only move within a certain range, but with control. The motions of the servo can be easily controlled by the PICAXE chip to perform simple movements, many servos can represent a complicated set movements (like a 3-axis skull). The small to mid-sized servo’s can be powered right off the board, but the bigger ones will need help. We’ll stick with the small ones for now.
  4. Solenoid Valve – a solenoid valve can control the flow of air to an air cylinder, which in turn triggers the prop. There are numerous methods, first depending on the type of solenoid. You can usually get them in 12VDC, 24VDC and 110VAC, best to use a relay to trigger the solenoid, which triggers the air cylinder, which will trigger ToT’s to run (hopefully). Make sure the relay is compatible with both the board and the type of power being used. I suggest using 12V DC, but it’s just my preference.

Programming the PICAXE

To program the PICAXE you will need a full kit (board, micro, battery pack and programming cable) and the FREE software loaded to your PC or Mac. If you are familiar with any type of programming, BASIC is among the easiest (Hmmm, I wonder if that’s why that call it that?) there shouldn’t be much to surprise you.

If you aren’t familiar with programming there is even a graphical version (works on PC’s only) where you don’t even have to write code, it’s like using a flow chart (like MS Visio)… But honestly, BASIC is pretty easy, especially if you don’t need to get complicated. We’ll stay on the uncomplicated side for the purposes of this how-to. If you want to get complicated there are lots of great sites that you can utilize (links included at the end) to get you there. You can also reference ‘Section 2 – Basic Commands’ at RevEd (Datasheets tab).

Example #1: Blinking an LED

This simple little program will blink an LED connected to pin 0 ON for 2 seconds (pause is milliseconds, so 200ms = 2 seconds) and then OFF for 2 seconds.

main:

high 0

pause 200

low 0

pause 200

goto main

Make sure your board is plugged into the battery and the USB cable is connecting your computer and board. Load the program to the PICAXE (will get a ‘success’ message if it loaded, if not try again) and it will automatically run. If everything is setup properly your LED will blink on & off. If it’s not, check to make sure the LED is connected properly (LEDs obey polarity).

Further examples… Not sure, will be based on feedback.

Resources/Links already referenced:

http://www.sparkfun.com

http://www.phanderson.com

http://www.robotshop.com

http://www.hvwtech.com

http://www.solarbotics.com

http://www.rev-ed.co.uk/picaxe

Additional Resources/Links:

This is a forum for PICAXE, lots of help can be found, code snippets, ideas, etc:

http://www.picaxeforum.co.uk

This is a great site on how to make robots and other automated/animatronic items. Another place for ideas:

http://letsmakerobots.com

1 comment:

  1. Great post. From looking at the post it looks a lot like the PBasic from Parallax which is pretty simple to use. Thanks for the heads up on this one.

    Cheers!

    ReplyDelete