Using gpiolcd on a 16x2 LCD

I am attempting to use Andriy's driver on a i2c controlled 16 Character LED with 2 Lines.
The driver source is one file and I have copied it to a BeagleBone where I have a working i2c bus on /dev/iic1


I copied this source file into /usr/src/sys/dev/gpio/ on a Beaglebone with FreeBSD 13.1-RELEASE on eMMC.
Still need to compile it.

I have enabled pfc8574(4) per AVG's instructions:

I created an overlay for it after using i2c -s -f /dev/iic1 to determine the i2c address in use by my module.
Code:
     / {

         ...
         pcf8574@27    {
             compatible    = "nxp,pcf8574";
             reg = <0x27>;
         };
     };

So what now?

Do I need to create an overlay for the 16x2 display?

This seems like they created a combined dts with pfc8574 i2c controller and hd44780 display.

Any thoughts? Do I need the overlay for hd44780 or will gpioled suffice?

What about I2C bus speed. I might enable another bus. I am using ds1307 now for test.
Should I use the fast bus overlay for the pfc8574? 400K or 100K clock freq?
 
Last edited:
Just a note, gpiolcd is not a driver, it's a very simple command line utility (although with not much of documentation). It works with gpio. You should have gotten a new gpio device if pcf8574 attached correctly.
Hope that helps.
 
Thank You so Much for this hint:
You should have gotten a new gpio device if pcf8574 attached correctly.

I now have something showing on the Raspberry Pi3.
DS3231 RTC on iic0 (pins gpio2 and gpio3) and pcf8574 on iic1 (pins gpio28 SDA0 and gpio29 SDL0)
Code:
gpio2: <PCF8574 I/O expander> at addr 0x4e on iicbus1

New gpioc2 bus showed up:
Code:
# gpioctl -f /dev/gpioc2 -lv
pin 00: -1      <>, caps:<>
pin 01: -1      <>, caps:<>
pin 02: -1      <>, caps:<>
pin 03: -1      <>, caps:<>
pin 04: -1      <>, caps:<>
pin 05: -1      <>, caps:<>
pin 06: -1      <>, caps:<>
pin 07: -1      <>, caps:<>

Recon Sentinal // Rock64 LCD is showing up as 3f and using an pcf8574A.
That threw me for a loop.

My pcf8574.dts:
Code:
/dts-v1/;
/plugin/;

&i2c1 {
        status = "okay";

        pcf8574@27 {
                compatible = "nxp,pcf8574";
                reg = <0x27>;
                clock-frequency = <400000>;
                };
};
dtc -O dtb -o pcf8574.dtbo -b 0 -@ pcf8574.dts

The Pi uses sysutils/rpi-firmware port for pre-compiled binaries for overlays.
Binary overlays go in /boot/msdos/overlays/
Configured with config.txt
Code:
dtparam=i2c_arm=on,i2c0=on,i2c1=on,i2c_arm_baudrate=400000,spi=on
dtoverlay=i2c0
 
Last edited:
Thanks Phishfry and Andriy for the tips.

My hardware is RPi 4B.

uname -a
Code:
FreeBSD generic 14.0-CURRENT FreeBSD 14.0-CURRENT #0 main-n259495-d1f3abc89250: Thu Dec  1 10:53:21 UTC 2022     root@releng1.nyi.freebsd.org:/usr/obj/usr/src/arm64.aarch64/sys/GENERIC arm64

I want to display text in 1602A.

Add pcf8574_load="YES" to loader.conf.

dev
Code:
nexus0
  ofwbus0
    psci0
    simplebus0
      bcm2835_clkman0
      mbox0
      gpio0
        gpiobus0
          owc0
            ow0
              ow_temp0
        gpioc0
      uart0
      spi0
        spibus0
      iichb0
        iicbus0
          iic0
      gic0
      simple_mfd0
      bcm_dma0
      bcmwd0
      bcmrng0
      bcm2835_firmware0
        ofw_clkbus1
        gpio1
          gpiobus1
          gpioc1
      sdhci_bcm0
        mmc0
      fb0
        fbd0
    ofw_clkbus0
      clk_fixed0
      clk_fixed1
    usb_nop_xceiv0
    clk_fixed2
    clk_fixed3
    simplebus1
      sdhci_bcm1
        mmc1
          mmcsd0
    pmu0
    generic_timer0
    cpulist0
      cpu0
        bcm2835_cpufreq0
        cpufreq0
      cpu1
      cpu2
      cpu3
    simplebus2
      pcib0
        pci0
          pcib1
            pci1
              bcm_xhci0
                usbus0
                  uhub0
                    uhub1
      genet0
        miibus0
          brgphy0
    gpioled0
    gpioregulator0
    regfix0
    regfix1
    regfix2
    simplebus3
  cryptosoft0

