Bury the Hatchet, Unbury the Axe by Wouter Spruit (NL) Getting Started with PICAXE
Total Page:16
File Type:pdf, Size:1020Kb
Elektor•Post Project No. 8 Bury the hatchet, unbury the axe By Wouter Spruit (NL) Getting started with PICAXE Microcontrollers can be used to add processing capabilities to any project, and off-the shelf microcontrollers are often used to fulfill a specific purpose. Programming a microcontroller with your own firmware gives you complete freedom to implement smart input and output for your projects. The PICAXE system gives any hobbyist the chance to program a microcontroller and inter- face it to peripherals with little hassle and at low cost. Figure 1. PICAXE chip sizes. What? Why? How? a range of accessories: from components, The PICAXE products are a range of Microchip breadboards, cams and gears to cables, I2C PIC microcontrollers programmed with a spe- peripherals, LCD screens and starter packs. cial firmware by Revolution Education [1]. The The website aims to offer everything neces- philosophy behind the PICAXE system is that sary to get started programming the PICAXE the best way to learn how to program and right away. The online store even offers kits to implement microcontrollers in a project is to build toys like such as robots based on PICAXE use a cheap system that doesn’t require a lot microcontrollers. All peripherals for sale come of experience but still offers complex interfac- with extensive documentation on how to inter- ing capabilities that make the microcontrol- face them with a (PICAXE) microcontroller. lers suitable for more advanced projects. The So even if you’re not using a PICAXE micro- PICAXE line offers a range of microcontrollers controller in your project, checking out this of different shapes and sizes, from simple store for components might be worthwhile. microcontrollers with only 8 pins and limited capabilities, to the more advanced 40-pin The secret that defines PICAXE is the special 40X2 model (Figure 1). Since the introduc- firmware. A PICAXE chip is a Microchip PIC tion of the PICAXE system over 15 years ago, pre-programmed with the PICAXE firmware, more recent parts have replaced the PIC including a BASIC interpreter and a number of microcontrollers that form the foundation of pre-loaded functions. The PICAXE code allows the PICAXE system, offering not only more a user to upload a PICAXE BASIC program at memory and computational power, but also any time, via the serial connection (as long parallel execution of tasks in many cases [2]. as it’s not in use by the current program- ming). The new code starts executing right The Revolution Eduction webstore [3] not only away. Because the PICAXE programs are inter- offers the PICAXE microcontrollers, but also preted BASIC code, the number of instruc- elektor post | Project No. 8 | 1 Elektor•Post Project No. 8 tions carried out per second are relatively and AXEpad, in addition to being available on limited, rendering bit-banged communications the PICAXE website [6]. The manual is split in to interfaced devices infeasible. However, the three parts, called “getting started”, “BASIC pre-programmed functions implement some commands” and “microcontroller interfacing common bit-banged input/output functional- circuits.”. The first part contains information ity, for instance enabling the PICAXE chip to on the technical capabilities and pinouts of communicate with I2C peripherals or sending various PICAXE products, instructions on pow- and interpreting IR signals. The advantages ering and connecting to the device, as well of using interpreted BASIC code for writing as a number of tutorials to get started with PICAXE programs is the way the programs are the system. The second part of the manual uploaded to the device. The interface required covers descriptions for all BASIC commands, to program regular Microchip PICs is complex as well as providing information on the com- and hard to build and use, in comparison to mand availability on the various PICAXE chips the PICAXE programming interface. PICAXE and programming examples. The third part projects commonly include a jack connected of the manual is a collection of interfacing to the chip’s serial interface pins, which allows examples. The manual not only covers inter- for quick and easy reprogramming of the chip facing basic components such as a switch, in the field. Just plug in the power and con- LED or motor via Darlington pair, but it also nect the serial jack to a PC and you’re ready provides examples for interfacing the PICAXE to upload a program to your PICAXE chip. chip with commercially available components and chips, including instructions for adding an Though the PICAXE BASIC programs can be LCD screen via I2C, and it even covers con- written and uploaded in a very short time, necting the PICAXE to a PC via a serial con- complex mathematical operations requiring nection. The best part about the examples is thousands of clock cycles per calculation are that they don’t apply exclusively to interfac- best not implemented using the real-time ing PICAXE with components, but the general interpreted BASIC code. The code would run principle applies to interfacing peripherals with too slowly to be of any use in real-time sen- any non-PICAXE chip (still, it might be wise sitive projects. to consider the chip’s operating voltage and maximum current it could sink and source). Alternatives to PICAXE Regular Microchip PICs require a PIC pro- Though it was originally designed for edu- grammer to upload new program code to cational purposes, PICAXE is also especially the device. Though projects such as the “el suitable for use in many hobbyist projects. cheapo” [4] can be used to decrease the price PICAXE users are encouraged to upload their of obtaining a PIC programmer, the cost and projects to the PICAXE website. The gallery complexity of starting a project to simply blink of user projects has become a great show- an LED on a fresh PIC can be fairly intimidat- case for PICAXE capabilities. The forums ing to those just starting to get interested in available on the website are a good place to programming their own microcontroller. The get answers to your questions regarding the same goes for the Atmel AVR microcontrol- PICAXE system or interfacing peripherals for lers. Though the Arduino project [5], con- your electronics projects. sisting of a Atmel AVR microcontroller on an interfacing board together with an IDE and Supporting software documentation, also offers an easy way to The PICAXE system allows the user to upload get started with microcontrollers, it’s more BASIC programs from a PC to a PICAXE chip expensive and difficult to implement in actual via a serial connection. PICAXE comes with projects in comparison to PICAXE. a feature-rich development environment for Windows called the programming editor, Support and documentation allowing the user to quickly connect to, pro- Because of the educational nature of the gram and debug PICAXE chips. A cross-plat- PICAXE products, it’s no surprise extensive form alternative to the programming editor documentation is available. The PICAXE man- is available under the name AXEpad. AXEpad ual is included with the programming editor provides the most important features of the elektor post | Project No. 8 | 2 Elektor•Post Project No. 8 Figure 2. USB-to-jack cable. programming editor, including: editing and uploading code to the PICAXE chip, a termi- nal window, and even several code generation wizards. In comparison to the programming editor, AXEpad does lack some features, for instance the on-screen tool to test and step through a simulation of a PICAXE program. Figure 3. To use the editor, connect a PICAXE chip using ure 3). Though Revolution Education offers Pinout of the PICAXE 08M2. either the serial-to-jack or the USB-to-jack starter packs that already include all neces- cables (see Figure 2) and specify the serial sary interfacing electronics, this example will port the programming editor (or AXEpad) show how to connect a PICAXE chip yourself, should use to connect to the chip. To tell the on a breadboard. The pins relevant to our editor what kind of chip it is programming, setup are pins +V (1), 0 V (8), serial in (2), the PICAXE type is selected manually. The serial out (7) and the output pin that connects program also offers a function to look up the to the LED (3). firmware version for a connected PICAXE chip. Once the chip is connected, it is programmed The blinking LED circuit is shown in Figure 4. by uploading a written/loaded a BASIC pro- The power pins +V and 0V are connected to a gram from the editor directly to the PICAXE DC power supply from 3.0 V to 5.0 V. To use chip. The new program starts running on the one of the battery packs (for instance, from PICAXE chip right away. Blinking an LED This simple example will show how to program a PICAXE chip to blink an LED. A PICAXE 08M is used in the example circuits, but the gen- eral principle applies to every PICAXE chip. Use the pinout diagrams [7] corresponding to your PICAXE chip to select an output to connect an LED to. In the case of the PICAXE 08M, pin 3 (C.4) was selected from the pin- Figure 4. out of the PICAXE 08M2 (as depicted in Fig- Blinking LED circuit. elektor post | Project No. 8 | 3 Elektor•Post Project No. 8 the Revolution Education store), take care Listing 1: our very first PICAXE program to use no more than three 1.5 V AA batter- ies or four 1.2 V AA rechargeable batteries. do ;repeat forever The download circuit according to Figure 5 high 4 ;set output 4 high is connected to the serial in, serial out and pause 1000 ;wait 1 second 0 V pins on the PICAXE.