Gobetwino: Arduino talking to Excel

Gobetwino is pretty easy use. The Arduino can now send words to the serial port and Gobetwino takes them as commands and does handy stuff like create csv’s send email etc. I’ve tested out this program by making the Arduino log the voltage of a discharging capacitor and send the details to Gobetwino to make a csv for Excel.

Circuitry

 

Log discharging capacitor, use FET's instead of BJT's if you want to avoid 0.6V drop


Arduino Code


//    Arduino code
//    Arduino to Excel using Gobetino

//      - Arduino logs 100 values
//      - Gobetwino takes these values and puts them in data.txt

//      - Excel Imports this file as a csv and draws the graph
// ==========< option 1 >==========
//      FIRST logs data to chip's sram,  THEN sends to pc using Gobetwino
//      - 1028 bytes can be stored

//      - readings are taken fast this way

// ==========< option 2 >==========
//      log straight to .txt with Gobetwino
//      - approximately a max of 37 readings/sec , depending on the serial speed you choose

//      - this way is safe (unlimited with the chips 1024 bytes of SRAM)
// ============< variables >==========

//  A0   -   Vcap
//  D3   -   button/switch    (trigger)

//  D4   -   transisters to charge & discharge cap
//  D5   -   LED 1

//  D6   -   LED 2 const int size = 100;
// number of readings (size of array must be constant)
// don't make it too big, arduino has limited memory const float Vss = 5.0;
// if you want to be more accurate measure arduino's Vss int arrayms[size];
// an arary to store time

int
arrayA0[size];
// an arary store voltage
int
a;
// counter
long startTime;

void setup() {
pinMode
(2, INPUT); // button
pinMode
(3, OUTPUT); // pin connected to transistor bases
pinMode(4, OUTPUT); // LED 1
pinMode(5, OUTPUT); // LED 2 LED's are used to show what stage the chip is in
pinMode(6, OUTPUT); // LED 3

Serial.begin(9600);
}

void loop() {

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /* test stuff
while(digitalRead(3)){}              // wait until I press pin 3 (trigger button)

while(!digitalRead(3)){}

Serial.println("#S|CPTEST|[]#");     // Use the CPTEST copy file command to make a copy of a new empty logfile

while(digitalRead(3)){}              //wait until I press pin 3 (trigger button)

while(!digitalRead(3)){}

digitalWrite(3, HIGH); // start charging capacitor
delay
(500); // wait 500 ms for the capacitor to charge
while
(digitalRead(2)){ digitalWrite(6, HIGH);   }
digitalWrite(6, LOW);
digitalWrite
(4, HIGH); // LED 1 tells you the capacitor should be charged

wait_until_pin_3_is_pressed(); // ------------------------------
a=0;
startTime =
millis();
digitalWrite
(3, LOW); // discharge capacitor
while
(a <= size )   {
arrayms[a]=
millis()-startTime; // record time
arrayA0[a]=
analogRead(0); // record Vcap
a++;
delay(1); // wait however ms before taking the next reading }
digitalWrite(4, LOW); // If LED 1 doesn't switch off, there is a problem in stage 1
digitalWrite(5, HIGH); // LED 2 tells you that Stage 2 is ready to start
wait_until_pin_3_is_pressed();

// ----------------------

a=0;

while
(a <size){
Serial.print("#S|LOGTEST|[");
// #S -> tells gobetwino to listen

// |LOGTEST|[ -> Gobetwino runs the LOGTEST command I made,
// which opens data.txt in this app's folder

// NOTE: there must already be a data.txt in the folder

printDouble(
double(arrayms[a])/1023*Vss, 3);
Serial
.print(";");
printDouble(
double(arrayA0[a])/1023*Vss, 3);
Serial.println("]#");
// # tells Gobetwino to stop paying attention
a++;
}
digitalWrite(5, LOW); // if LED2 doesn't switch off you're stuck in Stage 2
}
// end of void loop()
// somebody elses function I found to print doubles
void printDouble( double val, byte precision){

// prints val with number of decimal places determine by precision

// precision is a number from 0 to 6 indicating the desired decimial places

// example: printDouble( 3.1415, 2);

// prints 3.14 (two decimal places) Serial.print (int(val));

//prints the int part if( precision > 0) { Serial.print(".");

// print the decimal point

unsigned long frac; unsigned long mult = 1;

byte padding = precision -1; while(precision--)       mult *=10;

if(val >= 0)

frac = (val - int(val)) * mult;

else frac = (int(val)- val ) * mult;

unsigned long frac1 = frac;

while( frac1 /= 10 )       padding--;

while( padding--) Serial.print("0");

Serial.print(frac,DEC) ;   } }

void wait_until_pin_3_is_pressed() {

while( !digitalRead(2) ){   }

while( digitalRead(2) ){   }

}

How Gobetwino works

Before trying to use this program you should read the Gobetwino pdf. You basically have to open Gobetwino and create a command to handle .txt files. I did this by opening Gobetwino and creating a LOGTEST command to open log.txt

  1. Click on the Commands menu
  2. Selecting LGFIL (Log File command)
  3. Select the file location of an existing .txt file (data.txt in this case)

Now when the Arduino serially prints LOGTEST a .txt file is opened.

   Serial.print("#S|LOGTEST|[A,B,C]#");
  • #s tells Gobetwino to pay attention
  • |LOGTEST| is the command I created with Gobetwino to open data.txt
  • [A,B,C] are variables printed to the file
  • # tells Gobetwino to stop paying attention


Summary

  1. Upload the code to the Arduino
  2. Create the LOGTEST command with Gobetwino
  3. Press the button on your circuit (capacitor discharges)

I then import the .txt with excel and create the following graph

The voltage of the discharging capacitor

Notice the capacitor doesn’t fully discharging because I used BJT’s instead of FET’s.

Advertisements

8 thoughts on “Gobetwino: Arduino talking to Excel

  1. I found from your code, the procedure to store capacitor discharge data in “.txt” format. Do you import this data to Excel file later on? you require “.CSV” format to store directly in Excel file? isn’t it?

  2. lazy me.

    I’m so used to calling .txt files that have comma separated values in them csv’s.

    If you run excel and open the file (.txt) it asks if you how you want to import the data, where you can select commas, semi-colons etc.

  3. Fine web!
    please, can you help me? ( I am sorry for my English )

    I need to print: ( to EXCEL)
    Nr. of measure value1 value2
    1 2.54 3.05
    2 3.00 1.56 for example ….
    ………………………………………………………………………………..
    but I can´t print a float of number

    and I don´t understand this:

    logData ( … … ) is there necessary ?
    (itoa((value1), buffer, 10)) and
    printDouble( double(value3)/1023*Vss, 3)

    Best regards
    jiri

    • I’ve edited the code and put in tons of comments. Hopefully it’ll help.

      The printDouble function is what you must use if you have Arduino 0018 or older.

      Newer version can print doubles.
      I recomend learning Processing, the father of Wiring (Arduino’s language.) With that you can make a program yourself to chat to the arduino, make graphs, export csv’s etc. It’s nearly identical to programming the arduino, with all the example code. You can simply open one of it’s examples that involves .txt files and you’ll be done in no time. Langauge is SO similar, just with plenty more toys.

  4. First of all Congracts for your working and thanks for sharing it !! It is very difficult to find webpages like yours. Thanks for sharing it !!
    Well, it is very interesting to make a log files, it is very useful. But, for my project i think it is more interesting to make a live sending data to excel. Is it possible to make it using the Gobetwino? Imagine a sonar sending information to Gobetwino and this software send the information to different lines and columns and live generating a chart with the information there is being received.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s