| Home | | Weekly Assignments | | Final Project | | Photo Gallery |

Week 16 - Interface & application programming.
This week's assignment is to create an application that interfaces with an input/output device I made. I had already made a ambient light sensor in the input week's assignment. So here I will be creating an application that interfaces with the light sensor.
First I tried creating an interface which shows some graphical interface that changes according the the change in ambient light. For doing this, I tried my luck it Python, but could not figure out a good way to pull it off.
While exploring other ways to complete learn and complete this task, I came across Processing an open source software which can create cool 2D/3D interactive prgrams and applications. This was exactly what I was looking for.
Processing
Processing is a flexible multi-platform software sketchbook and a language for learning how to code within the context of the visual arts. Software prototyping and data visualization are two of the most important areas for Processing. Processing is very easy to use and the documentation for the same is available on its website.

I downloaded and installed Processing on Ubuntu. I used FTDI to connect the ambient light sensor board I made to my lapotp. The plan is to use processing to show a graphical representation of the ambient light picked up by the light sensor on screen. A yellow circle displays on screen and when the light is reduced, it will be replacaed by a grey circle which represents the moon.

I had trouble getting the board properly connected with the serial port and getting deteced while programming in Ubuntu. I modified the code written by Anna Nispeielak using the Processing editor. After a few trial and error, by setting the correct serial port and speed which is: /dev/ttyUSB0 9600
Code
import processing.serial.*; Serial myPort; int val; int sensorData; int highVal; int lowVal; int actualVal; void setup() { size(400, 400); String portName = Serial.list()[0]; myPort = new Serial(this, portName, 9600); } void draw() { if (myPort.available() > 0) { val = myPort.read(); if (val > 4) { highVal = myPort.read(); lowVal = myPort.read(); actualVal = 256 * (highVal + lowVal); println("The actualVal is " + actualVal); } if (actualVal < 800) { // If the sensor value is less than a this number background(142, 255, 233); fill(255, 249, 44); // set fill to black ellipse(200, 200, 200, 200); } else { // otherwise.... background(7, 47, 54); fill(255); // set fill to light gray ellipse(200, 200, 200, 200); fill(7, 47, 54); ellipse(210, 200, 180, 180); } } }
What the above code does is, create myPort object from Serial class and the sensorData object stores the date recived from the serial port. Based on the real time values recived from the sensor, the elipse in the bottom part of the code is set to change its colour.
Here is a working video of it:
Now I had to convert it into and independent application which runs without the helps of the processing software everytime.

Buy clicking this option, the visual interface for reading and displaying input can be exported as a double clickable standalone application for platforms such as windows and linux.

Now I also have executable files of this interface application for different OS platforms.