0
votes

I'm attempting to write to an LCD (LCD1602 Display Screen) using a PCF8574 IO Expansion Board. I've used some example code I found, but although it does flash the background light (so I know it is communicating with the LCD) it doesn't print numbers.

I don't want to use the WiringPI library because it is no longer supported and I want to use the BCM2835 libraries. Anyone know how I can write characters to the LCD? I thought I only needed to send the ascii codes?

#include <bcm2835.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>


int main(int argc, char **argv)
{
    char buf[1];
    char wbuf[] = "Hello World!";

    if (!bcm2835_init())return 1;
    bcm2835_i2c_begin();                //Start I2C operations.                                                       
    bcm2835_i2c_setSlaveAddress(0x27);  //I2C address                                                                 
    bcm2835_i2c_set_baudrate(10000);    //1M baudrate                                                                 

    buf[0] = 0xEF;    //LED ON                                                                                        
    bcm2835_i2c_write(buf,1);
    int ln = strlen(wbuf);
    for (int i=0; i< ln; i++)
    {
        buf[0] = wbuf[i];
        bcm2835_i2c_write(buf,1);
        bcm2835_delay(5);
    }

    bcm2835_i2c_end();
    bcm2835_close();
    return 0;
}

1

1 Answers

0
votes

Rather than doing all the work directly through bcm2835 I discovered a library for speaking to an lcd screen via i2c.

https://github.com/albertherd/LCD1602

If you did want to do this solely through bcm2835 then it looks like you just need to do some file IO operations for the I2C controller on the PI. (easier to use the library)