SOLVED: Struggling with new LiquidCrystal with _SR2W

I'm trying to test 595 in 2 Wire mode with backlight control and I'm struggling a little.

I've been over my wiring time and time again and I'm sure it's right. I've followed the ASCII wiring in the LiquidCrystal_SR2W.h file

Something must be working as I can control the backlight on and off. I then have two screens of test text and an animation for testing. All I'm getting displayed is random characters, although I can see parts of my text in it at times.

The display updates at the times that I would expect it to, and seems to do the animation, albeit it is all pseudo garbage characters, rather than what it should be displaying.

One thing that is also confusing me when I look at the _SR and _SR2W code is that they look to me like they don't use the same wiring.

For SR2W I have Bit 0 (Pin 15) connected to BL control. Bit 1 (Pin 1) is LCD RS. Bit 2-5 (Pins 2 - 5) is LCD D4-D7. Bit 6 (Pin 6) is one end of the diode. The other end of the diode is connected to E, with a 1k resistor between E and Data. Clock is onto Clock and Latch.

The thing that is confusing is that _SR seems to be saying that RS, D4-D7 and the diode are all one bit on.

I understand that using the 595 as non latching means bits are all out by one, but the _SR seems to be referring to the same 595 wiring.

Code is below, wiring is a bit of a mess as it's thrown together on a breadboard. If it's not possible to make any suggestion as to why everything seems to work except for bad characters then I'll rip it apart tomorrow and put back together tidily for some pictures.

My test sketch:-

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_SR2W.h>

const int BACKLIGHT_PIN = 29; // If using ext/pwm backlight pin

// Set the LCD constructor
LiquidCrystal_SR2W lcd1(27, 28, NEGATIVE);

// Creat a set of new characters
const uint8_t charBitmap[][8] = {
   { 0xc, 0x12, 0x12, 0xc, 0, 0, 0, 0 },
   { 0x6, 0x9, 0x9, 0x6, 0, 0, 0, 0 },
   { 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0, 0x0 },
   { 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0, 0x0 },
   { 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0x0 },
   { 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0x0 },
   { 0x0, 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0x0 },
   { 0x0, 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0x0 }
   
};

void setup()
{
    int charBitmapSize = (sizeof(charBitmap ) / sizeof (charBitmap[0]));

  // Switch on the backlight if using the hardware pin
  pinMode(BACKLIGHT_PIN, OUTPUT);
  digitalWrite(BACKLIGHT_PIN, LOW);
  
  lcd1.begin(16,2); // initialize the lcd for a 16x2 panel
  
  lcd1.setBacklight(1); // switch on the backlight if being controlled via SR

  for ( int i = 0; i < charBitmapSize; i++ )
   {
      lcd1.createChar ( i, (uint8_t *)charBitmap[i] );
   }

  lcd1.home(); // set LCD cursor to the home position
  lcd1.print(F(" Hello, Testing "));  
  lcd1.setCursor(0, 1); // set cursor to the first character of the second line
  lcd1.print(F(" SR2W  Backpack "));
  delay(2000);
  lcd1.home(); // set LCD cursor to the home position
  lcd1.print(F("  Using HC595   "));  
  lcd1.setCursor(0, 1); // set cuirsor to the first character of the second line
  lcd1.print(F(" Shift Register "));
  delay(2000);
  delay(4000);
}

void loop()
{
   lcd1.home();
   // Do a little animation by writing to the same location
   for ( int i = 0; i < 2; i++ )
   {
      for ( int j = 0; j < 16; j++ )
      {
         lcd1.print (char(random(7)));
      }
      lcd1.setCursor ( 0, 1 );
   }
   delay (500);
}

Struggling with new LiquidCrystal with _SR2W

I tried to tell fm that this was a poor choice for the program name....

Have you checked the date on that program. If it's the one I think it is then it is far from 'new'. Of course if you posted a link to the library we would be able to tell for sure.

Don

Don, it's v1.2.1 I'm using

Looks like there is still activity on this but no new packaged download for a while. I just had a quick look at the pull request and see some work on 1W mode, where the connections on 595 seem to be different again. I don't understand why the wiring keeps changing.

