Pi4J - Extending with a JavaFX info application

While trying out what Pi4J can do, I found it could easily be extended with a JavaFX application to provide info about the headers on a Pi board. This could later be extended to a remote/local (touch) User Interface using the REST interface from this post.

Starting point

I started with the minimal JavaFX application I created before for a quick start with the correct pom.xml and basic starting classes.

I also started from develop/2.0 branch of Pi4j with a fork and a new branch “2.0.pinninginfo” on my GitHub account.

Changes in Pi4j core

The core library contains a lot of information of the available pins on a Pi board in the class RaspiPin.java, eg

// the following GPIO pins are only available on the Raspberry Pi Model A, B (revision 2.0)
public static final Pin GPIO_17 = createDigitalPin(17, "GPIO 17"); // requires B rev2 or newer model (P5 header)

The only change I did in the core, was adding a Header/HeaderPin definition to group this info into a 26 or 40 pin header object depending on the type of board.

public static Header getHeader(SystemInfo.BoardType board) {
    Header header = null;

    switch (board) {
        case RaspberryPi_A:
        case RaspberryPi_B_Rev1:
        case RaspberryPi_B_Rev2:
            header = new Header(26);

            header.addHeaderPin(1, null, "3.3 VDC", "Power", null);
            header.addHeaderPin(2, null, "5.0 VDC", "Power", null);
            header.addHeaderPin(3, 8, "SDA0", "(I2C)", null);
            header.addHeaderPin(4, null, "DNC", "", null);
            header.addHeaderPin(5, 9, "SCL0", "(I2C)", null);
            header.addHeaderPin(6, null, "Ground", "", null);
            header.addHeaderPin(7, 7, "GPIO 7", "", RaspiPin.GPIO_07);
            ...

            break;
        case RaspberryPi_A_Plus:
        case RaspberryPi_B_Plus:
        case RaspberryPi_2B:
        case RaspberryPi_3B:
        case RaspberryPi_3B_Plus:
        case RaspberryPi_Zero:
        case RaspberryPi_ZeroW:
            header = new Header(40);

            header.addHeaderPin(1, null, "3.3 VDC", "Power", null);
            header.addHeaderPin(2, null, "5.0 VDC", "Power", null);
            header.addHeaderPin(3, 8, "GPIO 8", "SDA1 (I2C)", RaspiPin.GPIO_08);
            header.addHeaderPin(4, null, "5.0 VDC", "Power", null);
            header.addHeaderPin(5, 9, "GPIO 9", "SCL1 (I2C)", RaspiPin.GPIO_09);
            ...

            break;
    }

    return header;
}

Additional JavaFX module

An extra module was added to the Pi4J-structure to separate the FX application from the other modules.

By calling the getHeader-function from the core, the pins can be visualized in a table or header (compact and extended) view. These view sources are available here.

When running the application a list is filled with the available board types and after selecting one, the pins are shown in three different tabs:

Conclusion

This isn’t a fancy application yet, but just a proof-of-concept to show how easy it is to expose the info which is in the Pi4J-core in an UI. The checkboxes don’t do anything now, but combined with the REST interface from my previous post we could run this FX application an a PC or Pi and control one or multiple boards.

Depending on the decisions taken by the Pi4J-team and the changes in the 2.0-version I will try to adapt/extend this UI and hope it can be pulled into the next version of the Pi4J-project.