LCD Shifter for Arduino

30,584

44

54

Posted in TechnologyArduino

Introduction: LCD Shifter for Arduino

The original idea was to create a library that simplify the use of IC 74HC595 between Arduino and other hardware. In this Instructable I will share this to you using as example the control of a 16x2 LCD.
The example will show on the LCD the seconds that has passed since Arduino was restarted.

I hope it will be useful to you.

What do you need for THIS example?
- Arduino
- Arduino IDE installed
- LCD
- One IC 74HC595
- One 4.7Kohm resistor or similar
- One "104" capacitor
- Wires!

Step 1: Place the Library Under Arduino Folder

I've named the library "ShiftOut". It goes under %arduino-directory%/hardware/libraries

This one is the library that I've programmed. Comments are welcome.

Step 2: LCD Library

The second library needed is the one that communicate to the LCD. I've used this one and not the one that came with Arduino because it's an initialisation bug.

It's based on www.slashdev.ca/arduino-lcd-library/ and has the necessary changes to integrate the ShiftOut Library that I made.

This must be uncompressed under %arduino-directory%/hardware/libraries too.



Step 3: Open Arduino IDE

Now it's time to write the code. Open Arduino IDE and write this:

#include <Lcd.h>
#include
<ShiftOut.h>

ShiftOut sOut(8, 12, 11, 1);
Lcd lcd = Lcd(16, FUNCTION_4BIT | FUNCTION_2LINE | FUNCTION_5x11, &sOut);
 
void setup()
{
  lcd.set_ctrl_pins(CTRLPINS(1,2,3)); // RS->1, RW->2, E->3
  lcd.set_data_pins(_4PINS(4,5,6,7)); // D4->4, D5->5, D6->6, D7->7
 
  lcd.setup();
 
  lcd.clear();
}
 
void loop()
{
  lcd.home();
  lcd.print((long)millis() / 1000);
}

This simple sketch shows on the LCD the seconds that has passed since Arduino was restarted.


Step 4: Compilation

It's important that the libraries are copied before Arduino IDE is open. Otherwise the compilation could fail.

If everything was OK, you could connect Arduino to a 74HC595 and this one to a LCD following the schematic images diagrammed using Fritzing.

The connection should be as follow:

Step 5: Run the Sketch on Arduino

If everything is connected right, you should see the counting seconds on the LCD.





Step 6: Conclusion

I hope this library will be useful for someone. It's to me because the Arduino code gets simple and nice, without filling it with collateral coding messing the sketch main purpose.

Regards!

Step 7: Bonus Track: Another Example

Here is Arduino using ShiftOut to control two seven segment displays in cascade:




More info could be found here: http://gusps.blogspot.com/

