Week 17: interface and application programming
May 18 - 24
Assignment
- Write an application that interfaces with an input &/or output device that you made
Processing Interface

For the interface assignment, I wanted to create a visual representation for my temperature input. I turned to Processing in order to achieve this. I left the setup from the previous input device assignment, with the thermistor temperature sensor attached to the satshakit. I made some slight adjustments to the code to only output a single set of numbers through the serial port 9600. I then followed this Sparkfun tutorial on how to communicate to processing using the serial port. Additionally since this was my first time delving into Processing, I used a variety of tutorials for the basic language and object drawing from their website
The initial problem I ran into was determining my serial port on my Macbook. There isn't exactly a manual on this, so I tried making the connection several times without success. I did notice that one port kept reporting that it was busy. I then noticed that I still had the Arduino IDE open, and thought perhaps that this was the culprit. I closed the program and magically Processing was able to read the port. Now, this information seems to be common knowledge for people who have worked with these serial ports before, but for one who is doing this for the first time, this is not intuitive. None of the tutorials that run you through this process even care to mention this. This in my opinion is a rather large oversight in user experience. The common occurence of engineers developing tutorials seems to be facing towards other engineers. This creates an large learning block and steepens the curve for others trying to enter this space. Absolutely terrible.
The second hurdle was to convert a string from the serial into an integer or float, in order to process it for my interface. With some Googeling, I was able to find the solution using the float()
command.
At this point, I had most of it up and running, however I kept receiving a nullpointerexception
error a few seconds after the program had started. I did another Google search and found that it was a common error, where a value was not given an inital value. I checked all my integers and floats and found them all zeroed out in the code. The only value that could have been the culprit was the string. I did not know initially how to to this, but through more searches, I was able to set it to string xxx = null
. This solved the problem and everything was stable.

At first I used my hand to warm it up, but the difference was not very noticable. So, I took the heat gun and gave it a short blast.

The interface functioned as planned! I did not dare to do it too much in fear of damaging the board, so I was content with the slight movement that was displayed.
Below is the code that I hacked together. Overall Processing is simple to learn, with a lot of potential. I will spend more time delving deeper into this when I have the time!
import processing.serial.*; import cc.arduino.*; int lf = 10; // Linefeed in ASCII Serial myPort; // Create object from Serial class String myString = null; // Data received from the serial port float angle = 0; void setup () { String portName = Serial.list()[1]; //change the 0 to a 1 or 2 etc. to match your port myPort = new Serial(this, portName, 9600); size(100, 100); fill(0); } void draw() { while (myPort.available() > 0) { myString = myPort.readStringUntil(lf); if (myString != null) { print(myString); // Prints String angle=float(myString); // Converts and prints float println(angle); } } myPort.clear(); background(204); if (keyPressed == true) { if ((key >= 32) && (key <= 126)) { // If the key is alphanumeric, // use its value as an angle angle = (key - 32) * 3; } } arc(50, 50, 66, 66, 0, radians(angle)); }