MOV AX, BLOG

Electronics, Photography, Gadgets

Tag: microcontroller

First Project Using The PICAXE-08 Proto Board Kit

After building the first prototype of our timer device and then making preparations to use the PICAXE 08M and save space by using a single NPN transistor as a NOT gate, we have finally completed our project using the PICAXE-08 Proto Board Kit. As usual, I purchased the Proto Board and PICAXE chips from those reliable folks at techsupplies in the U.K. For around 5 Euros, the  PICAXE-08 Proto Board Kit with a PICAXE-08M microcontroller is a real bargain. It has almost everything you need to get going – the only extras you will require are a USB cable for programming the PICAXE and a battery box for holding 3 AA batteries to supply the circuit with 4.5v. I found the size of the prototyping area on the board to be ample for simple projects. Please note that the kit comes in component form, shown in the picture below, and has to be assembled using a soldering iron and a little bit of time – it is not complicated.

PICAXE-08 Proto Board kit

Moving the timer to the PICAXE-08M from the PICAXE-20M prototype was relatively straight forward. The new circuit uses pins 0, 1 and 2 to power the “minute/seconds LEDs” while pin 3, which is an input pin only, is used to select the device’s function (eggs or teeth) and pin 4 is used to power the piezo buzzer. On the prototyping area I placed the resistors to drive the LEDs and a voltage regulator to power the circuit from a 9v battery. In our circuit pin 3 is also pulled down to 0v using a 10k resistor. Below is the code for the device.

symbol counter = b0
symbol teeth = b1
symbol eggs = b2
symbol loopCounter = b3
init:
pause 200
loopCounter = 0
if pin3 = 1 then
teeth = 1
eggs = 0
else
eggs = 1
teeth = 0
endif
start:
for counter = 1 to 60
low 0
pause 500
high 0
pause 500
next
for counter = 1 to 60
low 1
pause 500
high 1
pause 500
next
for counter = 1 to 60
low 2
pause 500
high 2
if counter > 55 and teeth = 1 then
high 4
elseif counter > 55 and eggs = 1 and loopCounter = 1 then
high 4
endif
pause 500
low 4
next
if eggs = 1 and loopCounter = 0 then
loopCounter = 1
goto start
endif
end:
high 4
pause 1000
low 4

Luckily, as mentioned previously, we had prepared to save space in the enclosure – which is good because the space available turned out to be even smaller than I thought. The wiring to the LEDs and switches added quite a bit of bulk and as a result the whole circuit plus battery only just squeezes in. The image below helps to illustrate just how much bulk the wiring added to the internals of the device.

Unexpected Added Bulk Through Wiring

After many hours of work, the device is now completed and we used it tonight to time the brushing of our teeth. Tomorrow morning, we’ll use it for the first time to time our soft boiled eggs ;-).

The Completed Eggs-Teeth Timer

Building Something Useful With Counters

After building a 4bit counter using JK flip-flops last week, my son and I thought about what we could build using counters which would be of use around the house. We thought of two things – a 3 minute timer for timing how long you have brushed your teeth and a 6 minute timer for soft boiled eggs. The 9bit counter circuit required to build a 6 minute timer using JK flip-flops would require 5 chips plus a 555 timer set to “tick” once per second and quite a bit of discrete logic to turn on and blink the LEDs at the correct times. Knowing how much work this would involve to design it and then build it using strip board, I turned to the trusty PICAXE microcontroller to simplify things.

The advantage of using a microcontroller is that it is pretty simple to build what would be complex using discrete logic and therefore we decided to build an egg-teeth timer, i.e. both of the timers in one device. We used a PICAXE 20M to build the first prototype with output pins 0, 1 and 2 connected to 330 ohm resistors and then yellow LEDs. Input Pin5 is used to select the function of the device, i.e. eggs or teeth with output pins 4 and 5 connected to 330 ohm resistors and then green LEDs to indicate which function has been selected. A piezo buzzer is connected to output pin 3 to give an audible signal once the counter has reached either 3 or 6 minutes depending on the selected function. The code for the device is listed below:

