loading

LCD's generally need 11signal lines + 3 or 5 lines for Vcc, ground and contrast and in some cases an extra 2 for background light.

Using the LCD in 4 bit mode saves 4 pins, but often that is not enough. Although it is possible to use an I2C module to control the LCD with two wires via the I2C port, there are situations in which that is unpractical, e.g. when u need al analog ports and cant sacrifice A4 and A5 for SDA and SCL.

In that case using a shift register can be a solution.

I am using a 74164 shift register with only a few additional components to do what I need and it can easily be put on a piece of stripboard

BOM
74LS164
1N14148
2x1k resistor
1x1k variable resistor

The stripboard version follows the standard lay-out for most LCDs with a SIL pin lay-out. However, I also had an LCD, a Seiko M1602, that had a two line pin lay-out for which i made a dedicated version.

For the program I use the LCD library from Malpartida.

#include <LiquidCrystal_SR>
LiquidCrystal_SR lcd(8,7,TWO_WIRE);
//                   | |
//                   | \-- Clock Pin
// \---- Data/Enable Pin
void setup(){ lcd.begin(16,2); // initialize the lcd
lcd.home (); // go home // } void loop()
{
lcd.home (); lcd.print("LiquidCrystal_SR"); lcd.setCursor (0, 1 ); lcd.print("2 wire");
}

There u go.
Just one more thing. In mu circuit I feed the backlight directly from a 5Volt voltage through a resistor. But as you can see the Shift register still has empty pins. I believe pin 4 carries the backlight on/off signal and if you'd like you could pick up the signal from there, feed that to a BC547 that then can switch the backlight on and off by software.
On the "Next" page I will discuss how to make this work for an Attiny85

Step 1: 2-Wire LCD for an Attiny85

If there is a chip that will benefit from needing only 2 pins for the LCD, it is the 8 pin Attiny85/45/25. With pins being reserved for power supply and reset, there are in fact only 5 pins left to use. and though it is possible to implement an I2C protocol in that chip, using a shift register is probably easier.

In its most basic setting the Attiny85 only needs one pull-up resistor.

In order to use the Attiny with the Arduino IDE you need to install an attiny core. I presume that to be well known to most people working with an attiny. However, not all cores are equal and some will give you error messages when using specific libraries or functions. The 'print.h' override is a known one when using print statements or libaries on the attiny. Though that is easy to correct in the print.h and print.cpp files but chances are then an error will pop up in another core file like the hardwareserial.h.

it is easier to use a core that is known to work. The Attiny corefrom David Mellis works in this setting.

A program would look like this:

#include <LiquidCrystal_SR.h>
LiquidCrystal_SR lcd(0,2,TWO_WIRE);
//                   | |
//                   | \-- Clock Pin
//                   \---- Data/Enable Pin<br>void setup(){
  lcd.begin(16,2);               // initialize the lcd
  lcd.home ();                   // go home
  lcd.print("LCD with 2 wires");
  lcd.setCursor ( 0, 1 ); // go to position
  lcd.print("on Attiny85");
}<br>void loop(){
}

By no means do I want to claim my work in this is original: the core is not mine, the library is not mine and the idea of using a 164 shift register is not mine. I just pull it together here in a practical, working example.

Just a remark. Althoigh I removed the 'br' linebreak html codes a dozen times from the program listing, they keep coming back. So if you copy this program make sure you replace any br codes (the ones between the 'fish hooks') by a linebreak

NOTE
I noticed some problems that can occur if you are using the I2C port on the Attiny85 via the TinyWireM library as I was unable to read a BMP180 sensor. I have not pinpointed the cause yet. However, if you are implementing an I2C protocol on your Attin85, there is not much reason to use the SR backpack for your LCD anymore. Better use I2C then


Step 2: Two Wires 8 Bit

8 bit Two wires

Previous circuits are all for LCD in 4 bit mode as that is the most often used mode. However, Mike MacLaren pointed me to a circuit that uses a shiftregister (either a 164 or a 595) that uses two wires and does full 8 bit addressing of the LCD

Two Wire 8bit LCD with 164 Shiftregister Two Wire 8bit LCD with 164 Shiftregister[/caption]

The above circuit uses an HC164 shiftregister, but Mike's site also has a circuit for a 595 and a driver program for a PIC as well as an Arduino microprocessor. This circuit does not cater for software backlight control, but it has full 8 bit control, should you need that

