Re: Using 20x4 LCD display

"Dr. Rolf Jansen" <[email protected]>
Newsgroups gmane.os.freebsd.devel.arm
Message-ID <[email protected]>
> Am 22.10.2021 um 03:52 schrieb Olivier <[email protected]>:
> 
> I would like to use a 20x4 LCD display attached to a Raspberry Pi
> running FreeBSd 12.2.
> 
> I can talk to the display through the I2C interface, when I send
> something the back light will turn off and on, so the link is
> established.

I use a 20x4 LCD (HD44780 type) over I2C (via PCF8574T) on a BeagleBone Black. For this, I manually transcribed one of the many Python libraries into plain C, and I wrote a minimalistic I2C glue interface in C, so it can be easily addressed.

I just put a .zip file for downloading it on my web site:

  https://obsigna.com/Downloads/LCD_20x4_over_I2C.zip

I added a Hello World test program (s. below). Perhaps you need to change the I2C device number and the I2C address in lcd.c. Here I have:

  uint8_t lcd_iicid = 1;
  uint8_t lcd_addr  = 0x27;

The Python code contained a lot of delays between various calls. This was not necessary for the BeagleBone Black, I removed this and it let me optimize the subroutines for transferring data to the display. I don’t know whether this would work on a Raspberry Pi, though.

Compile it with: cc i2c.c lcd.c hello.c -o hello
Run it with: ./hello

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>

#include "i2c.h"
#include "lcd.h"

int main(int argc, const char *argv[])
{
  lcd_begin();
  lcd_print("Hello, World!", 13);
  lcd_setCursor(0, 1);
  lcd_print("HD44780 over PCF8574", 20);
  lcd_setCursor(0, 2);
  lcd_print("If it does not work,", 20);
  lcd_setCursor(0, 3);
  lcd_print("do not ask me why.", 18);

  return 0;
}

Best regards

Rolf



Dr. Rolf Jansen
- -
Rua Reginaldo de Lima, 98
Parque São Diogo
09732-550, São Bernardo do Campo
São Paulo - Brazil

Phone:	0055-11/4317-0974
Mobile:	0055-11/9 8141-1465
E-Mail:	[email protected] <mailto:[email protected]>
BLog:	obsigna.com <https://obsigna.com/>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.