A little (Lot) of help with the data logger please

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
User avatar
musher
 
Posts: 5
Joined: Fri Jan 14, 2011 11:17 am

A little (Lot) of help with the data logger please

Post by musher »

First off I know very little about electronics and Arduino and today was the first time I had picked up an iron in 20 years.

I have managed to solder the data logging shield (with out burning myself or starting a fire), install the Arduino IDE and upload the example sketches, all seems good so far.

Now what I want to do is have 2 buttons as inputs (one for 'machine up' and one for 'machine down') and log the time each was pressed, now I thought yeah thats not to hard - but well it is (for me anyway) if someone could explain or even point me in the right direction I would be most greatfull.

Ewan

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

Re: A little (Lot) of help with the data logger please

Post by adafruit_support_bill »

The Arduino Tutorials are a great place to start. They will walk you through the basics, including how to connect your pushbuttons. From there, it should be a short step to combine that with the logging examples to accomplish what you want.

User avatar
musher
 
Posts: 5
Joined: Fri Jan 14, 2011 11:17 am

Re: A little (Lot) of help with the data logger please

Post by musher »

Thanks I'm working my way through them, I have to say I'm looking up a wall and it's rather daunting, but I will give myself these sort of challenges.

Others at my work could do it in a few hours ( i take care of the website, trade accounts, editing the video blogs etc), but I want to see what is possible with no previous knowledge like many of our customers. All they have is the Internet and a need to learn - I'm thinking about blogging it, just to show what is possible.

Ewan

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

Re: A little (Lot) of help with the data logger please

Post by adafruit_support_bill »

Good luck, and feel free to post your progress, and/or ask any questions. :D

User avatar
musher
 
Posts: 5
Joined: Fri Jan 14, 2011 11:17 am

Re: A little (Lot) of help with the data logger please

Post by musher »

Right,

As I have previously said I want to use the data logger to log the time a button is pressed and now also light an led to show that its been pressed.

But im getting an error writing to the card, all I have done is copy and paste from the various examples out their into a sketch which I thought should work, I have wired green LED to pin 9 and the green button to pin six but I get 'error: file.create'

any help on why its not working would be great, even better if you could explain my stupidity ;)

anyhow here's the code:

Code: Select all

#include "SdFat.h"
#include <Wire.h>
#include "RTClib.h"

// A simple data logger for the Arduino analog pins
#define ECHO_TO_SERIAL   1 // echo data to serial port
#define WAIT_TO_START    0 // Wait for serial input in setup()

// the digital pins that connect to the LEDs
#define redLEDpin 8
#define greenLEDpin 9

// The analog pins that connect to the sensors
const int GreenButton = 6;               // dig 6
int buttonState = 0;

RTC_DS1307 RTC; // define the Real Time Clock object

// The objects to talk to the SD card
Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;

void error(char *str)
{
  Serial.print("error: ");
  Serial.println(str);
  while(1);
}

void setup(void)
{
  Serial.begin(9600);
  Serial.println();
  
#if WAIT_TO_START
  Serial.println("Type any character to start");
  while (!Serial.available());
#endif //WAIT_TO_START
 // initialize the SD card
  if (!card.init()) error("card.init");
  
  // initialize a FAT volume
  if (!volume.init(card)) error("volume.init");
  
  // open root directory
  if (!root.openRoot(volume)) error("openRoot");
  
  // create a new file
  char name[] = "TEST00.CSV";
  for (uint8_t i = 0; i < 100; i++) {
    name[6] = i/10 + '0';
    name[7] = i%10 + '0';
    if (file.open(root, name, O_CREAT | O_EXCL | O_WRITE)) break;
  }
  if (!file.isOpen()) error ("file.create");
  Serial.print("Logging to: ");
  Serial.println(name);

  // write header
  file.writeError = 0;
  
    
Wire.begin();  
  if (!RTC.begin()) {
    file.println("RTC failed");
#if ECHO_TO_SERIAL
    Serial.println("RTC failed");
#endif  //ECHO_TO_SERIAL
  }
  

  file.println("Rig,time,Up/Down");    
#if ECHO_TO_SERIAL
  Serial.println("Rig,time,Up/Down");
#if ECHO_TO_SERIAL// attempt to write out the header to the file
  if (file.writeError || !file.sync()) {
    error("write header");
  }
  
  pinMode(redLEDpin, OUTPUT);
  pinMode(greenLEDpin, OUTPUT);
  pinMode(GreenButton, INPUT);
 
   // If you want to set the aref to something other than 5v
  //analogReference(EXTERNAL);
}
void loop(void){
  // read the state of the pushbutton value:
  buttonState = digitalRead(GreenButton);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:    
    digitalWrite(greenLEDpin, HIGH);  
  } 
  else {
    // turn LED off:
    digitalWrite(greenLEDpin, LOW); 
  }
//{
  DateTime now;
  
  // clear print error
  file.writeError = 0;

  
//  digitalWrite(greenLEDpin, HIGH);

  // log milliseconds since starting
  uint32_t m = millis();
  file.print(m);           // milliseconds since start
  file.print(", ");    
//#if ECHO_TO_SERIAL
  Serial.print(m);         // milliseconds since start
  Serial.print(", ");  
#endif

  // fetch the time
  now = RTC.now();
  // log time
 // file.print(now.get()); // seconds since 2000
 // file.print(", ");
  file.print(now.year(), DEC);
  file.print("/");
  file.print(now.month(), DEC);
  file.print("/");
  file.print(now.day(), DEC);
  file.print(" ");
  file.print(now.hour(), DEC);
  file.print(":");
  file.print(now.minute(), DEC);
  file.print(":");
  file.print(now.second(), DEC);
//#if ECHO_TO_SERIAL
 // Serial.print(now.get()); // seconds since 2000
  Serial.print(", ");
  Serial.print(now.year(), DEC);
  Serial.print("/");
  Serial.print(now.month(), DEC);
  Serial.print("/");
  Serial.print(now.day(), DEC);
  Serial.print(" ");
  Serial.print(now.hour(), DEC);
  Serial.print(":");
  Serial.print(now.minute(), DEC);
  Serial.print(":");
  Serial.print(now.second(), DEC);
#endif //ECHO_TO_SERIAL


 /* if (file.writeError) error("write data");
  
  digitalWrite(redLEDpin, LOW);

  //don't sync too often - requires 2048 bytes of I/O to SD card
 // if ((millis() - syncTime) <  SYNC_INTERVAL) return;
 // syncTime = millis();
  
  // blink LED to show we are syncing data to the card & updating FAT!
  digitalWrite(greenLEDpin, HIGH);
  //if (!file.sync()) error("sync");
  digitalWrite(greenLEDpin, LOW); */
}

Thanks in advance


ewan

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

Re: A little (Lot) of help with the data logger please

Post by adafruit_support_bill »

Can you post the whole output of the Serial Monitor? And are there any files on the card?

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

Return to “Arduino Shields from Adafruit”