tietajajoshua
Posts: 5
Joined: Thu Aug 17, 2017 11:55 pm
Location: Brighton, England
Contact: Facebook

Java Pi4j interface with 16*2 lcd screen...

Fri Aug 18, 2017 12:02 am

I'm an old java programmer, looking to embed a pc application into a raspberry pi hardware device. I got this 16*2 lcd screen working with Python code first time, however the pi4j has been full of bugs. I've updated the wiring pi, the pi4j, for my A+ processor, but still no results... is there some on/off switch i'm missing? any help is appreciated.

tietajajoshua
Posts: 5
Joined: Thu Aug 17, 2017 11:55 pm
Location: Brighton, England
Contact: Facebook

Re: Java Pi4j interface with 16*2 lcd screen...

Fri Aug 18, 2017 9:38 am

The discrepancy between the pin numbering on this jargon code, and the original underlying wiringPi numbering was the cause of this frustration. Here is the revised code, where gpio 25 corresponds to wiringPi 6, not 26! Remember to update wiringPi and pi4j to the latest versions.

Code: Select all

import com.pi4j.wiringpi.Gpio;
import com.pi4j.wiringpi.Lcd;

public class LCD {

    public final static int LCD_ROWS = 2;
    public final static int LCD_COLUMNS = 16;
    public final static int LCD_BITS = 4;

    public static  void main(String args[]) throws 

InterruptedException, UnsupportedEncodingException {
        System.out.println("SYSTEM PRINT TEST");

        if (Gpio.wiringPiSetup() == -1) {
            System.out.println("GPIO SETUP ERROR");
            return;
        }

        // initialize LCD
        int lcdHandle= Lcd.lcdInit(LCD_ROWS,
                                   LCD_COLUMNS,
                                   LCD_BITS,
                                   6,
                                   5,
                                   15,
                                   16,
                                   1,
                                   4,
                                   0,
                                   0,
                                   0,
                                   0);

        if (lcdHandle == -1) {
            System.out.println("LCD INIT ERROR");
            return;
        }

        Lcd.lcdDisplay(lcdHandle,1);
        Lcd.lcdClear(lcdHandle);

        Lcd.lcdPuts (lcdHandle, "LCD TEST LINE 1") ;

        Lcd.lcdPosition (lcdHandle, 0, 1) ; 
        Lcd.lcdPuts (lcdHandle, "LCD TEST LINE 2") ;

try {
     Thread.sleep(10000);
    } catch (Exception e) {}
    }
}

Return to “Java”

Who is online

Users browsing this forum: No registered users and 3 guests