Using gpiolcd on a 16x2 LCD

I got some progress

dmesg | grep PCF8574
gpio2: <PCF8574 I/O expander> at addr 0x4e on iicbus1



# cat /boot/msdos/config.txt
[all]
arm_64bit=1
dtparam=audio=on,i2c_arm=on,i2c0=on,i2c1=on,i2c_arm_baudrate=400000,spi=on
dtoverlay=mmc
dtoverlay=disable-bt
device_tree_address=0x4000
kernel=u-boot.bin
dtoverlay=w1-gpio
dtoverlay=uart4
dtoverlay=pcf8574
dtoverlay=i2c1



# cat pcf8574.dts
/dts-v1/;
/plugin/;

&i2c1 {
status = "okay";

pcf8574@27 {
compatible = "nxp,pcf8574";
reg = <0x27>;
clock-frequency = <400000>;
};
};




But I can't get the text to display

# /usr/src/sys/dev/gpio/gpiolcd -d -f /dev/gpioc2 '123'
hd44780: reset to 4-bit interface, 2 lines, 5x8 font, no cursor
 
Look at your new GPIO expander device (pcf8574) via the /dev/gpio# and gpioctl.
Does there look like a new GPIO bus.
Can you see the pin assignments? gpioctl -f /dev/gpio# -lv
 
My new device:


# gpioctl -f /dev/gpioc2 -lv
pin 00: 1 P0<IN>, caps:<IN,OUT>
pin 01: 1 P1<IN>, caps:<IN,OUT>
pin 02: 1 P2<IN>, caps:<IN,OUT>
pin 03: 0 P3<IN>, caps:<IN,OUT>
pin 04: 0 P4<IN>, caps:<IN,OUT>
pin 05: 0 P5<IN>, caps:<IN,OUT>
pin 06: 0 P6<IN>, caps:<IN,OUT>
pin 07: 0 P7<IN>, caps:<IN,OUT>

 
After all the manipulations with the overlay, my device is on iic1

# i2c -s -f /dev/iic1
27

# i2c -s -f /dev/iic0




I continue to explore...
 
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.
Boy I sure have not completed that phase of the project.... messages.txt with Onewire Temps to LCD but I hate cron.
Needs a daemon instead.

For anybody writing a display driver this is a great start on writing things to a character display.. gpiolcd.
 
With your permission Phishfry, I will put all the pieces together.
Maybe it will be useful to someone.

HD44780 16x2 Modulo LCD Display

Load module pcf8574.ko
Add pcf8574_load="YES" in /boot/loader.conf for PCF8574I/O Expander for I2C Bus

Connect module SDA -> Pin 3, SCL -> Pin5, VCC -> 5V and GND -> Ground on Raspberry Pi3

I did the same as Phishfry for Enable i2c


# cat /boot/msdos/config.txt
[all]
arm_64bit=1
dtparam=audio=on,i2c_arm=on,i2c0=on,i2c1=on,i2c_arm_baudrate=400000,spi=on
dtoverlay=mmc
dtoverlay=disable-bt
device_tree_address=0x4000
kernel=u-boot.bin
dtoverlay=w1-gpio
dtoverlay=uart4
dtoverlay=pcf8574
dtoverlay=i2c1


Reboot

Scan i2c bus

# i2c -s -f /dev/iic0

# i2c -s -f /dev/iic1
27


Phishfry Overlay
Code:
/dts-v1/;
/plugin/;

&i2c1 {
        status = "okay";

        pcf8574@27 {
                compatible = "nxp,pcf8574";
                reg = <0x27>;
                clock-frequency = <400000>;
                };
};

Move pcf8574.dtbo to /boot

# dtc -O dtb -o pcf8574.dtbo -b 0 -@ pcf8574.dts
# mv pcf8574.dtbo /boot/msdos/overlays/


Install port sysutils/rpi-firmware

# cp /usr/local/share/rpi-firmware/overlays/i2c1.dtbo /boot/msdos/overlays/


Reboot

When the system is fully loaded we can see new device

# dmesg | grep 8574
gpio2: <PCF8574 I/O expander> at addr 0x4e on iicbus1



# 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: 0 P4<OUT>, caps:<IN,OUT>
pin 05: 0 P5<OUT>, caps:<IN,OUT>
pin 06: 0 P6<OUT>, caps:<IN,OUT>
pin 07: 0 P7<OUT>, caps:<IN,OUT>


Download and compile Andriy's utility gpiolcd
# clang -g -o gpiolcd gpiolcd.c

Sending a test message to a new device /dev/gpioc2
# ./gpiolcd -f /dev/gpioc2 "Hello FreeBSD!"

photo_2024-11-27_00-30-35.jpg
 
Back
Top