I'll have look through again tomorrow and see if I can get this working somehow.

Thanks

ok,
So I'm not only the author of SR2W but I'm also the guy that picked the name.
I've seen the comment before, but I really don't get the "it's not a good name"

tack:
Don, it's v1.2.1 I'm using

Looks like there is still activity on this but no new packaged download for a while. I just had a quick look at the pull request and see some work on 1W mode, where the connections on 595 seem to be different again. I don't understand why the wiring keeps changing.

tack,
The wiring is not changing.
fm's library allows operation in many modes to support many different
interfaces, circuit designs, & backpack designs.
The reason that there as not been any new packaged download for a while is the code is stable
and there was no need for a code update.
What you see with respect to SR1W is recent work to provide a new mode of operation.
It allows talking to the SR using only a single Arduino pin.
The circuitry and code as been optimized such that updates
to the LCD using a single Arduino pin is actually faster than the stock
LiquidCrystal library that uses 6 pins.
The one wire mode is pretty cool since it allows using 3 wire connectors
that are used on many of the sensor shields for the connections to a backpack
using this 1 wire circuit.
I've done quit a bit of testing on the new SR1W code and circuitry.
At some point there will be an updated library that includes
this new SR1W code, updated SR code to add backlight control,
and a new i2c interface that adds support for MCP23008 i/o expander chips
for backpacks like the onces from Adafruit and HongKong.
The code isn't quite ready yet.

SR and SR2W do use the same output bits and wiring when in 2 wire mode.
In fact you can switch between the two interface classes with no wiring changes.
The constructors are parameter compatible.
i.e. you can simply change LiquidCrystal_SR(DataPin,ClockPin, polarity)
to LiquidCrystal_SR2W(DataPin, ClockPin, polarity)

I do think the comments/documentation in SR needs a big update as it isn't clear
how it should be wired up.
I've got a big update for SR, that hasn't made it back into the source tree and into
distribution yet. It adds backlight control, includes ascii schematics and clears
up the information about wiring.
In a sense, this update will obsolete SR2W since the wiring (and constructor [other than name])
is the same when using SR in 2 wire mode.

For example here is the updated bit descriptions for SR:

// Connection description:
//
// SR output:
// Bit #0   - N/C - not connected, used to hold a zero in 2 wire mode
// Bit #1   - optional connection to backlight circuit
// Bit #2   - connects to RS (Register Select) on the LCD
// Bit #3   - connects to LCD data inputs D4
// Bit #4   - connects to LCD data inputs D5
// Bit #5   - connects to LCD data inputs D6
// Bit #6   - connects to LCD data inputs D7
// Bit #7   - enables the LCD enable-pulse (not used in 3 wire mode)
//           (2 wire mode: via the diode-resistor AND "gate")

And here is the added ascii schematic for 2 wire mode:
(which matches the schematics for SR2W)
I've updated the schematics to include the actual resistor and diodes that I use
in my circuits.

