My Experiments with the PICAXE 08M2+
PICAXE 08M2+ |
In the electronics and robotics world, the analogy of cooking from scratch is to build circuits using a bare bones micro-controller chip (e.g. the PICAXE) rather than a fancy board (e.g. the Arduino). Therefore, once I get a circuit working with the packaged Arduino approach (e.g. this robot I built recently), I usually try to replicate the circuit using more basic components like the PICAXE.
My decision to consider the PICAXE was influenced by Charles Platt's coverage of it in his awesome book Make: Electronics. But essentially, I am a minimalist and I want to see how much I can get done with a bare bones chip rather than a bulky board-based micro-controller like the Arduino. My current favorites are the Nano (quite small, just $7, breadboard friendly, and just as easy to work with as the Uno). My next experiment will be the ATtiny85V-10PU chip because I believe it's still fairly easy to work with (it can be programmed via a regular Arduino and has many of the same capabilities as the Arduino -- many programs written for the Arduino can easily be modified to work on the ATtiny), costs just $2.50, and is of course breadboard friendly. (I don't mind soldering, but for most of my experimentation breadboards are the way to go.)
And the actual PICAXE I chose was the latest model of the smallest chip available, i.e. the 08M2 ($7), for which (as a gentle soul on one of the forums clarified to me) the label on the chip actually reads 08M2+.
Uploading your program to the PICAXE is the first major hurdle you're likely to encounter. As I have discovered, everything involving the PICAXE is harder to do than it is with the Arduino. That's because the PICAXE is just a bare bones chip, whereas the Arduino is a micro-controller chip on a board along with a fairly large supporting cast of components and connectors (e.g. USB).
The standard way to program the PICAXE is by using the AXE027 (USB to 3.5mm jack plug male audio cable) or the USB010 (USB to RS232 9-pin male cable). In either case, additional components are needed to complete the setup.
The AXE027 cable uses an FTDI chip to perform the USB to RS-232 serial conversion required to program most micro-controller chips. However, I was inspired by this video by Kevin Darrah and other postings on the web to employ means other than having to buy this pricey $30 cable.
Kevin Darrah's approach uses an Arduino Duemilanove, which I don't have. So, I tried doing this with the Arduino Uno. The Uno didn't work because the Uno uses the Atmega16U2 chip to perform the USB to RS-232 serial conversion. According to my testing, using the PICAXE IDE's "Test Port" feature, the Uno's serial converter did not seem to support the RS-232 "break" command. The IDE's "Test Port" feature works by turning the signal on and off and a multimeter hooked up to measure the voltage across the PICAXE's serial input pin and 0V (or ground) is supposed to detect a change in voltage as the test LED is switched on and off.
This port test did succeed for me when I tried it with the Arduino Nano, probably because the Nano uses an FTDI chip to perform the USB to RS-232 serial conversion, which clearly does support the RS-232 "break" command.
Note: the exact chip I used was the PICAXE 08M2+, which is a significant upgrade on the 08 and 08M chips. I paid about $7 for it (compare with $35 or so for the Arduino, $45 or so for the Raspberry Pi, and $2.50 for the ATtiny85).
Note that the FTDI chip and most other USB to serial converters that perform the conversion often stop short of inverting the signals, as is needed for programming the PICAXE. The FTDI chip can be configured to invert the signals using FTDI's FT_PROG tool. However, I decided to heed the warning on the FTDI site and use the circuit I've described in this blog to invert the signals rather than mess around with the FTDI chip on my Nano and risk having my Nano being rendered useless.
As I mentioned previously, the reason this circuit is required at all is because signals are inverted in the RS-232 serial protocol. Using 0V to represent logic 0 (a bit value of 0) and 5V to represent logic 1 (a bit value of 1) is the more common approach and is known as the transistor-transistor logic (TTL) level. The RS-232 serial logic levels are not only higher (+/- 12V, so you wouldn't want to connect them directly to your chip since most chips operate on 5V or 3.3V) but also inverted. Therefore a USB logic 1 signal needs to be converted to a logic 0 signal and a USB logic 0 signal needs to be converted to a logic 1 signal. The circuit described here accomplishes that inversion of signals.
To program the PICAXE the IDE needs to send data to the PICAXE and receive data back from the PICAXE. Think of the RX (receive) pin on the Arduino as representing data arriving from the PICAXE IDE via the USB-to-serial FTDI converter. When the IDE is sending data to the PICAXE, the RX logic 1 signal is applied to the transistor's base, which results in completing the circuit from the transistor's collector to emitter and a logic 0 signal being applied to the PICAXE serial-in pin (the logic 1 signal from the Arduino's RX pin got inverted to a logic 0 signal prior to being sent to the PICAXE's serial in pin).
Conversely, when the PICAXE sends data back to the IDE, a logic 0 signal from the PICAXE's serial out pin causes the transistor to remain off and the 5V (logic 1) signal is applied to the Arduino's TX pin. And a logic 1 signal from the PICAXE's serial out pin, when applied to the transistor's base, turns the transistor on, thereby causing a logic 0 (0V) signal to be applied to the Arduino's TX pin. Hence, the inversion of signals is accomplished via the use of these two NPN 2N2222 transistors and four 10K resistors.
So, finally, here's the circuit that I've been describing in the paragraphs above.
Schematic From Kevin Darrah's Video |
Breadboard Circuit for Programming the PICAXE with an Arduino |
LED Blink Program for the PICAXE |
However, to be fair, I should acknowledge that Atmel also uses different physical/hardware and software/code pin numbering schemes for its chips, e.g. the ATtiny85. Regardless, I'd appreciate it if anyone could point me to a good tutorial on how to use the four ports (A, B, C, D) on the PICAXE 08M2+.
The ATtiny85 by Atmel |
PICAXE 08M2+ Pin Assignments |
Here's the circuit I put in place to get a reliably blinking LED. Note that this is the configuration you'll need in case you wish to have the serial in/out pins to double duty, e.g. digital I/O. However, my favorite configuration is one in which I leave serial in/out pins dedicated to programming and use the other four pins for I/O. That way, I can program on the fly. Also, note that here the Arduino is merely supplying power (5V) and I have not shown here the USB cable from my laptop providing power to the Nano.
Breadboard Circuit for PICAXE 08M2+ Blinking LED |
In closing I'd like to share one final observation. So far, I have been lucky to have fried or damaged very few components. The first was a set of three LEDs that came with my Raspberry Pi starter kit from Adafruit. That was until I realized that I simply must add a 1K resistor in series with LEDs at all times. And I also realized that once you know exactly what you want (which requires a bit of learning and research), it's a lot cheaper to buy components via eBay. The second was the Raspberry Pi's SD card slot, which broke upon the slightest application of vertical stress. (BeagleBone's MicroSD card slot is a much better idea since it's smaller and less susceptible to vertical stress.) And finally, the first PICAXE I ordered either arrived damaged or was damaged during my experiments with trying to program it. I suspect it might have been the former (a ding against eBay), because when it arrived the painted branding information (PICAXE 08M2+ and serial number) had already worn off and I had to strain to read the engravings (a shout out to the iPhone magnifying app "Mag Light" for making this a lot easier). The second PICAXE I ordered (again via eBay), which is the one I successfully programmed, seems pretty resilient. I have even accidentally applied reverse voltage and all it did was pop the software fuse on my laptop's USB port (requires a laptop reboot to reset). To be fair, I have ordered many, many components from eBay at extremely reasonable prices and have had very few negative experiences (although the best deals do take forever to ship and will test your patience and stamina for electronics). Note that I always make sure that the seller has at least a few hundred reviews and a 98% or higher ratio of positive feedback.
Update: Good news! The first PICAXE, which I had set aside as "damaged" has turned out to be perfectly fine and healthy. I swapped it into my programming/test operation circuit (described above in this blog post) and I am able to program and operate it. So, it was human error after all. However, when I'm at my wits end I often fall back to swapping components like chips that cannot easily be tested with a multi-meter. And it is certainly good to have plenty of spare breadboards and jumpers so that once, for example, you've established a working circuit for programming a micro-controller chip you can set it aside and not have to tear-down and build it each time you need to program the chip. Now on to programming my 2D string array of remote control codes for my Arduino robot project (see link above), which I eventually want to try controlling with the smallest bare bones micro-controller that'll do the job, e.g. a PICAXE or an ATtiny. Also, I am told that faded etching on top of the engraved chip markings are quite normal and are not necessarily a sign of wear.
I know I had a bunch of trouble getting my PICAXE 08M2+ to do my bidding. So, I decided to document my experiences in order to help others and perhaps even myself, if several days from now I can't recall how I actually got it working. As I mentioned, working with the PICAXE (or any other bare bones micro-controller chip like the ATtiny85) is sure to be more challenging than working with a board like the Arduino boards. Also, relative to the PICAXE, there is a lot more help available for the Arduino in the form of videos, web posts, and books. But if you're up for the challenge, then the PICAXE can give you more control at a smaller cost. All said and done, I feel very positive about the PICAXE and its prospects on future projects of mine.
0 Response to "My Experiments with the PICAXE 08M2+"
Post a Comment