It compiles flawlessly but the serial monitor shows nothing (should show "tizio")!
On what version of the IDE? Prior to 1.0.1, the failure of the compiler to find an include file was a fatal error. With 1.0.1, the failure to find an include file doesn't even generate a warning.
The failure to find the include file would explain the behavior you are seeing.
Eventually, my goal is to import a bidimensional array of numbers, but right now, for testing purposes I am experimenting with the following:
The entirety of "mydata.hh" contains the following text:
"tizio", "caio", "sempronio"
The entirety of "numbers.hh" contains:
1,2,3,4
"mydata.hh" on disk is 30 bytes long.
"numbers.hh"on disk is 9 bytes long.
guix:
It should work, are you sure the baud speed is the same in the serial monitor window?
Yes I made sure they are the same.
PaulS:
With 1.0.1, the failure to find an include file doesn't even generate a warning.
The failure to find the include file would explain the behavior you are seeing.
I am using 1.0.1
If I don't put the whole path, the compilers gives me an error: "No such file or directory".
This morning, after posting the reply above I re-run the sketches without changing anything and they work!
One thing that I did not mention is that yesterday, after changing something here and there and re-verifying I was getting a bunch of random errors that did not make much sense, such as that I already declared variables that were not even in the sketch anymore.....
Next I will actually try to import my large bidimensional array with the same method and I may reach for help again, but thank you for taking the time to answer.
One thing: does Arduino work better in daytime?
Any problem with full moon?
Perhaps random was not the right term, incomprehensible is better.
I was getting something like (I don't remember it verbatim and the error did not show up again, this morning): variable char[] already defined
when I never defined a variable called char[].
In a previous sketch I had defined
char* data[]
Maybe there is some reason for it {the pointer was still in the computer/arduino memory ??)
But if there is it is definitely not obvious :0
Ok, I think I did it.
I found a way to keep a large array of data in a separate text file and importing it in my sketch as an #include.
The advantages of doing that are:
you can modify and update your data file without touching the sketch.
you don't have to put an unsightly long declaration in your code.
you don't even have to re-verify your code after modifying the data but you have to re-upload it
I thought this was a fairly established thing to do but I could find hardly any documentation.
I am posting my solution here hoping it may be helpful to some other newbie.
/* This examples illustrates how to import numeric data from a separate Text file
By Luca Brigatti - 2012
witht he help of the folks in the Arduino programming forum.
Note: Leaving the first dimension empty: data[][2]
and using: sizeof(data)
to calculate the size of the array in bytes eliminates the need to know beforehand
how many values are there in the file.
The operation: maxIndex = sizeof(data) / 4 - 1
return the highest index number of the first dimension: data[maxIndex][2]
The denominator (4 in this case) is the product of the number of bytes per data type (2 bytes per integer)
times the size of the second dimension ([2] in this case)
The text file being read: "numbers2.hh"
contains something like that:
________________________
// Example of bidimensional numeric data array
// The actual numbers can be any int (if the data array is int)
{1,1},
{-2,4},
{3,-9},
{4,}, // Second element here will be 0, Like: {4,0},
{-5,-25},
......
_________________________________
Note: {,4}, i.e leaving the first place empty is NOT allowed.
*/
// Main importing instructions. data[][2] can be a variable
static const int data[] [2] = {
// Put the name of the file with the complete Path
#include "E:\Downloads\Devices\Arduino\arduino-1.0.1\data\numbers2.hh"
};
int maxIndex ;
int arraySize ;
void setup() {
Serial.begin(9600); // Initiate serial
arraySize=sizeof(data); // Gets the size of the array in bytes
maxIndex = arraySize/4 - 1; // Size /2 (bytes in an int) /2 (for a bidimensional array) - 1 (as index starts at 0)
// Print dimensions of the array
Serial.print("Array Size (bytes): ");
Serial.println (arraySize);
Serial.print ("# of rows: ");
Serial.println(maxIndex+1);
delay(2000);
}
void loop () {
// Print all the data in the array, over and over again
for (byte i=0; i<=maxIndex; i++) {
Serial.print (data[i][0]);
Serial.print (" , ");
Serial.println (data[i][1]);
}
delay(500);
Serial.println();
}