Example Implementations

The pi4j-examples repository contains complete example applications that use the Pi4J Drivers library. Each example shows how to wire up a specific component and use the corresponding driver in a Java application.

Getting the examples

Clone the repository to your Raspberry Pi or development machine:

git clone https://github.com/Pi4J/pi4j-examples

Each subdirectory contains a self-contained Maven project for a specific device.

Available examples

DeviceDescriptionInterface
1602A LCD HD44780U16x2 character LCD, direct GPIO controlGPIO
1602A LCD via PCF8574A16x2 character LCD over I2C expanderI2C
1602A LCD via MCP2301716x2 character LCD over 16-bit I2C expanderI2C
ADS125624-bit analog-to-digital converterSPI
AT24C512Serial EEPROM read/writeI2C
BME280Temperature, humidity, and pressure sensorI2C
BMP280Temperature and pressure sensorI2C
DAC855216-bit digital-to-analog converterSPI
DHT22Temperature and humidity sensorGPIO
IS31FL3731LED matrix controllerI2C
MCP230088-bit GPIO expander — drive and read chip GPIOsI2C
MCP23008 + MCP23017Pin monitoring exampleI2C
MCP2301716-bit GPIO expander — drive and read chip GPIOsI2C
MCP300810-bit analog-to-digital converterSPI
MCP472512-bit digital-to-analog converterI2C
MPL3115A2Altitude, pressure, and temperature sensorI2C
NeoPixel LED stripWS2812B addressable RGB LEDsSPI
Rotary Encoder (KY-040 / 5880)Rotary encoder with integrated push buttonGPIO
SN74HC5958-bit shift registerSPI
SSD1306128x64 OLED displayI2C
TCA95481-to-8 I2C multiplexer switchI2C
VL53L0XTime-of-flight distance sensorI2C

Contributing

Found a device not yet covered? Contributions are welcome. Open an issue or pull request in github.com/Pi4J/pi4j-examples to share your implementation with the community.