Controlling Arduino with Mosquitto and JavaFX on Raspberry Pi

One of the example applications in my book “Getting started with Java on the Raspberry Pi” combines a JavaFX application with Mosquitto on the Raspberry Pi to control a LED strip with an Arduino. All wireless and independent of each other as the Mosquitto-queue is dealing with exchange commands between all applications.

Between all applications a predefined list of commands can be exchanged as listed in table below.

See it in action:

Java application

The sources are available on GitHub. The color picker is a component of Gerrit Grunwald and combined with other JavaFX components two UI’s are available. The first one is used to control the LED strip.

The second UI is also receiving the commands from Mosquitto and shows them in a table.

The Java application also exposes a web interface with Undertow as the server, so anyone within the network can control the LED strip. As a proof-of-concept, only a few effects are available.

Arduino application

These sources are also available on GitHub. The Arduino code has functions per type of LED effect to generate the requested effect and is split into multiple easy to understand parts.

void setRunningLight() {  
  if (currentAction >= NUMBER_OF_LEDS) {    
    currentAction = 0;    
  }
  // Show color 1
  strip.setPixelColor(currentAction, rgb1);
  strip.show(); 
  // Reset to color 2 for next loop
  strip.setPixelColor(currentAction, rgb2);
  currentAction++;
}

Full description

This is just a very short description of what is described in more than 30 pages in the book in “Chapter 12: Message Queues”, including how to install and test Mosquitto on the Pi. Feel free to take a look in the code which is freely available on GitHub. I would love to hear your feedback!

Frank Delporte

Frank Delporte

Author of Getting Started with Java on Raspberry Pi" which is for sale on Leanpub (ebook) and Elektor (paper book). Software developer/technical lead/writer with more than 20 years of experience in video, multimedia, technical project management, digital signage, and (web) programming. Since 2010 I work for Televic Rail in Izegem, Belgium. My current work tools are Java/Git/Atlassian/IntelliJ IDEA/Visual Studio Code, but also use/used ASP.NET, C#, JavaScript, Angular, SQL Server, Flex, CSS, HTML5, Eclipse, QT,… I love to KISS (Keep It Simple, Stupid) and try to do this in everything I do.

Leave a Replay

Leave a Reply

Your email address will not be published. Required fields are marked *

Follow Me

More Posts By Frank