Skip to main content Skip to local navigation

Java and Arduino (2022 edition)

Java and Arduino (2022 edition)

In the EECS 1021 class here at York University the students learning about object oriented programming in an engineering that uses sensors and actuators. We use Arduino devices that host a special pre-made firmware called Firmata to do this in order to unburden the students from the C++ coding that would otherwise be required on the Arduinos.

More details about Firmata and Java can be found in an earlier Java + Firmata blog post.

The following are some of the example videos that we incorporate in the learning material in the course. (more videos on the EECS 1021 playlist).

An example of Java + Firmata

The following shows a Java program flashing an LED repeatedly on an Arduino with the Firmata firmware. Students leverage the Java Library called Firmata4j to handle the USB connection and to transmit and receive the specific commands that the Firmata firmware understands.

This is an example of a Java program interacting with the Arduino board to make its LED turn on and off. (https://youtu.be/z2Jq4HuAJj0)

Setting up a Java + Firmata project from scratch

The following is a short (under ten minutes) video that illustrates how to get a project going in Java that can interface with an Arduino board like the one we use in EECS 1021. The board gets flashed with the "Standard Firmata" firmware via the Arduino IDE and then we use Maven inside of IntelliJ to obtain the Firmata4j library.

This video illustrates how to start a new Java project that incorporates Firmata on the Arduino board and leverages the Firmata4j library within Java. (https://youtu.be/IiOnf2uXSNw)

Connecting Java to the OLED display on the Arduino

The Arduino board that we use in EECS 1021 has an OLED on it and we can access it using Firmata. This is a short video that shows the creation and execution of a project in Java that can do this.

Using the OLED on an Arduino board using Java (https://youtu.be/RVUjxVQkkh4)

Graphing data on the computer via Princeton's StdLib

It's important for students to create visualizations of their Arduino's data, so we use the Princeton StdLib library to help them accomplish it. After trying alternatives like JavaFX, we've found that this is the most accessible and successful route for students.

We use the StdDraw component of the Princeton StdLib library to allow students to graph data from their Arduinos. (https://youtu.be/505HJjwJ1-g)

a pen

James Andrew Smith is a Professional Engineer and Associate Professor in the Electrical Engineering and Computer Science Department of York University's Lassonde School, with degrees in Electrical and Mechanical Engineering from the University of Alberta and McGill University.  Previously a program director in biomedical engineering, his research background spans robotics, locomotion, human birth and engineering education. While on sabbatical in 2018-19 with his wife and kids he lived in Strasbourg, France and he taught at the INSA Strasbourg and Hochschule Karlsruhe and wrote about his personal and professional perspectives.  James is a proponent of using social media to advocate for justice, equity, diversity and inclusion as well as evidence-based applications of research in the public sphere. You can find him on Twitter. Originally from Québec City, he now lives in Toronto, Canada.