Tested with: Raspberry Pi 4B / Raspbian GNU/Linux 11 (bullseye) with the SparkFun 20x4 serLCD.
This code is ported with reference to this python script and this Arduino library.
- edit DEV_PATH and I2C_ADDRESS in example.h as necessary
- make
- ./example
- ctrl-c to terminate
This is C language demonstration code for the above liquid crystal display module. The included control functions are a minimum set to :-
- display a plain string.
- display a formatted string.
- create and display custom characters.
- provide a subset of basic control commands (function declarations in serLCD.h).
It is not a comprehensive port of the above repositories and connection is via i2c only. Displayed strings should be a maximum of 20 characters in length (for the 20x4 lcd) as overflow to the next line can be inconsistent. Control functions return 0 on success or a negative error number on failure.
No fancy scrolling, I'm afraid! I found the various scrolling functions too unpredictable, even with the official python driver.
Please read the next two sections to avoid a couple of gotchas!
Settings prerequisites:
- sudo raspi-config --> interfacing options --> enable i2c
- sudo apt install libi2c-dev i2c-tools
- determine i2c busses with i2cdetect -l
- determine SerLCD device location and id with i2cdetect -y <bus number>
Hardware prerequisites:
-
You may see "[Errno 121] Remote I/O error" with the default Raspberry Pi i2c baud rate settings. This can be resolved by running at a lower baud rate (10k), as opposed to the default baud rate (100k). If you need higher baud rates for other i2c devices, these can be connected to a separate i2c bus.
e.g. /boot/config.txt i2c settings of:
dtparam=i2c_arm=on,i2c_arm_baudrate=10000 dtoverlay=i2c3,baudrate=400000
with the serLCD on i2c-1 and other devices on i2c-3.
-
Put a 10k ohm pull down resistor on either one of the serLCD's RXI pins, to avoid random characters appearing on the display as a result of electrical noise pickup.