|
Project Information
Featured
|
NOTE: deprecated!Yet updated to Arduino 1.0 as well as pre-1.0 compatible, just in case. Big thanks to florian.fida who posted a huge pointer in Issue #6. Also, as a last update to this library I included a proper LCD initialization, as well as added LCD backlight control from formerly unused shift register bit #1. The reason for deprecating this library, is now twofold:
In addition, Marc made a LCD3wire port that he calls NewLiquidCrystal (without a space), if you have connected your LCD in that way but wants the functionality of this library. But this is also included in Francisco's new library now, so neither that nor this (arduinoshiftreglcd) are really needed anymore... Anyway, below is the old (somewhat updated) description for reference, if needed. Again, it is just a hack from what was mainly Lada Ada's improvement of the then-official (2009) LiquidCrystal library. Quick links
IntroductionThis is a library for connecting an Arduino with only 2 or 3 wires to HD44780-compatible LCD's. This was originally done via a very simple shift register, the 74LS164. It does not latch its outputs, so each output pin reflect the current "shift status" as bits are shifted in. In 2-wire mode this necessitated the enable-of-the-LCD-enable bit to be at the last position. Hence not pin compatible with LCD3wire library. Solutions now exists for latched shift registers as well. Usage#include <ShiftRegLCD.h> ShiftRegLCD objectName(Datapin, Clockpin, Enablepin or TWO_WIRE [, Lines [, Font]]) where Lines and Font are optional.
The compulsory "Hello world" example using a two-wire connection: #include <ShiftRegLCD.h>
const byte dataPin = 10; // SR Data from Arduino pin 10
const byte clockPin = 11; // SR Clock from Arduino pin 11
ShiftRegLCD srlcd(dataPin, clockPin, TWO_WIRE);
void setup()
{
// Turn on backlight (if used)
srlcd.backlightOn();
// Print a message to the LCD.
srlcd.print("HELLO, WORLD!");
}
void loop()
{
}More details on the Usage page. Mundane detailsSince I had an old HD44780 LCD display, I wanted to connect it to the Arduino, and still have some extra IO pins to use for other things than the LCD :) I hope this might be useful for others too. As of now this library seem to be very reliable regarding starting/initializing the display (as opposed to the first version, at least on my LCD). Generating the 8 allowable custom characters are also supported. Examples of usage are included. I'm pretty new to the Arduino, but I have dabbled a little in both electronics and C++ before. But not much, this is the first class or library I've written for C++. Or very C++ like language. Additional, somewhat technical dull detailsLast (ish) update: as of 2012.02.09, I added in a backlight control bit #1 from the shift register (or bit #0 if using Bill's version of tying together CLK and RCK), as well as a proper LCD initialization from the link below. Schematics are not fully updated for now, but there is a backlight "antiflicker" circuit suggestion for 2-wire mode, and 3-wire with an unlatched shiftregister. Do not connect the LCD backlight directly from the shift register to the LCD, use a driver circuit, such as a transistor and resistors. As of 2009.07.27 there is a 2-wire connection mode in addition, and also a new schematics, since the enable of the enable-puls needed to be at the last bit position. Also, a big thanks go to mircho from the arduino forum for pointing out a way of using only two wires! He found it at ScienceProg.com. There should still be the option of using 3 wires as before, if needed (see third schematics). Two ways of connecting to a "shiftregistered" LCD: (With this library)
The time difference is not significant, although 3-wire method is slightly faster. (The clearing of the shift registers in 2-wire mode does not need the delays the LCD needs). In both cases, the two other pins (data and clock) connects to the shift registers respective inputs. Basically any shift register should do. It's very simple, really. Note about latched shift registers (Like the 74HC595):
There is no reading from the LCD, the R/!W pin is therefore hardwired to GND. I was playing with the idea of implementing that while still using the same connections from the Arduino, but now I don't think I'll ever implement that. Note about the diode-resistor AND "gate"Some tweaking might be in order to get this to work. Not all diodes can be used, and maybe you need to change the resistor value. As far as I have been able to determine, the diode needs to have a low as possible junction capacitance (and / or reverse bias capacitance as well). It seems most diodes below 5 pF should work with most LCDs and types if IC's (74HCxxx and 74LSxxx etc, CMOS etc), but I cannot guarantee this, of course. A diode like 1N4148 should work. Also, in a pinch, some small-signal transistor's base-emitter diodes can be used (2N3904 is reported to work). Note about decoupling capacitorsThe shiftregisters themselves cause sudden changes to the current drawn from it's power, and hence introduces noise. To counter this, a "decoupling capacitor" should be used as close to the shiftregister power pins as possible (Vcc and GND). Otherwise, the shiftregister can get faulty data and hence the LCD will not work as intended (shows gibberish characters etc). This is also dependent on other factors, like wire lenghts etc. (Decoupling capacitors are not shown in the schematics). LicenseOriginal version is licensed under Creative Commons Attribution-ShareAlike 3.0 License. I couldn't find that one here (except for other contents than code), so I hope GNU GPL v3 is not too far off from that one. AcknowledgementsThis library would never have been if not for LadyAda's improved version of the Arduino "Official" LiquidCrystal library! Thanks must go to her for all those functions included, and not least a proper initialization routine (At least one that worked reliably, on my LCD's, but I have now changed this completely to the below version). I have finally implemented a proper (real proper this time) LCD initialization. Have a look at this excellent LCD initialization description: Character Based LCD Modules by Don (click on LCD Initialization). mircho from the Arduino forum helped with the two-wire method. Also thanks to florian.fida, CapnBry, Nystrom and Bill for pointing out things! So in short this library is only tweaked to work with a shift register and the shiftOut() function. I used 74LS164. That's not a fancy shiftregister (no tristate nor latching, not bidirectional etc.) but that's what I had at the time. Schematics2-wire schematicsPrinciple of two-wire method with an unlatched shiftregister and an AND gate (The reason I'm not really using a real AND gate is to keep component count down): Not shown: You should use a decoupling capacitor, ca 100 nF across the shiftregisters power pins, as close as possible to to the shiftregister! This goes for all schematics below too.
Unlatched shiftregisterNote, not shown: The power connection for the 74LS164 and decoupling capacitors. Diode: use 1N4148 or equivalent (works with HC family IC's also)
Backlight controlThis prevents most backlight flicker/flimmer from about 20-40 FPS of constant writes to the LCD (also lower FPS somewhat, but some tweaking is neccesary then). At higher (30-40 ish FPS) the flicker is not too noticeable anyway, but maybe even more importantly, it also makes the backlight turn off when off. Or almost so, unnoticeably very very dim light, whithout which it is simply a bit dimmer in 2-wire mode. The RC net and diodes are not needed in 3-wire mode for latched shift registers.
Nystrom's version with a latched shiftregisterThanks to Nystrom who posted it in issue #7) Any small-signal transistor should do, I used BC548B. (Power connections to 74HC595 not shown)
Bill's version with a latched shiftregisterBill's version, who also posted it in issue #7). NOTE Shift register bits are shifted to one lower bit position when connecting SRCLK and RCK together like this.
3-wire schematicsUnlatched shiftregister
Latched shiftregister
|