2-Wire LCD Interface for Arduino or Attiny (updated June 2016)

by diy_bloke in Circuits > Arduino

27690 Views, 116 Favorites, 0 Comments

2-Wire LCD Interface for Arduino or Attiny (updated June 2016)

2wire-p1050315e.jpg
2wire-lcd2wire.jpg
2wire-lcdshift.jpg
2wire-74sr-lcd.png
2wire-seikom1632.png
2wire-m1632.jpg

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
1N4148
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<br>//                   \---- Data/Enable Pin<br>void setup(){
lcd.begin(16,2);               // initialize the lcd<br>lcd.home ();                   // go home
//
}
void loop()<br>{<br>lcd.home ();
lcd.print("LiquidCrystal_SR");
lcd.setCursor (0, 1 );
lcd.print("2 wire");<br>}

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

2-Wire LCD for an Attiny85

2wire-img_20150316_210709.jpg
IMG_20150316_210943.jpg
IMG_20150316_210657.jpg

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


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