Paul,
Thanks. I cleaned up the brackets and was able to verify the code.
Sylvia,
Thanks. Sounds like in PLX-DAQ there is no code to write--other than setting up the Arduino to read my three axes? I'll try it out and see how it works.
Mikmo,
I am still having trouble sending the data to Excel. Am I possibly missing something in the GoBetwino setup? Here is the code that was verified--I might be off on some of the delays (I want to sample at 1000Hz), but I can play with this.
int serInLen = 25;
char serInString[25];
int xpin=5;
int ypin=6;
int zpin=7;
int pId = 0;
int result;
void setup()
{
// Set up serial communication. Start Excel.
Serial.begin(9600);
Serial.println("#S|SPXL|[]#"); // start Excel
readSerialString(serInString, 5000); //wait 5 seconds (max) for answer from Gobetwino (=process ID)
pId= atoi(serInString); // convert result to integer
sendPotValues(); // send some data to Excell
}
void loop()
{
//analogValue= random(0,1023);
//logData(analogValue);
//delay(5000);
}
void sendPotValues()
{
char buffer[5];
int potValue1;
int potValue2;
int potValue3;
for (int i=1; i<=15; i++){
//Read the three pot values - acceleration values
potValue1 = analogRead(xpin);
potValue2 = analogRead(ypin);
potValue3 = analogRead(zpin);
//Send the values as though it was typed into Excell, using the SENDK command
// This is the total line that is send: #S,SENDK,[pId; xpin {TAB} ypin {TAB} zpin {DOWN} {LEFT} {LEFT}]#
Serial.print("#S|SENDK|[");
Serial.print(itoa((pId), buffer, 10));
Serial.print("&");
Serial.print(itoa((xpin), buffer, 10));
Serial.print(" {TAB} ");
Serial.print(itoa((ypin), buffer, 10));
Serial.print(" {TAB} ");
Serial.print(itoa((zpin), buffer, 10));
Serial.print(" {DOWN} ");
Serial.print(" {LEFT} ");
Serial.print(" {LEFT} ");
Serial.println("]#");
// wait up to 1 ms for answer from Gobetwino, answer will be in serInString, answer is 0 if all is OK
readSerialString(serInString, 1);
//Deal with answer here - omitted in this example
delay(2);
}
// Now we have sent the 3 acceleration values X times, so save and close the XL sheet.
Serial.print("#S|SENDK|[");
Serial.print(itoa((pId), buffer, 10));
Serial.print("& ");
Serial.print("^s^w"); //= CTRL+S CTRL+W = save and exit
Serial.println("]#");
// Wait 2 seconds for the save to finish
delay(2000);
// wait up to 1000 ms for answer from Gobetwino, answer will be in serInString, answer is 0 if all is OK
readSerialString(serInString, 1000);
}
//read a string from the serial and store it in an array
//you must supply the array variable - will return if timeOut ms passes before the sting is read so you should
//check the contents of the char array before making any assumptions.
void readSerialString (char *strArray,long timeOut)
{
long startTime=millis();
int i;
while (!Serial.available()) {
if (millis()-startTime >= timeOut) {
return;
}
}
while (Serial.available() && i < serInLen) {
strArray = Serial.read();