symbol counter = b0
symbol teeth = b1
symbol eggs = b2
symbol loopCounter = b3
init:
pause 200
loopCounter = 0
if pin5 = 1 then
teeth = 1
eggs = 0
high 4
else
eggs = 1
teeth = 0
high 5
endif
start:
for counter = 1 to 60
low 0
pause 500
high 0
pause 500
next
for counter = 1 to 60
low 1
pause 500
high 1
pause 500
next
for counter = 1 to 60
low 2
pause 500
high 2
if counter > 55 and teeth = 1 then
high 3
elseif counter > 55 and eggs = 1 and loopCounter = 1 then
high 3
endif
pause 500
low 3
next
if eggs = 1 and loopCounter = 0 then
loopCounter = 1
goto start
endif
end:
high 3
pause 1000
low 3

Having built the first prototype, the next step was to build an enclosure for the device, below is an image of the prototype and the device’s enclosure.

The Eggs, Teeth Timer Prototype and Enclosure

The next step is to move the prototype into the enclosure, but before doing so we are going to redesign the device around a PICAXE-08 Proto Board and a PICAXE-08M microcontroller in an effort to reduce the space required in the enclosure and to use a “simple” microcontroller more appropriate to the devices’ functionality.

AXE029 PICAXE Breadboard Adapter

As we use breadboard quite extensively in our microprocessor experiments I decided to take a look at the AXE029 breadboard adapter for the PICAXE which I purchased from the reliable people at tech supplies. The first thing that surprised me after receiving it was that it is not pre-assembled but in kit form; in retrospect it was perhaps a little naïve to think that it would pre-built. After a few minutes soldering, as the kit is not hard to put together, everything was in place and working fine – before and after shots below. On the AXE029 device there is a jumper which enables you to select between an 18 pin or 28/40 pin PICAXE and this allows you to place the AXE029 directly next to the PICAXE pins on the breadboard – works a treat with the 28X1 PICAXE microprocessors but not the 20M. For the 20M, you will have to place the AXE029 somewhere on your breadboard and connect it to the 20M via wires – not a big deal.

AXE029 Breadboard Adapter

One problem that I have had for a while now, and which is unrelated to the AXE029, is reliably getting a connection to the PICAXE. Using the MacAXEpad and connecting to the PICAXE via a USB cable, I often get connection errors. I’ll have to take a closer look at this – I suspect the USB driver on the Mac but it is hard to tell.

Interfacing The PICAXE M-Series Microcontroller With A 4×3 Matrix Keyboard

After my son discovered that disclosing your PIN for a hard coded alarm is not such a great idea, we have embarked on moving our alarm system to a micro-controller which can then be programmed to allow the user to change the PIN at run-time. Our microcontroller of choice is the PICAXE which is available here. For this project, I chose the PICAXE 20M, but this was a bad idea as the memory on this device is much too small for this kind of project as I will show later. In addition to the 20M, I also ordered the AXE029 breadboard adapter, the AXE033 Serial LCD module and a 4×3 matrix keypad for data entry. I also should mention that the service from tech supplied in the U.K. is very good – I live in Germany and the package was dispatched the same day and arrived two days later.

 

4x3 Matrix Keypad

 

Our first job in this project was to interface the keypad and LCD module to the microcontroller. In this post I will describe how the keypad can be interfaced to the 20M and in a later post I will describe the LCD module and post the code for the first version of the alarm. The pins on the keypad are arranged as follows (reading left to right and looking at the keys): (1) Not Connected (2) Column 2 (3) Row 1 (4) Column 1 (5) Row 4 (6) Column 3 (7) Row 3 (8) Row 2 (9) Not Connected. The row pins (R1 – R4) should be connected to output pins of the 20M as follows: (1) Output0 -> R1 (2) Output1 -> R2 (3) Output2 -> R3 (4) Output3 -> R4. The column pins of the keypad (C1 – C3) should be connected to the input pins of the 20M as follows:  (1) C1 -> input0 (2) C2 -> input1 (3) C3 -> input2. Don’t forget that the input pins 0 – 2 on the PICAXE have to be pulled down to 0v using 10k resistors so that the pins aren’s floating when no input is present from the keypad. The circuit described above can be seen in the following schematic.

 