Share

    Recommendations

    • Microcontroller Contest

      Microcontroller Contest
    • Science of Cooking

      Science of Cooking
    • Pocket-Sized Contest

      Pocket-Sized Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    54 Comments

    Hi,
    Having problems compiling this script example.
    I might have missed something vital?
    Have the libraries saved in the location specified.
    Using Arduino UNO R3 and 1.0 IDE

    Here are the error messages...
    Its probably something simple on my part but can't work out what it is.

    Any help appreciated.

    Thanks
    Struggler

    C:\arduino-1.0\libraries\Lcd\Lcd.cpp:26:27: error: WConstants.h: No such file or directory
    C:\arduino-1.0\libraries\Lcd\Lcd.cpp: In member function 'void Lcd::send(uint8_t, uint8_t)':
    C:\arduino-1.0\libraries\Lcd\Lcd.cpp:65: error: 'delay' was not declared in this scope
    C:\arduino-1.0\libraries\Lcd\Lcd.cpp: In member function 'void Lcd::set_enable(uint8_t)':
    C:\arduino-1.0\libraries\Lcd\Lcd.cpp:113: error: 'delayMicroseconds' was not declared in this scope
    C:\arduino-1.0\libraries\Lcd\Lcd.cpp: In member function 'void Lcd::pulse_enable()':
    C:\arduino-1.0\libraries\Lcd\Lcd.cpp:119: error: 'HIGH' was not declared in this scope
    C:\arduino-1.0\libraries\Lcd\Lcd.cpp:120: error: 'delayMicroseconds' was not declared in this scope
    C:\arduino-1.0\libraries\Lcd\Lcd.cpp:121: error: 'LOW' was not declared in this scope
    C:\arduino-1.0\libraries\Lcd\Lcd.cpp: In member function 'void Lcd::check_bf()':
    C:\arduino-1.0\libraries\Lcd\Lcd.cpp:131: error: 'INPUT' was not declared in this scope
    C:\arduino-1.0\libraries\Lcd\Lcd.cpp:136: error: 'HIGH' was not declared in this scope
    C:\arduino-1.0\libraries\Lcd\Lcd.cpp:137: error: 'digitalRead' was not declared in this scope
    C:\arduino-1.0\libraries\Lcd\Lcd.cpp:138: error: 'LOW' was not declared in this scope
    C:\arduino-1.0\libraries\Lcd\Lcd.cpp:148: error: 'OUTPUT' was not declared in this scope
    C:\arduino-1.0\libraries\Lcd\Lcd.cpp: In member function 'void Lcd::setup()':
    C:\arduino-1.0\libraries\Lcd\Lcd.cpp:174: error: 'OUTPUT' was not declared in this scope
    C:\arduino-1.0\libraries\Lcd\Lcd.cpp:180: error: 'OUTPUT' was not declared in this scope
    C:\arduino-1.0\libraries\Lcd\Lcd.cpp:186: error: 'delay' was not declared in this scope
    C:\arduino-1.0\libraries\Lcd\Lcd.cpp:195: error: 'delayMicroseconds' was not declared in this scope
    C:\arduino-1.0\libraries\Lcd\Lcd.cpp:206: error: 'delayMicroseconds' was not declared in this scope
    C:\arduino-1.0\libraries\Lcd\Lcd.cpp: In member function 'void Lcd::dWrite(uint8_t, uint8_t)':
    C:\arduino-1.0\libraries\Lcd\Lcd.cpp:348: error: 'digitalWrite' was not declared in this scope
    C:\arduino-1.0\libraries\Lcd\Lcd.cpp: In member function 'void Lcd::pMode(uint8_t, uint8_t)':
    C:\arduino-1.0\libraries\Lcd\Lcd.cpp:355: error: 'pinMode' was not declared in this scope

    1 reply

    Hi. It seems that the installation have some issues. Does other projects work well?
    If "yes", maybe this instructions are not compatible with Arduino UNO R3. I remember to did this with Arduino 0015 or 0017. Try to use it instead.

    Maybe other user can confirm if this works on Arduino UNO IDE.

    I'll do the tests one of these days and tell you if it worked.

    Thanks.

    Thanks to your instructable (This one) I've managed to follow it to the letter and I've produced this.

    Thank you

    Am-OUGACMAEiXKL.jpg large.jpg
    1 reply

    Oww!!... Thanks!. I really apreciate your comment. Makes me willing to do another instructable ;p

    Regards!...

    The Code provided up above gives me an error, while compiling/verifying. Please Help.

    2 replies

    I meant in Step 3, of this tutorial.

    Hi marker4455. Which error do you get?

    I've Forgot to mention that I'm using arduino 0022.

    1 reply

    I guess that the IDE version doesn't matter in this case.

    Can you explain the problem with some more details?
    Thanks.

    I've built a simple header for this project and everything seems to be fine, it works perfect. However, when using ONLY the 5v power supply, it don't work out - in this case the arduino is not connected to the PC. I saw your comment about the initialization bug in the original liquid crystal library and I'm wondering if it's not the cause of this issue ...

    Please?

    1 reply

    But, are you powering Arduino with an external 9v and using 5v regulated from Arduino?

    Just wondering if you could do a more advanced version of this tutorial, say for example hooking up a keypad to the LCD display.

    Hello, please correct the first line
    wich says: #include < Lcd.h>;
    must says: #include WITHOUT THE SPACE :)

    Thanks for your work

    sorry for my english

    1 reply

    Done!
    Thanks for telling....

    I'm trying to follow this instructable, but you've forgotten to list the wire diagram, what pin connects to what wire on the LCD screen?

    I would love to include this in a huge project I currently have planned, but without the pin layout I will have to guess at it.

    3 replies

    Hi.
    It's on the 4th step, 2nd image.

    I managed to get it to work, thanks for taking the time and effort to help me, when I do my big project I'll acknowledge you in the credits

    The image is from left to right, pin1 to last pin on the LCD. Look for the comment below about the type of LCD i've used.
    Let me know if that help you...

    is it posible to use custem characters with this librarie
    cus i cant get it to work....

    1 reply