Now
its time to program something usable. This week we have to take an
input pcb that we had made and make a program to interact with it.
Arduino and Processing
I decide to do this week
assignment in Processing, because it was a new lenguaje for me. First
of all we need to install the Proccessing IDE.
In my experience, the processing
version must be according to the Java version. If you install the Java6
version, you could install any of the processing version (the stable
1.5.1 or the 2.0 Beta version), but if you install the Java 7 package,
i recommend use the 2.0 version of Processing. The stable version give
me some error with Java 7.
After this, processing is a
portable program, so you dont need to install it.
PROBLEM
When you start processing as a
normal user (at least in Ubuntu), this user dont have access to the USB
port, so if you try to run some program that try to use this port, the
system dont let them pass.
SOLUTION
Start the processing program as
superuser. After spend three days searching troubles with FTDI os
something like that, finally i started it with the command:
$ sudo ./processing
and finally i could read the data
from the board.
My program with Hello.light
I want to play with the Hello.light i solder in the Input week, so i
think the program could give me a good view of how many light there are
in the ambient.
So basically the processing program will draw a sun if the valor of the
sensor is lower than a valor and will draw a moon if the valor of the
sensor is higher.
This sensor returns a higher value if there are less light.
Processing has two important blocks of code: setup and draw.
"void setup()" its the way to initialize the enviroment of the program
(windows, canvas, colours).
"void draw()" is the main program, and it loops continuosly. Its like
the "int main()" in C.
I decide to add some details, so while its daylight there are two
little birds flying around the sun, and when its moonlight...watch the
video and see it yourself :)
size(700, 400); //Anna Kaziunas code for hello.light
// I know that the first port in the serial list on my mac
// is always my FTDI adaptor, so I open Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
imget = loadImage("et.gif"); // variable that contains a image file
}
void draw()
{
if (myPort.available() > 0) { // If data is available
val =
myPort.read();
// read it and store it in val
if (val >
4)
{
// Filter out the framing numbers: 1,2,3,4
println("The actualVal is " + val); //drop the valor in the terminal to check
valorbueno = val;
//i will use a variable with usable valors. 1,2,3,4 didnt store here.
}
if (valorbueno < 160) { // if its lightly. This valor must change to fit the needs
sol();
// draw the sun
}
else
{
luna(); // draw the moon
}
}
}
Working with processing
That
was the hardest job, to learn the lenguaje. Fortunately the main web
page of processing has a great learning documentation to get all the
objetives you could get:
The
change in the sensor value isnt as quick as i expected. Maybe this
photosensor isnt as sensitive and there are other in the market that
could bring this results more efficient. Or maybe my board arent well
solder, or my DIY FTDI cable isnt as good as i should be.
I must work with the optimization of the response time in the photosensor and the code inside.