Hoping this is the place to post this wuestion im not positive but Is it possible to pass an array from computer to arduino board with info from a program in a way that it can then use the bits of info to do various things. Basically what im asking is how to send the array (I am currently just using the VisualC++ example from: Arduino Playground - CPPWindows and just trying various things to send it with the Write function)
just send the array as a string with a start and a stop delimiter and a field separator, e.g. the array { 1,2,3,4,5 } can be send as "{1,2,3,4,5}"
{ = start delimiter
, is field delimiter
} is stop delimiter (end of array)
another option is is to send length, field* e.g. "5,1,2,3,4,5" for the same string as above however this latter method is less robust for missing digits.
If the array contains other datatypes similar schemes can be used.
Technically that would sort of work but you're sending a heck of a lot of characters for no reason and you're not actually indexing into the array so the numbers are hardcoded. Something more like
When im using Serial.read() will it return a string?
Serial.read returns a single character, it's up to you to accumulate them into an array and work on that (usually when you have all the characters).
This is covered al least 5 times a week on the forum so have a search around (having said that I can't find one example, try searching for "delimiter").
If you have no luck one of us will have some example code somewhere.
This code will read all the serial data, between the { and the }.
char inData[64];
byte index = 0;
bool started = false;
bool ended = false;
void loop()
{
while(Serial.available() > 0)
{
char inChar = Serial.read();
if(inChar == '{') // Did we get a {?
{
started = true;
index = 0;
inData[index] = '\0';
}
else if(inChar == '}')
{
ended = true;
break;
}
else
{
if(started && index < 64)
{
inData[index++] = inChar;
inData[index] = '\0';
}
}
}
if(started && ended)
{
// Parse the data and use it
// Reset for next pass
inData[0] = '\0';
index = 0;
ended = false;
started = false;
}
}
Where the Parse the data comment is, you can use strtok() to get each token (number as a string) and pass it to atoi() to convert it back to an int, and store it somewhere.