Arduino LiquidCrystal library

RGB backlight, negative display LCD

As I’ve been progressing on the sous vide controller, I’ve been playing with the LCD 16×2 character display screen that I’m going to put on it. It’s a negative display, RGB backlighted steal of a deal from Amazon.

In this process I got interested in ways to drive the LCD, things like using shift registers and even this amazing Shift1 system to control a whole LCD through a shift register with 1. single. pin. Rather than download various hacked libraries from different sources, I wanted a “standard” library that yet supported all these methods. I wanted support for latching shift registers, registers without latches, and of course shift1, all in the “standard” lib.

So, I did some minor refactoring of the arduino core LiquidCrystal library and extended it with a few more constructor options. You can pass it 3 pins to use a latching shift register where everything goes through the register using just shiftdata, shiftclock, and shiftlatch. You can also pass it a separate enable pin, for 4 pins total, which should speed things up marginally as it doesn’t have to shift the whole register for each LCD enable clock edge up and down. And of course you need that enable pin to use a non-latching register (or a latching register with latch tied to clock), and you can pass 255 as the shiftlatch pin and the library won’t try to use another pin for it.

Then there’s my favorite, the callback function method. You simply define a function that takes three uint8_t types, value, mode, and nbits. The value parameter is the bits the library wants to pound into the LCD, the mode is what it wants the RS pin set to, and nbits is just somewhat of a sanity check, but you can safely ignore it if your function assumes the same nbits that you passed to the constructor. You could write a single function that can do either 4 bit or 8 bit mode, and checks nbits to do either one.

Here’s an example of just how easy it is to use the callback, as well as a link to the github project. If you just use the shift1 library, your custom callback can easily call into the shift1 library to drive your LCD, no need for hacking shift1 directly into the LCD library!