0

LCD Backpack Sketch Query
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

LCD Backpack Sketch Query

by _phillip on Sun Jun 13, 2021 1:58 pm

I have been testing/modifying various LCD backpack sketches with the following hardware:

Adafruit Feather MO WIFI board
Adafruit LCD: #181 https://www.adafruit.com/product/181
Adafruit LCD Backpack: #292 https://www.adafruit.com/product/292

The successful sketch is Adafruit's 'HelloWorld_12c'
I say 'successful' because it worked for me after a few simple changes.

Adafruit's sketch initializes the backpack via the I2C snippet:
Code: Select all | TOGGLE FULL SIZE
Adafruit_LiquidCrystal lcd(0);


Other sketches do so with the following code:
Code: Select all | TOGGLE FULL SIZE
// Define LCD pinout
const int  en = 2, rw = 1, rs = 0, d4 = 4, d5 = 5, d6 = 6, d7 = 7, bl = 3; // original ...

// Define I2C Address - change if reqiuired
const int i2c_addr = 0x20;

LiquidCrystal_I2C lcd(i2c_addr, en, rw, rs, d4, d5, d6, d7, bl, POSITIVE);


My question is this: If Adafruit's sketch code works perfectly, why even try to use the other sketch code?

I tried to learn how to use the non-Adafruit sketch, but could never get it to work no matter what changes I made. How is this sketch code even useful?

I used the I2C_Scanner sketch to get my I2C hex address, while Adafruit uses the 'default' lcd(0) address. I understand that if we are using more than one backpack that the hex address becomes important, but for a single LCD/backpack combo, why bother with all the extra code.

Any enlightening comments are most welcome.

Thank you.

_phillip
 
Posts: 132
Joined: Fri Apr 09, 2021 3:28 pm

Re: LCD Backpack Sketch Query

by adafruit_support_mike on Tue Jun 15, 2021 9:12 pm

The different sketches are written for different kinds of hardware.

Raw LCDs are tricky to control. They have a matrix for connections to the elements, and have to be driven with a square wave to avoid damaging the liquid crystal. To save that trouble, there are IC LCD drivers that take simpler input and generate the correct signals for the display. The Hitachi HD44780 was one of the most popular, and its pinout/control interface have become a generic standard. It has a built-in memory chip with bit patterns for characters, and has a parallel data interface.

The basic interface has 8 data input lines, a Read/Write line (RW), a Register Select line (RS), and an Enable line (E), for a total of 11 lines. There's an optional interface that only uses 4 of the data lines though, for a total of 7 lines. The RW pin is optional, so the HD44780 will also work with 6 or 10 input lines.

The Arduino programming environment has code to talk to an HD44780 LCD driver directly, using 7 to 11 GPIO pins. Code for that starts by identifying the pins used for each signal.

Even the 6-pin connection uses a lot of an Arduino's GPIO pins, so we built an intermediate controller that uses an I2C GPIO expander (either the MCP23017 or the MCP23008). Those only need 2 pins (SDA and SCL), which can be shared with other I2C devices. The code for that needs to know how to talk to the GPIO expander, and how the GPIO expander's pins map to the HD44780's inputs.

That means the two kinds of code talk to different devices: the Arduino version talks to the HD44780 directly, and ours talks to the MCP23017/MCP23008.

adafruit_support_mike
 
Posts: 63053
Joined: Thu Feb 11, 2010 2:51 pm

Re: LCD Backpack Sketch Query

by _phillip on Tue Jun 15, 2021 9:28 pm

@adafruit_support_mike

Thank you for the indepth explanation to my question.

When compared to other LCD/backpack sketch code, the simplicity of the Adafruit code is amazingly simple. I now have a much better understanding as to why this is.

I sincerely appreciate your help.

_phillip
 
Posts: 132
Joined: Fri Apr 09, 2021 3:28 pm

Please be positive and constructive with your questions and comments.