Translate

Saturday 26 April 2014

Room Management System – Adding a 16 x 2 LCD

I finally got around to do a little research and some homework do add the LCD to the room management system using only 3 wires and a shift register. First of all a big thanks to Chris Parish for publishing his circuit diagrams and the library to make it work.

Second, before we start, a small explanation what I would like to do with the display. The main goal is still the menu project, implementing a way of adjusting timers and sensitivity settings without hooking the system up to a computer or pulling the chip out for reprogramming. A second goal is to display a permanent system status. For example displaying if a circuit has to be activated or not which makes troubleshooting a little easier if something goes wrong.

We need a HD44780 based LCD display, a 74HC595 shift register, a 10 k trim pot, a 220 ohm resistor (optional) a pref board, some wire and about an hour time for soldering or a breadboard and some jump wires if you like to make it temporary for experimenting first. To get started we make a quick D-tour to Chris blog at http://cjparish.blogspot.com/2010/01/controlling-lcd-display-with-shift.html to have a look at the original wiring diagram and a different approach of building the adaptor. Please also download the library from his site and place it as usual with all the other libraries in the library folder of the Arduino IDE. All done so far?
Let me show you how I wired up my display adapter. All brown drawn wire connections are on the solder side. The two yellow wires are on the parts side as jumpers. I couldn't get the MOSFET which Chris originally used in his diagram, so I used a FQP30N06L which works as well. I added also a 220 ohm resistor between the VCC connection and the LCD pin 15 cause I found the back light a little bright. However, that's up to your liking, putting it in or change the value to your needs.



Finally we connect it to the Atmega chip. The data pin (74HC595 pin 14) goes to Arduino pin DI 9, the latch pin (74HC595 pin 12) goes to Arduino pin DI 10 and the clock pin (74HC595 pin 11) connects to Arduino pin DI 11. Don't forget to connect GND and VCC.




Now comes the interesting part. First we need to include the ShiftLcd library and there fore we go right on top of our room management system sketch:


#include <DS1307RTC.h>
#include <Time.h>
#include <Wire.h>
//>>>>>>>>>>>>>>>>That's' the library to include<<<<<<<<<<
#include <ShiftLCD.h>

/////////////////////Declaring the Variables/////////////////


From here we jump down to the end of the timer variables to where it says


byte room901Active = 1;                   //Set to 1 if you want to process
                                                      //Timer will be ignored when set to 0
unsigned int room9On[2] = {17, 45}; //Time to switch on the lights
unsigned int room9Off[2] = {18, 30}; //Time to switch off the lights
////////////////////////////DO NOT MODIVY BELOW HERE///////////////////////////////////////

//////////defining Arduino Pins/////////////////
//>>>>>>>>>>>>>here we add<<<<<<<<<<<<<<<<<<
ShiftLCD lcd(9, 11, 10);                  //initializing the LCD adaptor pins

Next, we go down to the setup loop:

void setup() {
//////////////Start Serial for Debugging/////////////////////

Serial.begin(9600);
//>>>>>>>>>>>>>>addition starts here<<<<<<<<<<<<<<<<<<
lcd.begin(16, 2);                           //start lcd
lcd.print("RMU 1.2.3");                 //print something 
delay(2000);                                //for read abilety
//>>>>>>>>>>>addition ends here<<<<<<<<<<<<<<<<<<<<<<
//////////////////defining pin modes////////////////////
pinMode(doorMonitor, OUTPUT);     //setting the LED pin to output
pinMode(latchPin, OUTPUT);           //setting the latch pin to output
pinMode(clockPin, OUTPUT);          //setting the clock pin to output
pinMode(dataPin, INPUT);               //setting the data pin to input
pinMode(latchPinOut, OUTPUT);
pinMode(clockPinOut, OUTPUT);
pinMode(dataPinOut, OUTPUT);
OK so far. We move on and go down to the beginning of the holiday switch processing.

//////////////Holiday lighting/////////////////////////
//we need to move everything below this comment up to
// currentYear = tmYearToCalendar(tm.Year); //passing year to var
// }
//below the line, where it says “ //////////////////processing the input/////////////////////”
tmElements_t tm;                 //initializing RTC
if(RTC.read(tm)) {               //Reading the clock
currentHour = tm.Hour;        //passing the time into a var
currentMinute = tm.Minute;   //passing the time into a var
currentDay = tm.Wday;        //passing Weekday
//(Mon - Sun eg 1-7) into var
currentDoM = tm.Day;         //passing day in to var (1-31)
currentMonth = tm.Month;   //passing month into var (1-12)
currentYear = tmYearToCalendar(tm.Year); //passing year to var
}


After movement it looks like this:
//////////////////processing the input/////////////////////
tmElements_t tm;                   //initializing RTC
if(RTC.read(tm)) {                 //Reading the clock
currentHour = tm.Hour;          //passing the time into a var
currentMinute = tm.Minute;    //passing the time into a var
currentDay = tm.Wday;         //passing Weekday
//(Mon - Sun eg 1-7) into var
currentDoM = tm.Day;          //passing day in to var (1-31)
currentMonth = tm.Month;     //passing month into var (1-12)
currentYear = tmYearToCalendar(tm.Year); //passing year to var
}

Right below the moved time declaration part we add the following

lcd.setCursor(0, 0);         //set the cursor to line 1 pos 1
lcd.print(" ");                  //print 15 blanks to delete all
                                     //prior statements
lcd.setCursor(0, 1);         //set cursor to row 2 pos 1
if(currentHour < 10) lcd.print("0");           //if the hour is less than 10
                                                            //we print a 0 to keep 2 digits
lcd.print(currentHour);                            //print current time (hour)
lcd.print(":");                                          //print separator
if(currentMinute < 10) lcd.print("0");        //if the minute is less than
                                                            //10 print 0 to keep 2 digits
lcd.print(currentMinute);                        //print current time (minutes)

The last statement will print the current time generated by the implemented RTC. Now it's time to see if it all works.

If everything went well the sketch will compile and if you have added a delay(1000), in the setup loop just after the lcd.print statement, what ever you wrote in this statement will show up and disappear and the current time will show at the beginning of row 2.
If you are getting an compiler error like:
/Users/dan/Documents/Arduino/libraries/ShiftLCD/ShiftLCD.h:116: error: conflicting return type specified for 'virtual void ShiftLCD::write(uint8_t)'

Please do the following:

Open the whatever/Arduino/libraries/ShiftLCD folder and

In ShiftLCD.h
Change line 116 to virtual size_t write(uint8_t);

In ShiftLCD.cpp
Change line 6 to #include "Arduino.h"
Change line 252 to inline size_t ShiftLCD::write(uint8_t value) {

If you have any further issues, please go through Chris blog, there are lots of explanations how things work. I have it running and compile with Arduino IDE 1.5.6 r2 and a Funduino Uno clone for testing and it is connected now to a stand alone Atmega 328.

In the next post I build the switch shield for the menu entries and start building the menu.

No comments:

Post a Comment