dmesg | grep "gpio"
Code:
gpio0: <BCM2708/2835 GPIO controller> mem 0x7e200000-0x7e2000b3 irq 14,15 on simplebus0
gpiobus0: <OFW GPIO bus> on gpio0
gpio1: <Raspberry Pi Firmware GPIO controller> on bcm2835_firmware0
gpiobus1: <GPIO bus> on gpio1
gpioregulator0: <GPIO controlled regulator> on ofwbus0
owc0: <GPIO one-wire bus> at pin 4 on gpiobus0
gpioc0: <GPIO controller> on gpio0
gpioc1: <GPIO controller> on gpio1
gpioled0: <GPIO LEDs> on ofwbus0

gpioctl -f /dev/gpioc1 -vl
Code:
pin 00: 1       BT_ON<IN>, caps:<IN,OUT>
pin 01: 1       WL_ON<IN>, caps:<IN,OUT>
pin 02: 0       PWR_LED_OFF<OUT>, caps:<IN,OUT>
pin 03: 1       GLOBAL_RESET<IN>, caps:<IN,OUT>
pin 04: 1       VDD_SD_IO_SEL<OUT>, caps:<IN,OUT>
pin 05: 1       CAM_GPIO<IN>, caps:<IN,OUT>
pin 06: 0       SD_PWR_ON<IN>, caps:<IN,OUT>
pin 07: 1       SD_OC_N<IN>, caps:<IN,OUT>

Use and compile
./a.out -f /dev/gpioc1 "sdfk"

There's no change at 1602A.
After a while it will show:
Code:
Connection to 192.168.0.104 closed by remote host.

When you log in again, the following message is displayed:
Code:
ssh: connect to host 192.168.0.104 port 22: Connection refused

You can log in through ssh only after the restart.

Next
pkg install sysutils/rpi-firmware
pkg install rpi-firmware