<p>Hi all, I had my display on a 595 with LiquidCrystal595 library and 3 wires, controling the backlight from software, but due to pin shortage, I decided to go for the 2 wire interface with the 74LS164.</p><p>My problem is I cannot make the backlight work through the transistor. Everything else works great, the backlight works great if connected without the transistor.</p><p>I was checking the LiquidCrystal_SR .h and .cpp files to discover the setBacklightPin, that needs to exist prior to setBacklight, but it seems I am missing something.</p><p>I could stick with the LCD permanently on, but I need to turn it of through software.</p><p>Anyone can Help?</p>
<p>how exactly have you connected it with the transistor?</p>
<p>Hi, i connected everything like the schematic in my picture. But as I understand, I need to trigger the Qb pin (pin4) of 74ls164 to change the state of BC547 so as to allow (or not) current to pass through the cathode pin of the display.</p><p>Currently, the display works, but without the backlight, unless i connect the cathode directly to ground through a resistor, bypassing the use of the transistor.</p><p>My problem is probably on the software side, as i have to trigger the Qb pin to go from LOW to HIGH and vice versa. But I cannot figure out how. I am using the LiquidCrystal_SR library</p>
<p>what command are u using to switch on the backlight. Just to make sur, could u measure the level on pin4?</p>
<p>As my lcd is one without a backlight i can not try it, but have you tried</p><p>lcd.setBacklightPin(4,POSITIVE);<br> <br> lcd.setBacklight(HIGH);<br> lcd.setBacklight(LOW);</p><p>lcd.noBacklight();</p><p></p>
<p>Hi, thanks for your help, it was valuable.</p><p>I was actually looking at the LiquidCrystal_SR2W.h.</p><p>I made some tests but although it is working, it is &quot;kind of&quot; working. </p><p>I managed to set the display to LOW (mine is negative) to turn on the backlight, but then, everything I print with lcd.print comes out with random characters on random positions on the display.</p><p>What did the trick to manage to display something on the screen was to set the backlight to HIGH (turn screen off), then write anything, and without any delay of any sort, to set the backlight to LOW again, turning on the screen, and showing anything that I sent. This produces a flickering. If at some point I write something on the screen with backlight turned on, it messes everything again. </p><p>These were my observations!</p><p>Thanks again</p>
<p>ok good to hear. backlight flickering is an issue with this setup/ i understand that if you feed the base of the transistor that switches the backlight, through a diode and stabilize the signal with a 1uF capacitor the flickering is gone.</p><p>so it is Qb -1k resistor-1uF to earth-diode, base of transistor</p>
<p>Although the flickering (for me at least) comes from software, where I have to turn off the backlight in order to display something, then immediately turn it on, I will definitely implement the above.</p><p>Thanks for the nice project and your help!!</p>
<p>my pleasure. currently busy with 1 wire lcd</p>
<p>ok you may want to try:</p><p>LiquidCrystal_SR2W.h</p><p>rather than</p><p>LiquidCrystal_SR.h</p><p>assaid, i cannot try it as my lcd doesnt have a backlight</p>
<p>ok, did some more digging. For one, the lcd i used doesnt have a backlight so i never really came upon this problem.</p><p>But a quick look at the library did some explaining.</p><p>For one thing, apparently you need to set the setBacklightPin(pin, polarity), but apparently the 'setBacklight or backlight() routinesare not implemented in the SR. The routines are present but empty.</p><p>As I understand, the SR library from Malpertida is based on the ShiftregLCD123 library and that HAS the routines, but obviously I am not sure if that is easy to port and as I understandthe shiftreglcd123 library expects the backlight on bit 0 or 1. Perhaps that can help u further. </p><p><a href="https://code.google.com/archive/p/shiftreglcd123/downloads">https://code.google.com/archive/p/shiftreglcd123/d...</a></p>
<p>I'm trying to make this work with an ATTiny85, but when I try to use the code, I get an error that there is no wire.h file. Would you please tell me where to get the wire library? </p>
<p>That is odd, as the Wire library should be included with your Arduino install.<br>But you may check here: <a href="https://code.google.com/p/arduino/source/browse/trunk/libraries/Wire/?r=1092" rel="nofollow"> https://code.google.com/p/arduino/source/browse/t...</a><br>But are you sure you selected the right lcd library? Coz as far as I know wire.h is not necessary for this.<br>Make sure you check yr sketchbook/libraries folder to see if you maybe still find the wire library there.<br>I use the LCD library from Francisco Malpertida </p>
I got the libraries straight with your help. Everything compiles regarding wire.h, etc. When I bought the shift register ICs, I didn't realize that I got the 74LS164N version instead of the 74LS164 version. I cannot find out what the difference is anywhere. TI has a very nice datasheet for the 74LS164 version, but I cannot find an equivalent for 74LS164N. Do you know if there is a difference? If so, are there any tweaks that could make the N version work? I really want to get this working--I'll buy the non-&quot;N&quot; version, if I have to.
<p>I am not entirely sure but I think the N only refers to the package. Fairchild has a datasheet mentioning the 'N' version: </p><p>http://pdf.datasheetcatalog.com/datasheets/70/232399_DS.pdf</p>
<p>Thanks for the quick response. I've made a big mess out of my libraries and will try to make it more organized or go to a different PC altogether. In my efforts, I have run into issues with LiquidCrystal_SR.h calling LCD.h calling Arduino.h (which I don't have, either). I am now using new_liquidcrystal which has a bunch of header files. Eventually, I want to do your Mini Weather Station project, but there I am in trouble with manchester.h and can only find MANCHESTER.h. Oh my! I have been successful with using RF RX and TX for temperature on a combination of arduino nano and arduino mini, but I want to do it with the ATTiny85--like you do it. I'll try to set up on a different PC, and get my libraries straight. If all else fails, I'll use my Ubuntu box and try it there. I'll likely be back for more advice.</p>
<p>sorry for my late response on this one, but somehow i seeemd to have overlooked it. The Arduino.h comes with the arduino install package so ineed it seems like you made a bit of a mess, but i understand u have it sorted out now.</p>
<p>Got everything working. Now for the weather station.</p>
<p>Great, glad to hear that</p>
<p>Does this also work with an 74HC595N Shift register ?</p>
<p>try these</p>
<p>I found a circuit for you: http://i557.photobucket.com/albums/ss11/rar0n/Electronics/Arduino/LCD_4-bit_serial_converter_2-wire-latching.png</p>
<p>Martin, in principle yes, but it won't be a 1 on 1 swap as they are not pin compatible.. The New LCD library of Francisco Malpertida works with HC595 as well.<br>I must say though that most circuits I have seen with a 595 require 3 pins, even the Adafruit LCD backpack.<br>But if you specifically want to use a 595, then consider using it as a ONE wire interface: </p><p>https://code.google.com/p/shiftreglcd123/wiki/Hardware</p>
Ok.. its only because i dont know where to get an 74LS164 shift register. If i enter at amazon i get only the 74HC595N as a reply. The other one seems unknown...
<p>that surprises me. Maybe amazon doesnt have it because it is slightly less popular than the 595. Mercateo in &Ouml;sterreich has it, but they are quite expensive with sending. </p><p><a href="http://www.mercateo.at/p/1331-1178439/74LS_74LS164_DIP14_7V.html?switchToCountry=at&chooseGeo=true" rel="nofollow">http://www.mercateo.at/p/1331-1178439/74LS_74LS164...</a></p><p>You can find 10 of them for 3 euro's (or a 100 of them for a bit more) at Aliexpress: </p><p><a href="http://www.aliexpress.com/item/Midas-Free-Shipping-10-PCS-LOT-74LS164N-74LS164-LS164-SN74LS164N-DIP-14-8-BIT-PARALLEL/32298718020.html" rel="nofollow">http://www.aliexpress.com/item/Midas-Free-Shipping...</a></p><p>Could probably find them in any electronic shop in &Ouml;sterreich but as it will cost you maybe 3 euro's in gas and parking, I'd pick delivery from aliexpress</p>
<p>I can't wait for the coming tutorial of Attiny85 version.Thanks</p>
<p>That is simple: click on the NEXT button and you will see it</p>

About This Instructable

14,177views

106favorites

License:

Bio: I am a physician by trade. After a career in the pharmeceutical world I decided to take it a bit slower and do things I ... More »
More by diy_bloke:Working With the Funduino W5100 Ethernet Module. Uploading Data to ThingSpeak With MQTT Adding an MCP23017 I/O Extender to Arduino or ESP8266 
Add instructable to: