INTRODUCTION
At the end of every year, I try to do a project with hardware/software I had not explored before. Having a little over 10 years of exploring microcontrollers, I came across something I never bumped into when researching my prior projects. Searching element14, I found that there are very few posts on it despite it being the father of the Arduino IDE. So, I thought I'd share as I see it as a major tool in the tool kit.
What I found was the language ecosystem called "Processing IDE". For those of you who have used it, don't bother with this brief blog. For those of you who have not used it, this can be a game changer for developing your embedded projects.
DEFINITIONS
First, some definitions I'll use loosely:
GUI-Graphical User Interface: an application that allows a user to interact with the device typically via touch screen or mouse input.
HMI-Human Machine Interface: Used often to represent both the GUI and the hardware used for a person to control a device. It doesn't have to have a GUI, but rather just physical buttons or the device may just take voice commands for its HMI.
REFERENCES
Arduino and HC-05 Bluetooth Module Complete Tutorial (howtomechatronics.com)
PROJECT BILL OF MATERIALS
Arduino Nano 33 IoTArduino Nano 33 IoT
MY PROJECT
What led me to the Processing IDE was a project to explore the HC-06 Bluetooth module. The HC-06 project isn't the star of this blog, but serves as a great example of how you can use the Processing IDE. It can be used with most serial enabled devices (although my iPhone wouldn't list it for pairing). If you have a Tx and Rx on a device, you can have them talk to other devices wirelessly with the HC-06 brokering the serial transmission. The HC-06 is the Bluetooth "slave only" version which keeps things very simple for your projects.
It can be reliably powered by 3.3V, so it is directly compatible with Raspberry Pi's and the newer Arduino Nano series. Several documents state that if you power it with 5V, you have to do your own logic voltage level shifting in your circuit - for example, with a resistor based voltage divider.
This is what the module looks like:
To test the HC-06, I needed just needed my Arduino code to read available incoming bytes from Serial1 of my Arduino Nano IoT 33. I also needed another device to play the role of the Bluetooth master to send those bytes. That's where the "Processing IDE" walked in.
Side Note: Before we leave this topic - note that I said Serial1 above. On the Arduino Nano series, "Serial" without the "1" is for communicating with the USB serial bus and displaying the communication in the Serial Monitor available in the Arduino IDE. Serial1 (with the "1" at the end) is for communicating serial via pin 0 and pin 1. For me, that was a real head scratcher that took the O-scope to get down the right track- not knowing that "Serial1" was a thing.
HISTORY OF "Processing IDE"
Processing IDE has its start all the way back to 1975 at MIT. They desired a quick means of graphical programming in "sketch" fashion. It changed hands a couple of times over the years until it hit its modern day era around 1999 as Java spread across the globe.
A few years later, the Arduino IDE project grew out of Processing IDE while its MIT founder Casey Reas was teaching at the Interaction Design Institute Ivrea in Italy(1). In turn, the development environments as well as core libraries, reserved keywords, and base methods are all very familiar.
Here is how they look side by side as of 2021:
Processing IDE (Left) Versus Arduino IDE (Right)
Both environments have the same approach to structure. They both look like "C" or "Java". They both have a "setup" method. They both have a method that continuously loops after the "setup" method is executed. For Processing IDE, the looping method is "draw" which allows you to handle events and update the GUI (application window) accordingly in a forever loop. For Arduino, the looping method is named "loop".
If you are already versed with Arduino, you can be coding standalone applications for PC/Linux, Android, and the Raspberry Pi with a "write once/use everywhere" approach using the Processing IDE.
THEORY: Why I haven't seen "Processing IDE" before?
My son and I have done many projects over the years. Many can be found here at element14. Still, the "Processing IDE" language never jumped out at me as I researched for my projects. Here is why I think I hadn't discovered it:
- It came into its modern state after I graduated college.
- Only recently have I tackled projects desiring wireless HMIs.
- Maker tutorials using PCs or smart phones are rare to come by such as those archived on the Arduino Playground.
- When folks want a separate HMI, they often go with using mobile phones. You most often see one using the phone as a web client and the microcontroller as the server can provide a quick, auto sized, attractive approach to a GUI. Another common approach is an Android app.
- The Python and its pygame library has come into vogue in the last several years for GUI design. This, too, can be used cross platform.
- The name "Processing IDE" doesn't exactly jump out as a language option when skimming search results.
WHEN WOULD I USE THE "PROCESSING IDE" LANGUAGE?
I would definitely use it when I need a wireless or wired PC/laptop HMI for an embedded project. I'd prefer it over Python because it can generate a standalone, double-clickable executable without the need of installing an interpreter.
I'd also use it to teach newcomers programming in general. It gives you that old school Commodore 64 BASIC feel.
I would also use it to teach youngsters that are new to the Arduino. Having the look-and-feel of its IDE being so similar to the Arduino IDE removes many learning obstacles for the beginner.
Processing IDE also has a bunch of the common libraries for doing amazing things like OpenCV which could be used to do a lot of things that folks do with the Raspberry Pi, but instead do them with one's PC or laptop. It could breath new life back into a desktop PC that you keep on all the time as a whole house automation hub without any limitations.
WHAT OTHER ALTERNATIVES ARE THERE FOR DESKTOP GUIs?
In my past, I would use Unity to do the PC side GUIs - which gives one a great more power and display capabilities, but comes with a lot of overhead, time, and knowledge to produce the application.
Python has its place still for me due to its large user base, many canned libraries available, and many tutorials. However, I like the Java language much more than Python if I don't have any library dependency limitations.
Another approach is to use an ad hoc WiFi connection (or LAN Network) to the microcontroller. The microcontroller would pipe out HTML to a connected client. This is a good approach as you can use the ever popular jQuery application Bootstrap to handle all the heavy work of laying out the GUI and autosizing it to any device.
CODE
Here is the code I used to get my HC-06 talking to my Arduino Nano 33 IoT. I followed a tutorial (referenced in the code originally by Dejan Nedelkovski) for the Uno, but ported it for the Nano.
I also made the PC side automatically poll and detect the correct COM port which makes it much simpler for an end user who wants to just turn it on and it start working.
Arduino Side (Arduino IDE):
//Originally from: https://howtomechatronics.com/tutorials/arduino/arduino-and-hc-05-bluetooth-module-tutorial/ //Updated for the Nano by Sean J. Miller 2021. MIT License #define ledPin 7 int state = -1; void setup() { pinMode(ledPin, OUTPUT); digitalWrite(ledPin, LOW); Serial.begin(9600); // Default communication rate of the Bluetooth module Serial1.begin(9600); } void loop() { if(Serial1.available() > 0){ // Checks whether data is comming from the serial port Serial.println("Receiving!"); state = Serial1.read(); // Reads the data from the serial port Serial.println("Done Receiving!"); } if (state == '0') { digitalWrite(ledPin, LOW); // Turn LED OFF Serial1.println("LED: OFF"); // Send back, to the phone, the String "LED: ON" state = -1; } else if (state == '1') { digitalWrite(ledPin, HIGH); Serial1.println("LED: ON"); state = -1; } else { delay(1000); Serial1.println("Ready"); } }
PC Side (Processing IDE):
//Originally from: https://howtomechatronics.com/tutorials/arduino/arduino-and-hc-05-bluetooth-module-tutorial/ //Updated for the Nano and additional functionality by Sean J. Miller 2021. MIT License import processing.serial.*; Serial myPort; String ledStatus="LED: OFF\n"; boolean DEBUG=false; boolean CONNECTED=false; String the_port=""; void setup(){ size(550, 600); surface.setTitle("Raising Awesome"); // List all the available serial ports ShowConnectionMessage(); } void ShowConnectionMessage() { background(0, 0, 0); textSize(24); fill(255); text("Status:", 230, 180); fill(255,0,0); textSize(24); text("Connecting to Bluetooth...", 110, 230); fill(155); textSize(16); text("Program by Sean J. Miller", 170, 320); } void serialEvent (Serial myPort){ // Checks for available data in the Serial Port if (DEBUG) println("About to get serial!"); ledStatus = myPort.readStringUntil('\n'); //Reads the data sent from the Arduino (the String "LED: OFF/ON) and it puts into the "ledStatus" variable if (DEBUG) println("Got Serial",ledStatus); } void draw() { if (!CONNECTED) ConnectToBluetooth(); background(0, 0, 0); fill(20, 160, 133); // Green Color stroke(255); strokeWeight(4); rect(50, 100, 150, 50, 10); // Turn ON Button rect(350, 100, 150, 50, 10); // Turn OFF Button fill(255); textSize(32); text("LED ON",62, 135); text("LED OFF", 362, 135); textSize(24); fill(255); text("Status:", 230, 200); textSize(30); textSize(16); text(" Program by Sean J. Miller\n Copyright 2021 by Raising Awesome", 80, 320); text(ledStatus + the_port, 245, 240); // Prints the string comming from the Arduino if(mousePressed && mouseX>50 && mouseX<200 && mouseY>100 && mouseY<150&&CONNECTED){ myPort.write('1'); // Sends the character '1' and that will turn on the LED // Highlighs the buttons in red color when pressed stroke(255,0,0); strokeWeight(2); noFill(); rect(50, 100, 150, 50, 10); if (DEBUG) print("clicked on"); delay(250); } // If the button "Turn OFF" is pressed if(mousePressed && mouseX>250 && mouseX<400 && mouseY>100 && mouseY<150&&CONNECTED){ myPort.write('0'); // Sends the character '0' and that will turn on the LED stroke(255,0,0); strokeWeight(2); noFill(); rect(250, 100, 150, 50, 10); if (DEBUG) print("clicked off"); delay(250); } } void ConnectToBluetooth() { String the_coms[]=Serial.list(); while (!CONNECTED){ for (int ii=0;ii<(the_coms.length-1);ii++) { if (DEBUG) print (the_coms[ii]); try { myPort = new Serial(this, Serial.list()[ii], 9600); myPort.bufferUntil('\n'); myPort.clear(); the_port=Serial.list()[ii]; delay(3000); if (ledStatus=="Ready") { CONNECTED=true; if (DEBUG) println("Connected!"); break; } } catch (RuntimeException e){ if (DEBUG) println("!Error!"); } } } }
Desktop PC GUI by the Processing IDE
CONCLUSION
I consider Processing IDE a hidden GEM for PC coding as I believe it has been overshadowed by Python over the last decade. For those that are swift with any of the semicolon languages (Arduino IDE, C/C++, C#, Java, or JavaScript), you'll quickly find that the Processing IDE can be your go-to HMI language or Bluetooth embedded application prototyping engine.
With it also having great libraries such as for OpenCV, you now no longer are at the limitations of BeagleBone's and Raspberry PIs hardware for advanced video based AI, too - such as facial recognition, object recognition, and image segregation techniques. Last, if you have old Android phones or Amazon tablets collecting dust, you can use them as touchscreen HMIs for your embedded projects using the Processing IDE as well.
In sum, if you haven't explored the Processing IDE, yet - it's definitely worth a look!
-Sean J. Miller
Top Comments