August 4th, 2009

Matrix keyboard explained

Matrix keyboard setup

In many cases you want to add some input interface to the project, the most simple is to use some push-buttons but what if you need to set some values, some of you might say:  you can do it with up-down, left-right, select button and some clever menu. Yes that’s about right but just imagine the software if you want to set values from 0-9999, or applications like access control, counters.

The most commonly known is the 12 (34) type which has off course 12 buttons noted from 0-9 and *, # for extra features. Well so far there isn’t anything clever about it, 12 buttons which need 12 input pins, wrong it needs just 7, the push buttons are organized in rows and columns, each row shares the same horizontal connection, while each column shares the same vertical connection. For a better understanding look at the schematic:

matrix keyboard schematic

Because of this matrix connection the reading of active button(which is pushed) isn’t so straightforward, each column has to be processed sequentially.

The resistors are external components, there are not included into the keypad but certainly needed, R1-R4 are the pull-up resistor, in the demo application the atmega88’s internal pull-ups are used, R5-R7 are for current limiting.

A few words about the firmware, the keyboard is connected to PORTB, PB0-PB3 are configured as inputs with the internal pull-up active, these will read which row is active, PB4-PB6 are configured as outputs and serve for column selection, their default value is logic ‘1’ the same as the row pins default value. The reading is made sequentially, the first column is selected by setting PB4(COL1) to logic ‘0’ and the pins PB0-PB3 are red, if no key is pressed the pins remain in their default state: logic ‘1’ else their value is logic’0′ we must go trough these steps for each column, once a pressed key is found its space thus value is determined, the function restores the corresponding column select pins default state and exits, this way speeding up the process.

Lets take an example: key 4 is pressed, column 1 is selected by setting PB4 to logic ‘0’, when we read PB0-PB3 PB1 will be logic ‘0’, since we know which column is active (it would be really funny otherwise since we wrote the firmware) the exact location of the pressed key is determined. Now we have 2 coordinates x(0..2),y(0..3)  x=1 is the row, y=0 is the column the most simple way to turn these coordinates into a value is using a 2 dimension look-up table:

const unsigned char KeyMap[3][4] = {{1,4,7,ESC},{2,5,8,0},{3,6,9,ENTER}}; // values ESC and ENTER are defined by macros

By simply addressing the table with the coordinates we have the corresponding value of the pressed key  value = KeyMap[x][y]; the look-up table can also hold any data of choice like ASCII, or can have other type definition as long as its dimension matches the keypads dimension [x][y].

Since the keypad or any other human machine interface tends to be asynchronous, which means that at any moment the firmware should be able to sense and to handle the input, the entire process or in other words the scanning must be executed periodically. This can be done inside some timer interrupt routine or just by adding some delays to the main cycle, if possible avoid using the mains power frequency or any multiple of this for scanning.

Also between the column selection and the effective pin reading some delay must be inserted, this allows time for the electrical state of the wires, traces to stabilize. After one pressed key is sensed the function exits, thus multiple pressed key will not be recorded although the modification needed to the firmware is quite simple, so consider this a challenge.

I attached the entire AVR Studio project, it is written in C, using the winavr package, it will be easy to integrate into any project. In the near future I will explain how to save I/O pins by sharing the row pins with other functions like driving the 7 segment display.

Matrix keyboard explained: [download]

October 1st, 2008

LED Pharmacy Cross

This article is part of the PCB Giveaway program that we have running here at Youritronics. Morgoth will get a free pcb manufactured by BKRtech for submitting this project. If you’re interested in participating, read more on the program page.

These days most pharmacies use LED pharmacy crosses posted at their entrance to let people know there is a pharmacy there. The reasons are obvious, they look cool&hi-tech, they can be seen from distance and they can be customized really easy (well, easy customizing pretty much depends on how the manufacturer approaches things).

If you try to search the web about schematics or example codes for this kind of circuit you wont find any, and again i think the reason is obvious, the crosses are quite expensive and so is the profit for the manufacturer. So nobody is gonna post schematics for such a project, unless you’re a hobbyist and you’re having fun with electronics.

The project consists of one ATmega64, three ULN2003 and five 57 LED matrix from Kingbright(TA20-11EWA). I had the idea to build something like this but so far i haven’t had the time nor the knowledge to get it done. So i asked Morgoth if he would like to participate in the project. I sent him the LED’s, the drivers and the PCB and he started working. As you can see not many parts are involved , but the secret lies in the microcontroller, it’s the programming that does the job.


In the next pictures you can see the microcontroller board with the ULN2003 darlington arrays:

LED Pharmacy CrossLED Pharmacy Cross

The circuit was designed to receive messages trough serial interface from a computer and than display them. Morgoth also designed a custom terminal for windows which provides easy access to the display.

In this test phase a serial interface by wire was used to transmit data between the terminal and the ATmega64, but a wireless or bluetooth module could be integrated with no problem.

Also as a note, the LED’s don’t light up really bright, for that to happen you need to use drivers on the positive rail. This also applies if you’re planning to take the project to another level and use bigger LED’s

And now, watch some videos with the LED Pharmacy Cross beeing controlled from the computer:

You need to a flashplayer enabled browser to view this YouTube video You need to a flashplayer enabled browser to view this YouTube video
July 18th, 2008

Fancy LED matrix

Fancy LED matrix

The author, Olivier de Broqueville designed this circuit for hi’s son who was dreaming of a small tool able to write symbols or pictures on a screen. The solution adopted was to pilot a matrix of Leds. This way, with only some cheap transistors, common red Leds,  and a 16F628 , the dream could become reality.

Olivier also made a VB application that you can use to design patterns and export them apropriately.

Fancy LED matrix: [Link]

Computer Controlled LED Matrix

The project uses (2) 57 LED Displays, so 10 columns and 7 rows for a total of 70 LEDs.  The matrix works on the basis of scanning the display very quickly. The 4017 chip is used to switch between the columns. The way the 4017 chip works, is that when a signal is sent to a certain pin, 1 of 10 of the other pins is sequentially activated. The way the software works, is it tells the chip to switch columns, which sets one column high.

The software then makes the parallel port turn on the individual LEDs in that column needed. This is done very quickly, many times a second. It’s a fairly easy concept and it turned out the programming was easier than the author had initially anticipated.

And the great thing about this project is that it also comes with a font writer, which is basically a software written also by the author of the circuit to help him quickly design animations.

Computer Controlled LED Matrix: [Link]

You need to a flashplayer enabled browser to view this YouTube video

Another useful application for a LED dot matrix display, well useful for those who use twitter. The purpose of the project is simple, it scrolls your twitters on the led matrix, this way you don’t have to be in front of your computer to see what’s new. Source codes and info about building it is provided by the author. The matrix is controlled by an Arduino

Physical LED Twitter Scrolls Your Twitters: [Link]

© 2007-2011 YourITronics | Any logo, trademark and project represented here are property of their respective owners | Wordpress | Privacy Policy    RSS