Posts: 6
Joined: Tue Dec 22, 2015 2:32 pm

Problems hooking up LCD module with wiringPi

Sat Nov 18, 2017 3:01 pm

So I got the ... i/overview LCD module for hooking up to the Raspberry pi. I wanted to write a program in C that can use the screen and print various things. I used this guide ... -wiringpi/ to do it and it works except that I have to setup the pins before I start the program.
For example:

Code: Select all

#include <wiringPi.h>
#include <lcd.h>
#include <mcp23017.h>
#include <stdio.h>

#define AF_BASE         100
#define AF_RED          (AF_BASE + 6)
#define AF_GREEN        (AF_BASE + 7)
#define AF_BLUE         (AF_BASE + 8)

#define AF_E            (AF_BASE + 13)
#define AF_RW           (AF_BASE + 14)
#define AF_RS           (AF_BASE + 15)

#define AF_DB4          (AF_BASE + 12)
#define AF_DB5          (AF_BASE + 11)
#define AF_DB6          (AF_BASE + 10)
#define AF_DB7          (AF_BASE +  9)

#define AF_SELECT       (AF_BASE +  0)
#define AF_RIGHT        (AF_BASE +  1)
#define AF_DOWN         (AF_BASE +  2)
#define AF_UP           (AF_BASE +  3)
#define AF_LEFT         (AF_BASE +  4)

int main()
{   int lcd = 0;
    mcp23017Setup (AF_BASE, 0x20) ;
    lcd = lcdInit (2, 16, 4, AF_RS, AF_E, AF_DB4,AF_DB5,AF_DB6,AF_DB7, 0,0,0,0) ;

    lcdClear (lcd);

    lcdPutchar(lcd, 'f');
    digitalWrite (AF_GREEN, HIGH) ; delay (500) ;
    digitalWrite (AF_GREEN,  LOW) ; delay (500) ;


Now if I just start my pi and run this program, nothing is printed to the screen and (green)led doesn't light up. It's like the pins aren't configured. But if I would run the command

Code: Select all

gpio -x mcp23017:100:0x20 mode 107
before running the program, the green led does light up as expected! If I run this command for all the different pins(0-15) everything works fine, leds light up, buttons work, screen prints characters etc.

Why is this happening and how do I fix it? I suppose I could write a script that is run everytime the pi starts but shouldn't this be possible to fix in code?

Return to “Beginners”

Who is online

Users browsing this forum: Bing [Bot] and 39 guests