cp -pr /usr/local/share/rpi-firmware/* /boot/msdos/
cp /boot/msdos/config_rpi4.txt /boot/msdos/config.txt


Add the following to config.txt:
Code:
dtparam=i2c_arm=on,i2c0=on,i2c1=on,i2c_arm_baudrate=400000,spi=on
dtoverlay=i2c0

./a.out -f /dev/gpioc1 "sdfk"

There's no change at 1602A.
However, ssh login is not automatically logged out

What should I do
 
i2c_arm=on,i2c0=on,i2c1=on,
You need to fire up sysutils/i2c-tools.
Use that to figure out what is where by scanning the buses.

You should see PFC8574 in dmesg when you have the lcd on the right bus.

I have found i2c naming very inconstant. Please consider turning on all i2c buses for your platform.

I never figured out this program. I got it up and running but couldn't figure out how to send text to display with arguments.

There is a possibility you need an overlay for the display too like the hd44780 overlay. I don't know for sure.
 
iichb0 iicbus0 iic0
It looks like only one i2c bus is active.

HDMI requires i2c so make sure you use a different bus than that uses or disable HDMI if unused.

A scan with i2c -s should make things more apparent.

You are looking for 0x27 or 0x3f i2c address for the gpio extender to lcd controller.
 
gpioctl -f /dev/gpioc1 -vl
Take a look at that output you posted.
Does that look like the output from a GPIO expander(PCF8574) ?
No that is the Pi's second bank of GPIO pins.
The PCF8574 will be the next GPIO bus once it shows up in dmesg.
 
Be advised the above dts overlay I posted is using i2c1. You may need to adjust that for your board.
Pin27 and Pin28 on Pi are special and need muxing for i2c.
 
I have found that decompiling the dtb to see what resides where is a very useful learning experience.

I am on BananaPi-M1 now and see two i2c busses with ls /dev/iic*
I have no idea where the pins are for this board.
dtc -I dtb -O dts bananapi.dtb > bananapi.dts

After decompiling the dtb I see that iic0 is the boards Power Management Unit.
iic1 is on Pin3 and Pin5 for user gadgets.

# i2c -s
Scanning I2C devices on /dev/iic0: 34

# i2c -f /dev/iic1 -s
Scanning I2C devices on /dev/iic1: 3f

I can see from the decompiled dtb that the 34 address is the PMU
 
I still have not figured out how to display things with gpiolcd
I would assume I need to clear the screen and send text then end line.

./gpiolcd -d -h 2 -w 16 -I 4 "\nTesting\r"
hd44780: reset to 4-bit interface, 2 lines, 5x8 font, no cursor
 
Well I just realized you must set the gpio bus in the program source.
Once I did that it shows errors now:
Code:
./gpiolcd -d -w 16 "testing"
hd44780: reset to 4-bit interface, 2 lines, 5x8 font, no cursor
hd44780_set_pin: error 92
hd44780_set_pin: error 92
hd44780_set_pin: error 92
hd44780_set_pin: error 92
hd44780_set_pin: error 92
hd44780_set_pin: error 92
hd44780_set_pin: error 92
hd44780_set_pin: error 92
hd44780_set_pin: error 92
hd44780_set_pin: error 92
hd44780_set_pin: error 92
hd44780_set_pin: error 92
hd44780_set_pin: error 92
hd44780_set_pin: error 92
hd44780_set_pin: error 92
hd44780_set_pin: error 92
hd44780_set_pin: error 92
hd44780_set_pin: error 92
hd44780_set_pin: error 92
hd44780_set_pin: error 92
hd44780_set_pin: error 92
hd44780_set_pin: error 92

From this I can see the device has changed:
Code:
# gpioctl -f /dev/gpioc2 -lv
pin 00: 1       P0<OUT>, caps:<IN,OUT>
pin 01: 0       P1<OUT>, caps:<IN,OUT>
pin 02: 0       P2<OUT>, caps:<IN,OUT>
pin 03: 0       P3<IN>, caps:<IN,OUT>
pin 04: 1       P4<OUT>, caps:<IN,OUT>
pin 05: 1       P5<OUT>, caps:<IN,OUT>
pin 06: 1       P6<OUT>, caps:<IN,OUT>
pin 07: 0       P7<OUT>, caps:<IN,OUT>
 
Well I have characters coming up on Line 1 of the LCD now. They are not the correct characters but a start.
 
The i2c-tools pkg package does not contain i2cdetect. An error occurred when I compiled.

When I scanned it with i2c-s, I didn't find anything.

I am using Pin3=SDA and Pin5=SCL for i2c.

Yes, you're right.
gpioc1 is the Pi's second bank of GPIO pins。
When I reboot after unplugging from SDA and SCL, the output is the same:
gpioctl -f /dev/gpioc1 -vl
Code:
pin 00: 1       BT_ON<IN>, caps:<IN,OUT>
pin 01: 1       WL_ON<IN>, caps:<IN,OUT>
pin 02: 0       PWR_LED_OFF<OUT>, caps:<IN,OUT>
pin 03: 1       GLOBAL_RESET<IN>, caps:<IN,OUT>
pin 04: 1       VDD_SD_IO_SEL<OUT>, caps:<IN,OUT>
pin 05: 1       CAM_GPIO<IN>, caps:<IN,OUT>
pin 06: 0       SD_PWR_ON<IN>, caps:<IN,OUT>
pin 07: 1       SD_OC_N<IN>, caps:<IN,OUT>

I'll try the others later.

Lack of understanding of the overall architecture of embedded hardware, where can I find this information. I think I can learn from the linux literature and it will be easier to grasp the whole thing.
 
Are the ASCII control characters and escape sequences needed for command prompt arguments?
I am a bit lost by arguments.
Is quoted text OK as shown?
 
I traced it out and defaults were fine.

I switched platforms to the RockPro64 and I used pins 27 and 28.

When I did a scan of buses I discovered my device 3f on /dev/iic3 so for my overlay I used i2c3.
That was a mistake. When I tried i2c4 I could then write to the LCD device.
./gpiolcd -d -f /dev/gpioc5 "testing"
hd44780: reset to 4-bit interface, 2 lines, 5x8 font, no cursor


Thanks Andriy for the program and your patience.

So next stage. How to display OneWire temperatures?
Write them to a text file from the sysctl? Then display text file on LCD?
 
I am having troubles with Escaping and New Lines. I can only get messages on line one. I tried several different ways. I am now using a 4 line x 20 display now.

./gpiolcd -d -F -h 4 -f /dev/gpioc5 "This is line one.\nThis is line two."
./gpiolcd -d -F -h 4 -f /dev/gpioc5 "This is line one.'\n'This is line two."

Is my use of tcsh shell the problem here?

So from your help file I see the ability to use standard input. Can I use a file?
./gpiolcd -d -F -h 4 -f /dev/gpioc5 < message.txt

Code:
  args     Message strings.
           Some ASCII control characters and escapes sequences are supported:
                  <BS> (\b)    Backspace
                  <LF> (\f)    Clear display, home cursor
                  <NL> (\n)    Newline
                  <CR> (\r)    Carriage return
                  <HT> (\t)    Tab
                  <BEL> (\a)    Flash screen
                  <ESC>R    Reset display
                  <ESC>H    Home cursor
           If args not supplied, strings are read from standard input
 
When displaying characters from a text file I have all four lines working well.
./gpiolcd -d -h 4 -w 20 -f /dev/gpioc5 < message.txt


It is only on the command prompt that I am seeing an issue with multiple lines.
I am not proficient in escape sequences. I seem to be getting the Yen symbol instead of escaping...

This is what I am going to try.
Make a cron script scraping the sysctl of dev.ow_temp.0.temperature &date into message.txt for display.

First off though I want to make a gpioled rc.d service for startup text on LCD.

Merged solution from another thread that covacat help me through.
tail -n 4 /var/log/messages | cut -c 35- | /usr/local/sbin/gpiolcd -h 4 -w 20 -f /dev/gpioc5
 
Last edited:
Back
Top