// ===========================================================================
// Wiring when using 2 Arduino Pins (data pin), (clock pin)
// Constructor: blpolarity is optional and is POSITIVE or NEGATIVE
// 
//  LiquidCrystal_SR lcd(DataPin, ClockPin, [, blPolarity] );
// ===========================================================================
// 
// 2 pin Wiring for a 74LS164
// --------------------------
//                          4.7k
//              +--------[ Resistor ]--------+---(LCD Enable)
//              |                            |
//              |          74LS164    (VCC)  |
//              |        +----u----+    |   _V_ diode 1N4148
// (data pin)---+---+--1-|A     VCC|-14-+    |
//                  |    |         |         |
//                  +--2-|B      Q7|-13------+
//                     3-|Q0     Q6|-12--(LCD D7)
// (BL circuit)--------4-|Q1     Q5|-11--(LCD D6)
// (LCD RS)------------5-|Q2     Q4|-10--(LCD D5)
// (LCD D4)------------6-|Q3    /MR|--9--(VCC)
//                   +-7-|GND    CP|--8--(clock pin)
//                   |   +---------+ 
//                   |      0.1uf
//                 (gnd)-----||----(VCC)
// 
// (LCD RW)--(gnd)
//
// ---------------------------------------------------------------------------
//
// 2 pin Wiring for a 4094
//------------------------
// 
// NOTE: pin 1 is not connected to pin 2
// 
//                          4.7k
//                 +----[ Resistor ]----------------+---(LCD Enable)
//                 |                                |
//                 |      74HC4094                  |
// (data pin)------+       HEF4094    (VCC)         |
//                 |     +----u----+    |           |
// (clock pin)+----|---1-|STR   VCC|-16-+           |
//            |    |     |         |    |           |
//            |    +---2-|D      OE|-15-+          _V_ diode 1N4148
//            |          |         |                |
//            +--------3-|CP    QP4|-14--(LCD D5)   |
//                     4-|QP0   QP5|-13--(LCD D6)   |
// (BL circuit)--------5-|QP1   QP6|-12--(LCD D7)   |
// (LCD RS)------------6-|QP2   QP7|-11-------------+
// (LCD D4)------------7-|QP3   QS2|-10
//                   +-8-|GND   QS1|--9
//                   |   +---------+
//                   |      0.1uf
//                 (gnd)-----||----(VCC)
// 
// (LCD RW)--(gnd)
// 
// ---------------------------------------------------------------------------
// 
// 2 pin Wiring for a 74HC595
// --------------------------
// NOTE: the 74HC595 is a latching shift register. In order to get it to operate
// in a "non latching" mode, RCLK and SCLK are tied together. The side effect of this
// is that the latched output is one clock behind behind the internal shift register bits.
// To compensate for this the wiring is offset by one bit position lower.
// For example, while the backlight is hooked to Q0 it is still using bit 1 of
// of the shift register because the outputs are 1 clock behind the real internal shift
// register.
// 
//                         74HC595    (VCC)
//                       +----u----+    |  +-----------------------(BL circuit)
// (LCD RS)------------1-|Q1    VCC|-16-+  |  +--------------------(data pin)
// (LCD D4)------------2-|Q2     Q0|-15----+  |      4.7k
// (LCD D5)------------3-|Q3    SER|-14-------+---[ Resistor ]--+--(LCD Enable)
// (LCD D6)------------4-|Q4    /OE|-13--(gnd)                  |
// (LCD D7)------------5-|Q5   RCLK|-12-------+                 |
//                       |         |          |                 |
//              +------6-|Q6   SCLK|-11-------+--(clock pin)    |
//              |      7-|Q7    /MR|-10--(VCC)                  |
//              |    +-8-|GND   Q6'|--9                         |
//              |    |   +---------+                    diode  _V_ 1N4148
//              |    |      0.1uf                               |
//              |  (gnd)-----||----(VCC)                        |
//              +-----------------------------------------------+
// 
// (LCD RW)--(gnd)
// 
//
// Example Backlight Control circuit
// ---------------------------------
// Because the shift resiter is not latching the outputs, the backlight circuitry
// will "see" the output bits as they are shifted into the shift register which
// can cause the backlight to flicker rather than remain constantly on/off.
// The circuit below slows down the transitions to the transistor to remove
// the visible flicker. When the BL input is HIGH the LCD backlight will turn on.
//
//                (value depends on LCD, 100ohm is usually safe)
// (LCD BL anode)---[ resistor ]---(VCC)
//
// (LCD BL cathode)-------------------------------+
//                                                |
//                                                D
//                                                |
// (BL input)----[ 4.7k Resistor ]----+-------G-|-<  (2N7000 FET)
//                                    |           |
//                          (0.1uf)   =           S
//                                    |           |
//                                  (gnd)        (gnd)
// 
// 
//
// ---------------------------------------------------------------------------

In terms of why it isn't working, things must be fairly close since you can control the backlight.
Are you using the decoupling cap on the 595?
What type of diode are you using?

Other than that, maybe you could post a photo of your circuit and we could take a look at and
add a second eyes to see if there is any kind of "oops..." going on.

--- bill

So I'm not only the author of SR2W but I'm also the guy that picked the name.
I've seen the comment before, but I really don't get the "it's not a good name"

