The Fabacademy experience,

Stage 15 : interface and application programming

Home Work


The challenge this week is to write an application that interfaces with an input or output device.

Because I've never programed anything in a computer, I'm quit impressed : I don't know any language (I would probably remember some remote part of the Basic I've learnt 20 years ago... ), and I've really no idea how to start, what language to select ect.. Stress.
But we are lucky : our tutors Luciano and Guillem , have decided to teach us a specific language for this assigment, Processing. I remember Neil told us one day "if you know Arduino you'll love it".

Surprise , this is 100% true : the UI of Processing and Arduino are exactly the same, the comand are really very similar and the syntax seem to be a copy cat. The basic video tutorial from processing.org are well done , this is cool to be able to build a Paint-like program in some hours.

So everything seem to be under control, and this could be, hopefully , a lesson I can succeed ?
Well , if it was quit easy to understand and follow the course Guillem gave us, then when I was starting alone with Processing, it was not exactly the same ..

The nightmare was the serial port we have to set up in Processing , because Serial doesn't exist by default :
The exercice I decided to do is to have a photoresitor in the board side, sending the sensor value through the serial to the computer, and drawing a proporcional circle : the more the photoresistor receive light, the bigger is the circle .
I suffer 3 hours trying to make the 2 program talk together through serial . Finally Guillem send me a wonderfull piece of code for knowing the correct USB port number . The strange thing is this number change for the same computer ...?

the processing code to detect available ports the result in my computer

OK , problem SOLVED !

Then came another one : if datas are flowing between the board and the computer, the result is not the one it should be. The Processing program seem to draw circle without logical relation with the sensor.
Well, it was another longs hours trying to understand what was failing , replacing the board, then the photoresistor, then the board programm, the processing programm, trying with another computer ... But everything seem to be OK

Following pictures are the 2 codes at this stage :

the processing code the rarduino code

A day after, I finally succeed to fix it : indeed there was 2 errors.

------------- First problem were the format of the datas :

I add in both program a Serial.print in order to check in each terminal what data are sending/coming : they are not the same ! We have a correct value variation when I open the arduino terminal, playing with the light coming to the photoresistor , but when I serial.println the datas received in the processing side, they are complety differents.

I put a big delay ( 10s) in order to check in detail what's going on . If the sensor read the value "100" , the Processing side receive : Smell a protocol problem : 49,48,48 are the ascii code for 1,0,0 ! And 13 is "NL" meaning New Line, 10 is "CR" meaning Carriage Return. I found in the Processing forum that the command serial.println send the datas in Ascii format, ending by a newline + carriage return. But Processing is waiting for binary datas not Ascii.

What I need to send is binary data not Ascii => I've to use in the boardside the command Serial.write instead of Serial.print

=> SOLVED !

the processing code the rarduino code the rarduino code

------------- Second problem was about synchronisation : there is a big lag between what the sensor detect and the circle drawed

Because the lag increase with time, it sound logical this would come from the serial buffer : the board side is sending too many datas as the processing side is able to proceed. I've look for a command to erase the buffer at the end of each Processing loop, but I didn't found anything.

Finaly a quick and dirty solution was to add a delay in the board side, looking for the corect value to erase the lag effect but keeping some reactivity : a good one is 100ms

So the final Board programm is :

the processing code

=> SOLVED !

I will try now to make some process in the Procesing side, keeping the current scheme, and lighting a condicional led on the board : this mean building a fullduplex serial communication .. But out of the delay to publish it now.