Nov 7, 2012

Modules updated

Re-designing the code


Finally I've got some time to update the files to github. The after having a break for a couple of months I realized that my first approach was wrong, the classes were dependent, therefore I redesigned each of the for having independence among them.

Some tests need to are bounded to several classes, e.g. the most of the class need the class LCD to show the behavior or result of the tests.

When I re-designed the classes I had also to rename some of them. At the time of updating this to github I encountered with a problem. I had removed or rename the files on my local computer so when I did commit and push them to the server, the server kept the old files and the new. There was no way to remove them. Was then when I found the following command that helped me to remove the old files from the server, and update everything as it was on my local computer:

git add . -A
git commit -m "removed some files"
git push origin master

This is the list of new classes:


DHT11
Sensor of temperature and humidity. I took the code from http://arduino.cc/playground/Main/DHT11Lib in which I did some minor changes.

Keypad
Now this class only controls the keypad and does not include the LCD, Even though are both in the same board. I believe this way is more clear for use it, and the code is grouped by functionality and cleaner.

LCD
This class only writes on the display, nothing else. Actually is the wrapping of the LiquidCrystal class where I merged a couple of function to make the writing easier.

LEDRGB
This class remains almost the same, what before was test now is function of the class. So the test only calls the functions.

MenuController
This class controls the index of the menu but is not a menu itself. does not contain titles/text. That will be performed by the class Menu in the future.

Relay4
Represents the board Channel Relays. It offers the basic functions for controlling the relays.

Test samples.
Now the tests are clearer, shorter and easier to run.



What is next.



I'm thinking about a good way to generate a Menu dynamically and reusable, with a main index and each item containing options, any suggestions?

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.