Aug 25, 2012

Interactive menu with keypad and the LCD display

After make sure that each button is recognized properly by the software I created a class called Menu.

This class is for controlling the menu's options, reacting to the buttons' events:
UP, DOWN, LEFT  and RIGHT.

Basically the menu has four options, they are listed as follow:


1 - LIGHTS
2 - WATER PUMP
3 - FAN
4 - HUMIDIFIER

The program starts showing the option 1 - LIGHTS. Pressing the buttons UP and DOWN you can scroll the menu. Boundaries were established to not let the buttons scroll more than available options.
With the LEFT and RIGHT buttons you can set ON and OFF the status of the output which is not implemented yet. The status is shown on the bottom right corner.


Source code now is available on GitHub

I was configuring my account on github for sharing this code, feel free to take a look and fork it ;)

Source code


Aug 19, 2012

First test with LCD Keypad Shield

I've got my LCD Keypad Shield two days ago. I bought it for 8 € in dx.com Here is the link if you are interested to buy one.

LCD Keypad Shield



I was not sure if this Shield would fit in my Arduino Mega. Fortunately it did. Now, I tried to use some of the examples from the Arduino but they did not work properly.
Since I don't know even which model is this shield and I don't have any documentation, I took a code from freetronic and checked how this thing works. By the way there is nice explanation about how the buttons are connected to a single analog input (A0).

Check the article here

I ran the example and it did not work because this code is for freetronic not for this one. so I went through the code and I noticed that Arduino reads the A0 to figure out which button was pressed. There is a range of voltages for each button. Now, what I did was to show in the display the voltage of the pressed button down on the right corner of the display.
As you can see in the image, pressing the Down button generates 308mV. These are the values I got.

  ADC voltages for the 5 buttons on analog input pin A0:

    RIGHT:  0.00V :   0 @ 10 bit
    UP:     0.71V :       133 @ 10 bit
    DOWN:   1.61V :  308 @ 10 bit
    LEFT:   2.47V :     481 @ 10 bit
    SELECT: 3.62V :  722 @ 10 bit

I adapted those values in the code and now it works!

#define RIGHT_10BIT_ADC           0  // right
#define UP_10BIT_ADC            133  // up
#define DOWN_10BIT_ADC          308  // down
#define LEFT_10BIT_ADC          481  // left
#define SELECT_10BIT_ADC        722  // right

This are the lines you can uncomment to see the voltage of each button:

   //debug/test display of the adc reading for the button input voltage pin.
   lcd.setCursor(12, 1);
   lcd.print( "    " );          //quick hack to blank over default left-justification from lcd.print()
   lcd.setCursor(12, 1);         //note the value will be flickering/faint on the LCD
   lcd.print( analogRead( BUTTON_ADC_PIN ) );
   delay(500);


Notice that I change the location of the message for the second row and also put a delay.