Here's what I asked fm when he announced the 'New LiquidCrystal' library here: --> New LiquidCrystal library - LCD library - Displays - Arduino Forum;

"I haven't had a chance to look at your library yet but I do have a problem with the name "New Liquid Crystal". My question is what are you going to call the next version of the library?"

Don

OK, I've taken it apart and rewired from scratch a lot tidier with short pieces of wire.

I'm using a 1N4001 diode as that is what I have available.

Looking at he breadboard image the4 connections at the top are from a Shift output on my board.:-

Purple = GND
Grey = 5V
Blue = Data
Green = Clock

I've shown a picture of my board and how these connect. Just to be sure I have tried using some other pins on the board as Data/Clock to make sure that it wasn't an error in my pin mapping. I get the same behaviour.

I've also show a close up of the wiring from the LCD. This has now been kept in a logical order from left to right to reflect the LCD connections of pin 1 (VSS) to pin 16 (K - cathode of backlight LED).

At the moment I have 5V to A and then K connected to pin 15 of the '595. This has the '595 sinking the backlight LED current and set up in the constructor as negative polarity.

The data must be getting to the shift register OK as I can change my sketch to flash the backlight and it works exactly as coded. The problem is with the character display, so some data is going wrong somewhere.

Thanks for your help.

tack:
I'm using a 1N4001 diode as that is what I have available.

Nope, no good. I tried using a 1N4001 and it worked, kind of, by playing with the resistor value. But it only worked for certain precise input voltages (I was playing with different power supplies). Change the voltage by 0.1V and it's back to garbage.

The 1N4001 has too much internal capacitance. See:

http://code.google.com/p/shiftreglcd123/wiki/Hardware

This method relies on a "quick'n'dirty" diode-resistor AND "gate" (you can also use a real AND gate of course).

The diode characteristics are very important, not every diode works the same. Also important are the series resistor, and probably also what type of LCD you got. You need a small signal diode with the least amount of junction capacitance possible, although I have found some ways to get other diodes to work too. No guarantee that it will work, though.

Diodes that should work:

1N4148
1N914
Even a 2N3904 NPN transistor's B-E diode works, in a pinch.

A very short list, and I'm sure lots of other diodes fit the bill. Generally, I think diodes with less than about 5 pF junction capacitance should work (not confirmed). But this is dependent on a lot of factors.

Diodes that probably don't work:

1N4001
BYV95

Generally, (rectifier) diodes with more than 10-15 pF junction capacitance will probably not work.

Experimentation might be called for to get this to work, if it doesn't work "out of the box".

Ahhhh, brilliant. That's probably my problem then. Thanks for the input.

Off to order some correct diodes...

Yep. That is why I asked what diode was being used.
Note the updated ASCII schematic.
It specifies using 1n4148 and 4.7k resistors.
These components are much more stable.
Also, I wouldn't drive the backlight directly from the 595 particularly when
using the part in non latching mode.

Note that without the r/c dampening like what is in the sample backlight circuit
in the ASCII schematic, the backlight will flicker quite a bit as the bits
transition across the backlight output control pin of the 595.
This will be noticeable under heavy LCD updates, particularly if the backlight
was set to be off.

--- bill

That's OK Bill, the hard sinking of the backlight was just for quick and easy testing. I just wanted to confirm the circuit I've drawn up in Eagle.

I've already got a PCB design using I2C, with 2 x PCF8574 that does a dual LCD/Keypad on the same 23mm x 48mm backpack. This allows different methods of operating backlight and contrast, plus a backlight resistor or optional short to cater for different LCD's. I'll be adapting that to create a 2W SR backpack and it will use a transistor to switch the backlight.

Once I have this working I will test the transistor and with the added capacitor you recommended, before I send off for a first set of prototype boards.

I'll also look at that 1W schematic and probably end up making a 1W backpack, unless it might be possible to design a dual function board that can be switched 1W/2W via some jumper settings.

Thanks again for your help. I'll have to wait a couple of days for 1N4148 diodes to arrive before trying again.

1N4148 diodes arrived. Problem solved. :slight_smile: