HD44780 LCD, I/O expanders, I2C interface etc

Search for a command to run...

I wrote a script called phx-docker-compose-new that can be used instead of mix phx.new to generate a new Phoenix application. Building the development environment for a Phoenix application using Docker Compose is convenient because you can set up not...
この記事について Raspberry Pi、TensorFlow、Pythonのいずれにも詳しくない筆者が、物体検出をやって楽しんだ成果の記録です。 TensorFlow公式の物体検出のサンプルプログラムを実行します。 動作環境 ボード Raspberry Pi 4 Model B OS Raspberry Pi OS (32-bit または 64-bit) デスクトップ環境 カメラ Raspberry Pi カメラモジュール v2 Python Python ...
One day I was trying to upgrade one of my Phoenix 1.5 apps to Phoenix 1.6. In that app, I customize Bootstrap styles using SCSS. I want to talk about what I found and stumbled on when setting up SCSS. TIL All explained in Phoenix 1.6 Asset Managemen...
This is written in Japanese. I might convert it to English later, maybe. はじめに Elixirのテストでモックを用意するときに利用するElixirパッケージとして、moxが人気です。Elixir作者のJosé Valimさんが作ったからということもありますが、ただモックを用意するだけではなくElixirアプリの構成をより良くするためのアイデアにまで言及されているので、教科書のようなものと思っています。 一言でいうと「その場...
TIL Access supports keyword lists (Keyword) and maps (Map) out of the box, but not structs. There is a reason why Elixir does not implement Access behaviour for structs. Perfer data.key for accessing predefined atom keys of map or struct. Access be...
Here is my study note on the HD44780 Character LCD and the options for it connection to the controller devices.
According to Wikipedia:
We have an option of purchasing:
For a standalone LCD, some products come with header pins soldered:
For an LCD with I2C interface module, some products are pre-assembled:
For SparkFun Qwiic Connect System, most products come with Qwiic connectors:
The HD44780 LCD typically has 16 pins but some products add extra pins for RGB backlight.
I personally categorize the LCD pins into four groups in my head so that they make sense to me:
Wikipedia and Adafruit Character LCD wiring instructions may be helpful to see the broad picture. For further info, I found helpful the following links:
| LCD pin # | LCD pin name | |
| 1 | Ground | |
| 2 | VCC | +3.3 to +5V (typical) |
| 3 | Contrast | +3.3 to +5V (typical) |
| LCD pin # | LCD pin name | |
| 4 | Register Select (RS) | 0: Instruction , 1: Data |
| 5 | Read/Write (R/W) | 0: Write, 1: Read; most likely always 0 |
| 6 | Enable (EN) | Starts read/write |
Particularly the Register Select bit and the Enable bit are important. Register Select switches between the instruction mode and the data mode when we interact with the display. The Read/Write bit is not needed if we are only writing to the display. We will most likely to connect the Read/Write pin to ground so that it is always low.
| LCD pin # | LCD pin name | |
| 7-10 | Data Bit 0-3 (DB0-3) | Unused in 4-bit operation |
| 11-14 | Data Bit 4-7 (DB4-7) | Transfers instruction or data |
The HD44780 LCD has 4-bit mode and 8-bit mode. The 4-bit mode allows us to split a data byte (8-bit) into high four bits and low four bits, then sent them separately. That way, we can reduce the number of the required I/O pins by half. It seems like typically most people only use the 4-bit mode.
The byte we send to the display can be either instruction or data depending on the Register Select bit.
| LCD pin # | LCD pin name | |
| 15 | Backlight Anode | If applicable |
| 16 | Backlight Cathode or Red | If applicable |
| 17 | Backlight Cathode Green | If applicable |
| 18 | Backlight Cathode Blue | If applicable |
The backlight is not directly relevant to controling the LCD. It can be done independently.
The original HD44780 LCD only has a single color LED backlight using pins 15-16. Some newer HD44780-compatible LCDs has RGB backlight using pins 15-18.
We should plan ahead of time about what we want to do with the backlight. Many I2C modules do not support RGB backlight. If a display has an RGB backlight and we only use pin 15-16, the backlight would be fixed to the red color, which would not be ideal.
With the RGB backlight, it is easy to to get yellow, pink and cyan just by switching on/off red, green and blue. It is simply the combination of red, green and blue.
If we want to control 24-bit RGB for more precise colors in beween red, green and blue, we would need Pulse Width Modulation (PWM) so that we can adjust the brightness for each color.
Adafruit RGB Backlit LCDs instructions may be helpful.
The HD44780 LCD allows us to register custom characters; however I personally would not bother because I do not find the feature useful. According to Wikipedia:
There are so many I/O expanders out there, but it seems like the following items are among the most poplular for the LCDs:
We need 6-7 pins out of eight to control the LCD so the 8-bit I/O expander runs out of pins for the RGB backlight. We can switch on/off one LED.
Different products out there use different I/O expanders internally, so please be aware of which I/O expander you are using if you use something like an I2C / SPI backpack. Also the pin assignment between the LCD and the I/O expander is important.
As far as I know, the PCF8574-based I2C modules are the most popular and inexpensive. A pre-assembled 16x2 LCD with I2C module is typically less than US$10. Handson Technology I2C Serial Interface 1602 LCD Module User Guide summarizes the typical specifications of the PCF8574-based I2C module.
The Adafruit i2c / SPI character LCD backpack supports both I2C and SPI interfaces. It uses MCP23008 for I2C and SN74HC595 for SPI as of writing.
The following wiring worked well:
| LCD backpack | Raspberry Pi - I2C | Raspberry Pi - SPI |
| Clock (CLK) | Serial Clock (SCLK) | Serial Clock (SCLK) |
| Data (DAT) | Serial Data (SDA) | Controller Out Peripheral In (COPI) |
| Latch (LAT) | - | Chip Select (CS) |
I have never used the Qwiic Connect System before but it looks like a nice option when we need to connect multiple deviced on the I2C bus.
It seems promissing but since it is relatively new, I am concerned that there is not much information available as of writing.
I'll try it soon.
It is similar to SparkFun Qwiic Connect System.
There is also a USB interface. I wonder when this option can be useful because for example Raspberry Pis do not have many USB ports.
I have not used SparkFun Qwiic Connect System or USB interface but I am curious about them. I'll try them out soon and keep on updating the contents as I learn more.