How can I use data logger shield to collect data?

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
POTOOLE
 
Posts: 13
Joined: Tue Mar 06, 2012 3:00 pm

How can I use data logger shield to collect data?

Post by POTOOLE »

I have attached an ADAFRUIT data logger shield to an Arduino UNO.
I can use readwrite-arduino to download text to an SD card, but I want to collect voltag pulses at pulses per second.
I tried using/modifying this arduino sketch to download collected pulsating voltages as pulses per second
/*
SD card read/write

This example shows how to read and write data to and from an SD card file
The circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 10

created Nov 2010


*/

#include <SD.h>

File myFile;

void setup()
{
Serial.begin(9600);
Serial.print("Initializing SD card...");
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
pinMode(10, OUTPUT);

if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");

// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open("test.txt", FILE_WRITE);

// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}

// re-open the file for reading:
myFile = SD.open("test.txt");
if (myFile) {
Serial.println("test.txt:");

// read from the file until there's nothing else in it:
while (myFile.available()) {
Serial.write(myFile.read());
}
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}

void loop()
{
// nothing happens after setup
}

On the SD card I get, "Writing to test.txt..., testing 1, 2, 3" etc

I'm using in pre-setup,
#include <SD.h>
int digipin = 2;
int wavin = 0;

I added a void loop() , I'm using, in the loop
attachInterrupt(0, freqin, RISING);

and a function after the loop,
void freqin()
{
wavin = wavin + 1;
}

mwilson
 
Posts: 46
Joined: Sun Oct 23, 2011 11:17 am

Re: How can I use data logger shield to collect data?

Post by mwilson »

I've never done this, but I think your code should be more like

Code: Select all

/*
Logging to SD card
* SD card attached to SPI bus as follows: */
const int MOSI = 11;
const int MISO = 12;
const int CLK = 13;
const int CS = 10;

#include <SD.h>

File myFile;

void setup()
{
    Serial.begin(9600);
    Serial.print("Initializing SD card...");
    // (10 on most Arduino boards, 53 on the Mega) must be left as an output
    // or the SD library functions will not work.
    pinMode(CS, OUTPUT);

    if (!SD.begin(4)) {
        Serial.println("initialization failed!");
        return;
    }
    Serial.println("initialization done.");

    // open the file. note that only one file can be open at a time,
    // so you have to close this one before opening another.
    myFile = SD.open("test.txt", FILE_WRITE);

    // if the file opened okay, write to it:
    if (!myFile) {
        // if the file didn't open, print an error:
        Serial.println("error opening test.txt");
    }
}

void loop()
{
    while (not_done_yet()) {
        // get a new reading, format it, etc and then
        myFile.println( ... );    // write the formatted reading to the chip.
    }
    // close the file:
    myFile.close();
    Serial.println("done.");
}
`not_done_yet` would have to check a button, or check the time, or something to determine that you want to stop sampling and wrap up.

Sometimes it's awkward that Arduino's "embedded" programming model assumes that processes loop forever. Maybe your not_done_yet button should be changed to mean "close the SD card, pop it out, and wait for a new one to be inserted."

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: How can I use data logger shield to collect data?

Post by adafruit_support_bill »

but I want to collect voltag pulses at pulses per second.
Can you be more specific? What do you want to log, pulses or pulse frequencies. If you are logging frequencies, you need to define the sample period for counting the pulses.

POTOOLE
 
Posts: 13
Joined: Tue Mar 06, 2012 3:00 pm

Re: How can I use data logger shield to collect data?

Post by POTOOLE »

Can you be more specific? What do you want to log, pulses or pulse frequencies. If you are logging frequencies, you need to define the sample period for counting the pulses.


As a for instance, voltage pulses coming from the speed sensor on a motorcycle. They are a result of a magnetic Hall Effect sensor which is in close proximity to a gear in the transmission. These pulses are used to operate the speedometer. They are square wave pulses of about five volts (peak voltage). Of course, the faster the bike is moving, the higher the frequency of the pulses. I want to record the pulses in pulses per second. From this I can build a curve, comparing speed (on Y axis) compared to pulses per second (on the X axis). I want to determine changes in the motorcycle performance after mechanical changes are made. I could go to a shop, have them put it on a dynomometer for $100 a try.

I've done this before, but by an older more complicated method; but I don't remember the sketches that I used. I thought the Adafruit data logger shield would be the clear cut thing, but so far I haven't been able to get the SD card to accept that kind of data.

I have a SparkFun "Open Log" (http://www.sparkfun.com/products/9530), which does the job, but it is less robust than the data logger. For tht I use this sketch

Sketch for sparkfun openlog
int ledPin = 13; // LED connected to digital pin 13
int analogPin = 3; // potentiometer wiper (middle terminal) connected to analog pin 3
int digipin = 2;
// outside leads to ground and +5V
int val = 0; // variable to store the value read
int mp = 5.0;
int wavin = 0;

void setup()
{
pinMode(ledPin, OUTPUT);


Serial.begin(9600); //9600bps is default for OpenLog
//Serial.begin(57600); //Much faster serial, used for testing buffer overruns on OpenLog
//Serial.begin(115200); //Much faster serial, used for testing buffer overruns on OpenLog

delay(1000); //Wait a second for OpenLog to init
Serial.println("Feb 28b/freq");
//Serial.println("Run 10 OpenLog Tests FOR Paddy");
Serial.print ("millis =");
Serial.println (millis());
Serial.println ();
}

void loop()
{
int testAmt = 21;

//At 9600, testAmt of 4 takes about 1 minute, 10 takes about 3 minutes
//At 57600, testAmt of 10 takes about 1 minute, 40 takes about 5 minutes
//testAmt of 10 will push 111,000 characters/bytes. With header and footer strings, total is 111,052

for(int numofTests = 1 ; numofTests < testAmt ; numofTests++){
Serial.print("test # = ");
Serial.println(numofTests);

attachInterrupt(0, freqin, RISING);

//val = analogRead(analogPin); // read the input pin
//Serial.print((val*.0049)); // debug value
//Serial.println (" volts");
Serial.print("Freq. = ");
Serial.println(wavin);
wavin = 0;
Serial.print("millis = " );
Serial.println (millis());
Serial.println ();
delay(999);

}


if(digitalRead(ledPin) == 0)
digitalWrite(ledPin, HIGH);
else
digitalWrite(ledPin, LOW);

Serial.print("Time taken : ");
Serial.print(millis()/1000);
Serial.println("secs");

Serial.println("Done!");

while(1)

{
digitalWrite(ledPin, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(1000); // wait for a second
}
}

void freqin()
{
//if (state = HIGH)
wavin = wavin + 1;

}


Thank you
Paddy

POTOOLE
 
Posts: 13
Joined: Tue Mar 06, 2012 3:00 pm

Re: How can I use data logger shield to collect data?

Post by POTOOLE »

Ah, the more I try, the worse it gets.

There's gotta be a simple straight forward sketch for downloading/logging digital data by use of Adafruit's Data logger shield.

I guess I'm too dumb to figure it out.
A $20 item that I can't use.

potoole

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: How can I use data logger shield to collect data?

Post by adafruit_support_bill »

Does the OpenLog sketch capture the data you want?
If so, just add statements to write to the SD card instead of to the serial port. The "datalogger" example sketch from the SD library has all the code you need to initialize the card and open the file. Then for every "Serial.println()", you can add a "dataFile.println()' to log to the card.

POTOOLE
 
Posts: 13
Joined: Tue Mar 06, 2012 3:00 pm

Re: How can I use data logger shield to collect data?

Post by POTOOLE »

I'm having some success using the datalogger sketch, and gradually getting things to work.

Thanks
potoole

POTOOLE
 
Posts: 13
Joined: Tue Mar 06, 2012 3:00 pm

Re: How can I use data logger shield to collect data?

Post by POTOOLE »

I have been able to get what I want by using the datalogger sketch. After a few modifications things will work O.K. for me, but I am having problems with the RTC.

Thanks to all for the help.
potoole

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: How can I use data logger shield to collect data?

Post by adafruit_support_bill »

but I am having problems with the RTC
What problems are you having with the RTC?

POTOOLE
 
Posts: 13
Joined: Tue Mar 06, 2012 3:00 pm

Re: How can I use data logger shield to collect data?

Post by POTOOLE »

What problems are you having with the RTC?
I posted a new question for that problem. I posted:
Help please, getting RTC to work on Ada datalogger shield.
Under "General Project Help"

Thank you
POTOOLE

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”