This is a Spring-based demo project to show how a Vaadin User Interface (website) can interact with the GPIOs of a Raspberry Pi by using the Pi4J library.
The application supports multiple development boards with automatic feature detection:
The CrowPi is an all-in-one Raspberry Pi learning kit with various components. Different CrowPi versions contain different components, so the application adapts based on the configured version.
Features: LED, Touch sensor, LCD display, 7-segment display, Buzzer, LED matrix (Red or RGB depending on version), DHT11 sensor
The Pioneer600 is a Raspberry Pi expansion board with a different set of components.
Features: LED (GPIO 26), Key/Button (GPIO 20), OLED display (SSD1306 via SPI), BMP280 barometric sensor (I2C), Joystick and Buzzer (PCF8574 I/O expander), IR Receiver (GPIO 18)
The board type is configured in application.properties or via command line:
# Options: crowpi-1, crowpi-2, crowpi-3, pioneer600
board.type=crowpi-2You can also use any other Raspberry Pi with a GPIO header and connect electronic components directly to the GPIO pins. Change the pin numbers as needed in a custom configuration class.
Following versions of this code are available in branches:
- main:
- Dependencies got upgraded to latest versions in September 2025 of Spring Boot, Vaadin
- Many code changes to be compatible with those new versions.
- Uses Pi4J V4.0.0-SNAPSHOT.
- Uses Pi4J Drivers V0.0.1-SNAPSHOT.
- Separate services per type of device to make it easier to understand and reuse in other applications.
- vaadin-23-spring-2.6: Initial example with LED output and button input, based on Vaadin 23 and Spring Boot 2.6. It is described in detail in this Foojay.io blog post.
- vaadin-24-spring-3.0: Example used during a few conference talks, e.g. Controlling Electronics with Java and Pi4J through a web interface (J-Spring 2023) and Unlocking the Potential of Bits and Bytes (Devoxx 2023).
The base code with different Vaadin layouts, was generated on start.vaadin.com/app.
The application can interact with various components in the CrowPi1.
If you are developing on a PC, you can build the application with the following command
- Windows:
mvnw clean package - Mac & Linux:
./mvnw clean package
and upload to your Raspberry Pi with (replace login pi and the IP address with the one of your board)
$ scp target/pi4jdemo-1.0-SNAPSHOT.jar pi@192.168.0.222://home/pi/Build and upload in one command:
./mvnw clean package && scp target/pi4jdemo-1.0-SNAPSHOT.jar frank@crowpi3.local://home/frank/PWM and DHT11 need to be enabled on the Raspberry Pi. For example, on a Raspberry Pi 5:
$ sudo nano /boot/firmware/config.txt
# Add at the end of the file:
dtoverlay=pwm-2chan,pin=18,func=2,pin2=12,func2=4
dtoverlay=dht11,gpiopin=4The Pioneer600 requires SPI and I2C interfaces to be enabled for its components:
| Component | Interface | Configuration |
|---|---|---|
| OLED Display (SSD1306) | SPI | Bus 0, RST=GPIO19, DC=GPIO16 |
| BMP280 Sensor | I2C | Address 0x76 |
| Joystick/Buzzer (PCF8574) | I2C | I/O Expander |
| LED | GPIO | BCM 26 |
| KEY/Button | GPIO | BCM 20 |
| IR Receiver | GPIO | BCM 18 |
Enable the required interfaces using raspi-config:
sudo raspi-config
# Interface Options -> SPI -> Enable
# Interface Options -> I2C -> EnableOr add to /boot/firmware/config.txt:
dtparam=spi=on
dtparam=i2c_arm=on
Reboot after making changes.
Specify the board type you are using:
# For CrowPi
$ java -jar /home/pi/pi4jdemo-1.0-SNAPSHOT.jar --board.type=crowpi-3
# For Pioneer600
$ java -jar /home/pi/pi4jdemo-1.0-SNAPSHOT.jar --board.type=pioneer600