PICAXE 20M Keypad Interface Schematic

 

The next step is to program the microcontroller so that it scans the key pad. To do this, simply loop through the rows one at a time (output0 – output3) and test which column is set. Below is the code I developed to do this. In a nutshell, the main routine loops across all of the row pins and sets them high one by one. The keyscan routine is called for each row scan and it checks if a column pin is high – if true, it calculates the key number using the simple calculation row * 3 + column and waits until the key is released. The displayKey routine displays the number on an LCD module.

symbol row = b1
symbol key = b2
init:
pause 500
main:
key = 0
for row = 0 to 3
high row
gosub keyscan
low row
if key > 0 then gosub displayKey
next row
goto main
keyscan:
if pin0 = 1 then
key = row * 3 + 1
do loop while pin0 = 1
elseif pin1 = 1 then
key = row * 3 + 2
do loop while pin1 = 1
elseif pin2 = 1 then
key = row * 3 + 3
do loop while pin2 = 1
endif
return
displayKey:
serout 7, N2400, (254,1,#key)
return
end

Update: This post described how to interface an alternative 4×3 Keypad with a different pin-out configuration.

A First Simple PICAXE Microcontroller Project

Some of my son’s other interests include traffic lights (or stop lights), boom barriers, automatic doors and control panels of any kind. The first microcontroller project we decided to build was a traffic light system including a pedestrian crossing. The microcontroller kit I decided to use for this was the PICAXE-20M Starter Pack (USB) which uses a PICAXE 20M with 8 input pins, 8 output pins, 220 lines of program memory and supports interrupts, digital temperature sensors, radio-control servos, keyboard input, user defined musical tunes, infra-red transmission and reception, an 8/10 bit ADC option, pwm motor control and input pulse counting. The device is programmed via the supplied USB cable. It is a surprisingly sophisticated chip for 2,35 euros. Below is an image of the 20M connected to a small breadboard with three LEDs (one red, one yellow, one green) and 330 ohm resistors.

PICAXE 20M Traffic Light Project

In the circuit above, we connected output pin1 to a 330 ohm resistor and then a red LED, output pin2 to a 330 ohm resistor and then a yellow LED and finally output pin3 to a 330 ohm resistor and then a green LED. To program the PICAXE, you will need a copy of the MacAXEPad for the Apple Mac or AXEPad for the PC which is available at the PICAXE software download page. There is also a comprehensive set of manuals online which describe how to develop code for the PICAXE in BASIC. The basic program below controls the traffic light and is my son’s first ever piece of code. :-)

tlight:
high 1
pause 3000
high 2
pause 1000
low 1
low 2
high 3
pause 3000
low 3
high 2
pause 1000
low 2
goto tlight

Alarm 2.0 and Microcontrollers

The next projects we have been working on and will be described in later posts are much more sophisticated than the previous alarm system. The projects include: building logic gates such as AND, NAND and OR out of NPN transistors, a four bit adder out of logic gates which in turn are built from NPN transistors, a 4 bit counter from J-K Flip-Flops, a new version of our alarm system using 555 timers, logic gates, diodes and a keypad to activate and de-active the alarm and finally, a traffic light system using a PICAXE microcontroller and logic gates. If you would like to find out more about these components and electronics in general, I can highly recommend Make: Electronics by Charles Platt.

Make: Electronics

If you would prefer an online source of information, I can also recommend doctronics which has some great guides and projects with useful circuit diagrams in breadboard format. Take a look at the doctronics biscuit tin alarm for a fun project.

© 2017 MOV AX, BLOG

Theme by Anders NorenUp ↑