We are still shipping! However, order processing may take longer than usual and we cannot guarantee same day shipments due to staffing guidelines from the CDC. Please see all COVID-19 updates here. Thank you for your continued support.

Member #739885

Member Since: November 13, 2015

Country: United States

  • I am trying to connect Nokia 5110 LCD to BeagleBone Black Rev-C over SPI protocol using Linux kernel's SPI driver.

    I successfully installed and ran Adafruit's python-library: Adafruit_Nokia_LCD

    I have a strange issue, when I run this python code first and then my C code, the code works perfect! But if I run my C code before the python code, I get no output. Logic says that the python code must be initializing something that I am missing in my code. Here's how I am initializing the LCD:

    fd_spi_dev = open(device, O_RDWR);
    //set mode
    mode = SPI_MODE_0;
    ioctl(fd_spi_dev, SPI_IOC_WR_MODE, &mode);
    ioctl(fd_spi_dev, SPI_IOC_RD_MODE, &mode);
    //set max bitrate
    speed = 4000000;
    ioctl(fd_spi_dev, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
    ioctl(fd_spi_dev, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
    // set an msb first
    lsbsetting = 0;
    ioctl(fd_spi_dev, SPI_IOC_WR_LSB_FIRST, &lsbsetting);
    // set bits per word
    bits = 8;
    ioctl(fd_spi_dev, SPI_IOC_WR_BITS_PER_WORD, &bits);
    ioctl(fd_spi_dev, SPI_IOC_RD_BITS_PER_WORD, &bits);
    lcd_write_cmd(0x21);    // LCD extended commands
    lcd_write_cmd(0xB8);    // set LCD Vop (contrast)
    lcd_write_cmd(0x04);    // set temp coefficient
    lcd_write_cmd(0x14);    // set biad mode 1:40
    lcd_write_cmd(0x20);    // LCD basic commands
    lcd_write_cmd(0x09);    // LCD all segments on
    /* I am expecting to see all segments lit here */
    lcd_write_cmd(0x0C);    // LCD normal video 
    void lcd_write_cmd(uint8_t cmd) {
        uint8_t *tx = &cmd;
        uint8_t rx;
        uint32_t len = 1;
    struct spi_ioc_transfer tr = {
        .tx_buf = (uint32_t)tx,
        .rx_buf = (uint32_t)&rx,
        .len = len,
        .delay_usecs = delay,
        .speed_hz = speed,
        .bits_per_word = bits,
        .cs_change = 1,
    size = write(fd_dc_val, "0", 1);
    size = write(fd_cs_val, "0", 1);
        ioctl(fd_spi_dev, SPI_IOC_MESSAGE(1), &tr);
    write(fd_cs_val, "1", 1);

    I am a novice in embedded programming. I would greatly appreciate any help. Thank you.

No public wish lists :(