[Elixir Nerves] Character LCD with serial interface (I2C)
![[Elixir Nerves] Character LCD with serial interface (I2C)](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1612786611875%2FyyNAQMFI-.gif&w=3840&q=75)
Search for a command to run...
![[Elixir Nerves] Character LCD with serial interface (I2C)](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1612786611875%2FyyNAQMFI-.gif&w=3840&q=75)
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...
As a Nerves IoT framework hobbyist, I enjoy learning the very basics of the electronics through writing Elixir programs that run on my Raspberry Pis. Today I will talk about the HD44780 Character LCD display with the serial interface. There are multiple ways to use the serial interface between an LCD and a Raspberry Pi, but here I will use a typical inexpensive I2C piggyback board as an example.
Here are the items I prepared:
| I2C module | Raspberry Pi |
| 5V | 5V Power |
| GND | Ground |
| SDA | SDA |
| SCL | SCL |

Clone the demo project
$ git clone git@github.com:mnishiguchi/lcd_display.git
$ cd lcd_display/examples/nerves_hello_lcd
Set necessary environment variables. The demo project assumes you will use WIFI so two WIFI related values (ssid and psk) are required to be set. The MIX_TARGET environment variable can be any target tag that Nerves supports.
$ export WIFI_SSID=_____ # your WIFI id
$ export WIFI_PSK=______ # your WIFI password
$ export MIX_TARGET=rpi0 # your target board
Install dependencies.
$ mix deps.get
Create firmware.
$ mix firmware
Insert the SD card into your host machine (e.g. laptop) and run the following command to burn the firmware to that SD card.
$ mix firmware.burn
Insert that SD card into your target board (e.g. Raspberry Pi) and power it on.
Check the connection.
$ ping nerves.local
SSH into your target board, then interactive Elixir shell will start.
$ ssh nerves.local
Interactive Elixir (1.11.2) - press Ctrl+C to exit (type h() ENTER for help)
Toolshed imported. Run h(Toolshed) for more info.
RingLogger is collecting log messages from Elixir and Linux. To see the
messages, either attach the current IEx session to the logger:
RingLogger.attach
or print the next messages in the log:
RingLogger.next
iex(1)>
Run RingLogger.attach then log messages will be outputted.
Follow the instructions in mnishiguchi/lcd_display README to show "Hello" text.
For the other supported commands, please refer to LcdDisplay.HD44780.Driver documentation.
Here is the command I use for testing the LCD. It runs various commands one after another.
iex(1)> NervesHelloLcd.hello_pcf8574
Different products out there may use a differnt I/O expander internally.
At first, I was under the impression that all the I2C boards would do exactly the same thing. That is not true at all. There is no gurantee the same program works for all the serial interface boards.
So the lesson I learned is even if two products look similar, it is a good idea to still check what I/O expander is mounted on a board and check the pin assignment between the I/O expander and the LCD display.
I totally underestimated the difficulty level of desoldering. I messed up two LCDs. First of all, desoldering itself is difficult to me at least. Secondly, a solder sucker can peel the printed metal sheet. I do not know the name of it, but I mean by the metal bits on which we solder to connect the header pins.
The lesson I learned is to avoid desoldering whenever possible.
Many I2C boards only support one pin for the backlight, using pins 1 to 16.
For the 16-pin standard LCDs, there is no issue, but for the 18-pin RGB LCDs, the pin #16 is for the Red LED. So the backlight can always be red if only that pin is connected not the Green and the Blue pins. I should have use a standard LCD, not the RGB one.
The lesson I learned is to make plans before using the RGB LCD.
They say SparkFun Qwiic Connect System makes the I2C connection easy.
The USB port can be used for connecting a LCD.
Here are my study notes on HD44780 LCD, I/O expanders, I2C interface etc in case they may be helpful for somebody.