Electronics, Photography, Gadgets

Month: May 2010

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
pause 500
key = 0
for row = 0 to 3
high row
gosub keyscan
low row
if key > 0 then gosub displayKey
next row
goto main
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
serout 7, N2400, (254,1,#key)

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

Amazon Kindle v2.5 Software Update

In the immortal words of Professor Hubert J. Farnsworth, good news everyone! It looks like there is an imminent firmware update for the Kindle waiting in the wings – version 2.5. The exciting new features in this release seem to be collections for organizing books and documents into one or more groups or “collections”, PDF pan and zoom, improved clarity and more fonts. It will also apparently support some social network features such as facebook, twitter and shared “highlights” or interesting passages in books – ok, but I’m more interested in its book reading capabilities. In my opinion, this fixes almost all of the niggles with the device.

Update: My Kindle DX now runs with 2.5.2 – details here.

© 2017 MOV AX, BLOG

Theme by Anders NorenUp ↑