Home United States USA — software Blink a LED on a Raspberry Pi With Vaadin

Blink a LED on a Raspberry Pi With Vaadin

190
0
SHARE

Build a responsive website with Vaadin Flow to control electronic components connected to a Raspberry Pi with Pi4J
Join the DZone community and get the full member experience. As I’m becoming a senior developer in terms of age, I’ve transitioned from one language to another. One of my main interests has always been clean, easy-to-understand UIs (User Interface). That journey started for me with Director (to create multimedia CD-ROMs), Flash website animation, and Flex Rich Internet Applications (= “Flash on steroids”). When I started developing with Java over 10 years ago, we had some projects with the early versions of Vaadin and JavaFX. As I went on with serverside applications, I only continued with JavaFX for some personal and side projects and loved the way you can create a UI both with XML (FXML actually) and code, exactly the same approach I loved with Flex. Since then, my love for Java and JavaFX only grew and it’s still my major programming environment. But JavaFX has one missing piece: running it in the browser… Yes, JPRO can do this, but it needs a license and a dedicated server. And yes, there are some projects ongoing to bring JavaFX fully to the browser, but they are ongoing and not mature yet… Let’s look at another approach: Vaadin Flow and run it on a Raspberry Pi to control a LED and show the state of a button. Only recently I re-discovered Vaadin to build Web User Interfaces, and this really feels like JavaFX in the browser. Full Java code to create your views and run it in the browser without the need to write a single HTML, CSS, JavaScript, or TypeScript file! Vaadin Flow is a unique framework that lets you build modern (responsive!) web apps 100% in Java without writing HTML or JavaScript. In this tutorial, I’m using this Vaadin Flow combined with Pi4J to create a web interface to interact with a LED and button connected to the GPIO (General Purpose Input/Output) pins of a Raspberry Pi. The finished project is available on GitHub. Pi4J, the Java I/O library for the Raspberry Pi, aims to unite Java programming with electronics. The project started in 2012. Version 1.3 was released in February 2021 to support the newest Raspberry Pi boards (4,400, and Compute 4) and is the last version that is based on Java 8. In the summer of 2021, a completely refactored V2 was launched, based on Java 11, PiGpio, Java modules, etc. By using the Pi4J-dependency in a project, controlling electronic components connected to the GPIO (General Purpose Input/Output) pins of the Raspberry Pi can be controlled as objects in the Java code. Pi4J uses native libraries to control the GPIOs so you as a programmer don’t need to fully be aware of all the “magic” which relates to hardware communication.

Continue reading...