Sunday, May 22, 2011

The problem's source

Last friday i noticed that our Arduino Mega board wasn't giving us the right input, but why?

My first suspicion was firmata, the firmware loaded onto the the microprocessor,
but looking at the firmata code and testing it with the firmata testing program showed that the arduino was indeed sending data for all of the 54 digital (on/off) and 16 analog (range of 1-1024) pins correctly.

There were only 2 other links in the chain, my processing code and the Arduino library that gets loaded into processing.

All the analog pins worked, but any pin above 15 was not being read by processing, an inspection of the source code for the Arduino library showed some hope, the array for storing inputs for both digital and analog were both 16 long, so extending that should work, right?

int[] digitalInputData = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, etc.. };
no, perhaps if i change the Max bytes from 32 to 70 to hold all the pins?
no, perhaps if i increase the data cap at witch it stops loading data into an array?
no, (a huge amount of println's later) What is this datastream? where is that variable set? Gaaaah!

So after 2 days of cursing and testing, i decided to re-do the whole thing, upload arudino firmware, re-write processing program, and revert the library back to it's original state.
There are multiple firmata programs, Standard, allinputs, and a few more, but as allinputs wasnt compiling due to an error i coudnt figure out, i had been uploading standard firmata.
After a google, i read that changing :

sendPort(i, readPort(i));
to
sendPort(i, readPort(i, 255));

fixed the error, i did so, uploaded it, and everthing worked.. 2 days of utter fustration and it was this little error in firmata's own code.

Why everything worked in the firmata tester and not in processing earlier? nobody knows.

No comments:

Post a Comment