Poll
Question: Help... Data Files ...
data files - 1 (100%)
create new - 0 (0%)
Total Voters: 0

Pages: 1 ... 3 4 [5] 6   Go Down
Author Topic: FileLogger  (Read 9265 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

*Need Some Help* Hello, I am currently stuck on a problem with the filelogger code.  I am just testing things out and got the arduino to write the "Hello, this is my message. Just testing the FileLogger library.\r\n" message onto my SD card.  I want to start writing some numerical data to the card from a thermister and am having some problems.

here is my code:
Code:

#define sample 10
#include "FileLogger.h"
#define MEM_PW 8

byte buffer[sample];

void setup(void) {
  pinMode(MEM_PW, OUTPUT);
  digitalWrite(MEM_PW, HIGH);
  Serial.begin(9600);
  
}

void loop(void) {

  
  for(int i = 0; i < sample; i++){
  buffer[i] = i;
  Serial.println(buffer[i]);
  delay(1000);
  }
  
 FileLogger::append("data.log", buffer, sample-1);

}

For now I am trying to just write the numbers 0-9 onto the SD card and am having some problems.  I believe it has something to do with the variable type of the buffer array.  I can not change it though or else I get this warning message:

error: cannot convert 'int*' to 'byte*' for argument '2' to 'int FileLogger::append(const char*, byte*, long unsigned int)

I should note that something does write the SD card it just isn't the numbers 0-9 though.  The text file just has a bunch of garbage characters in it.

Any assistance would be greatly appreciated, thank!

« Last Edit: December 25, 2009, 08:51:30 pm by billtodd » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 616
Posts: 49444
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why is there a delay after putting each value in buffer?

The data being written to the card is the byte value you put into the array. If you want to see a 0, 1, 2, 3, etc. in the file, you need to store the ASCII value of the number in buffer, not the number itself.

Code:
buffer[i] = i + '0';

Why the -1 in the FileLogger::append call? If you want to write the numbers 0 thru 9, that's 10 values. You are only writing 9 values.
Logged

ND, USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 81
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Has anybody been able to get "FileLogger" working?

If so, in which file did you download the FileLogger program to?
I've downloaded(extracted) FileLogger.VO6 to Arduino-0014>hardware>libraries.  Then used the FileLogger demo in the Arduino-0014 operations window, but it won't even compile.  I get a message
:24:error:FileLogger.h:  NO SUCH FILE OR DIRECTORY IN 'void loop()':


I changed "FileLogger.VO6" to just "FileLogger" in hardware>libraries, as per
Quote
thais

Re: FileLogger
Reply #59 - 24.12.2009 at 01:16:31    ptool64ar try renaiming the directory to just FileLogger
but that made no difference. :-[

FileLogger Demo
Quote

 
//
// Title        : FileLogger library for Arduino, example code
// Author       : Eduardo García (egarcia@stream18.com)
// Date         : April 2009
// Id                  : $Id: FileLoggerDemo.pde 24 2009-04-23 22:45:13Z stream18 $
//
// DISCLAIMER:
// The author is in no way responsible for any problems or damage caused by
// using this code. Use at your own risk.
//
// LICENSE:
// This code is distributed under the GNU Public License
// which can be found at http://www.gnu.org/licenses/gpl.txt
//

#include "FileLogger.h"

// define the pin that powers up the SD card
#define MEM_PW 8

// variable used when reading from serial
byte inSerByte = 0;

#define MESSAGE "Hello, this is my message. Just testing the FileLogger library.\r\n"
unsigned long length = sizeof(MESSAGE)-1;
byte buffer[] = MESSAGE;

void setup(void) {
  pinMode(MEM_PW, OUTPUT);
  digitalWrite(MEM_PW, HIGH);
  Serial.begin(9600);
}

void loop(void) {
  char command = '0';
  unsigned long t1, t2;

  // Arduino expects one of a series of one-byte commands
  if (Serial.available() > 0) {
    int result;
    inSerByte = Serial.read();
    switch (inSerByte) {
      case 'W':
        result = FileLogger::append("data.log", buffer, length);
        Serial.print(" Result: ");
        if( result == 0) {
          Serial.println("OK");
        } else if( result == 1) {
          Serial.println("Fail initializing");
        } else if( result == 2) {
          Serial.println("Fail appending");
        }
      break;
    case 'T':
        for(int i=0; i<10; i++) {
            result = FileLogger::append("data.log", buffer, length);
              Serial.print(" Result: ");
              if( result == 0) {
                Serial.println("OK");
              } else if( result == 1) {
                Serial.println("Fail initializing");
              } else if( result == 2) {
                Serial.println("Fail appending");
              }
        }
          Serial.print("Done");
      break;
    }
  }
}


 
« Last Edit: December 26, 2009, 03:54:51 pm by ptool64ar » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The delay was just for testing out something else, I just wanted to see what was in the buffer array positions slower *it should be noted that the delay needs to be taken out, or nothing will get written to the SD card*.  I tried using your suggestion PaulS

Code:
buffer[i] = i + '0';

but I still get weird characters and not numbers in my text file.  Is there an easy way to convert integers to byte arrays?  I came up with this as a workaround but I don't think it is how most other people would do it*I know there are more parenthesis then needed, they just help me keep track of stuff*

Code:
test = 123 / 100; //=1
         Serial.println(test);
test1 = (123 - (100*test))/10; // = (123-100)/10 =2
         Serial.println(test1);
test2 = (123 - ((100*test)+(10*test1)))/1;// (123- ((100)+(20)))/1 = 3
         Serial.println(test2);

So if i have a number that is less than 1000 (in this example 123) I can break it up into it's individual components 1,2,3 and then assign each to a byte representation e.g. 1=49, 2=50, 3=51 then put these into my byte array.  This would yield the correct answer of 123 in my text file on the SD card.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ptool64ar try upgrading to Arduino 0017.  The problem may be that you are using an older version of the Arduino software.  Arduino 0017 even comes with example filelogger code in File>Examples>SDcard
Logged

ND, USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 81
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Re: FileLogger
Reply #64 - Today at 22:01:54    ptool64ar try upgrading to Arduino 0017.  The problem may be that you are using an older version of the Arduino software.  Arduino 0017 even comes with example filelogger code in File>Examples>SDcard  
Back to top  

I'm in the process of adding ar-17, what do I do with ar-14 when the downloading is complete?  :-/
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just run the executable arduino.exe from the arduino-0017 folder.  When the program asks you to save or when you want to retrieve a file just browse to the folder where you normally keep your sketches.
Logged

ND, USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 81
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Posted by: billtodd Posted on: Yesterday at 23:34:55
Just run the executable arduino.exe from the arduino-0017 folder.  When the program asks you to save or when you want to retrieve a file just browse to the folder where you normally keep your sketches.  

I got the fileloggerdemo working.  I changed:
Code:
result = FileLogger::append("data.log", buffer, length);
to:
Code:
[code] result = FileLogger::append("data.txt", buffer, length);
[/code]


I see that data is added at the end of the data file, not at the beginning as uFat does.

As edguarcia states:"you will give the name of the file when you call the function append(). "

Where does one "call the function append()?

When a person opens a file on a cd card, how many 'characters' should be added to the file?

Quote
edugarcia

Posts: 15
Oviedo, Asturias
Gender:
  Re: FileLogger
Reply #3 - 26.04.2009 at 22:32:15    Hi prakat,

yes, the SD card need to be formated with FAT16.
You need to create a file in the root folder, the name is not important as you will give the name of the file when you call the function append(). In fact you can log to more than one file specifying differente file names. The only restriction for the files is that the size must not be zero (at least one character must be written before using the liberay).
 

PO'T
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

AAARRRGGGHHH!!


Code:
buffer[i] = i + '0';  

Yeah, your suggestion worked PaulS.  I had to format the SDcard.  To do larger numbers then 9 though I whipped this up:

Code:
int number = 1998;
  byte SDArray[4];
  
  int test;
  int test1;
  int test2;
  int test3;
  
  void setup(void) {
  pinMode(MEM_PW, OUTPUT);
  digitalWrite(MEM_PW, HIGH);
  Serial.begin(9600);
  
  
 }
  
  void loop(void){
    
    
  test = number / 1000; //=1
  //Serial.println(test);
  test1 = (number - (1000*test))/100; //(1123 - (1000*1)) / 100 = (1123 - 1000)/10 = 123/100 = 1
  //Serial.println(test1);
  test2 = (number - ((1000*test)+(100*test1)))/10; // = (1123 - (1000+100)) / 10 = 2
  //Serial.println(test2);
  test3 = (number - ((1000*test)+(100*test1)+(10*test2)))/1;// (1123-(1000+100+20))/1 = 3
  //Serial.println(test3);
  
  
  
  SDArray[0] = test  + '0';
  SDArray[1] = test1  + '0';
  SDArray[2] = test2  + '0';
  SDArray[3] = test3  + '0';
  

  
  FileLogger::append("data.log", SDArray, 4);

It breakes down numbers smaller then 10,000 into their individual components e.x. 1998 1,9,9,8 so each can fit into the byte allocated in each array element.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For anyone who wants to write numbers 0-9999 onto their SDcards for sensor logging I wrote this piece of code:

Code:
//billtodd
//DEC 27th 09'
#include "FileLogger.h"
#define MEM_PW 8

byte buffer[4];

  int test;
  int test1;
  int test2;
  int test3;
  
  void converter(int number, byte SDArray[6]){
    
  test = number / 1000; //=1  example number is 1123
  //Serial.println(test);
  test1 = (number - (1000*test))/100; //(1123 - (1000*1)) / 100 = (1123 - 1000)/10 = 123/100 = 1
  //Serial.println(test1);
  test2 = (number - ((1000*test)+(100*test1)))/10; // = (1123 - (1000+100)) / 10 = 2
  //Serial.println(test2);
  test3 = (number - ((1000*test)+(100*test1)+(10*test2)))/1;// (1123-(1000+100+20))/1 = 3
  //Serial.println(test3);
  
  SDArray[0] = test  + '0'; //assigns the first digit from the int "number" to array element 0
  SDArray[1] = test1  + '0';//assigns the second digit from the int "number" to array element 1
  SDArray[2] = test2  + '0';
  SDArray[3] = test3  + '0';
  SDArray[4] = 13; //the 13 and 10 are carriage returns so the numbers form a list
  SDArray[5] = 10;
    
  }
  
  void setup(void) {
  pinMode(MEM_PW, OUTPUT);
  digitalWrite(MEM_PW, HIGH);
  Serial.begin(9600);
    
 }
  
  void loop(void){
    
  for(int i=0; i < 60; i++){  //this writes the numbers 0-60 over and over again onto the SDcard
  byte SDArray[6];
  converter(i, SDArray);  //calls the function converter up above
  FileLogger::append("data.log", SDArray, 6);
  }
    
  
}





Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 616
Posts: 49444
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Look at the sprintf function. It will convert all kinds of numbers, of various sizes, to strings, adding the appropriate null terminator.
Logged

ND, USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 81
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can get filelogger to work, but I had to change:
Code:
result = FileLogger::append("data.log", buffer, length);


to:
Code:
result = FileLogger::append("data.txt", buffer, length);

However, it only works with data.txt
I tried saving a file on the sd card labeled data2.txt, then went into fileloggerdemo changed:
Code:
result = FileLogger::append("data.txt", buffer, length);
to:
Code:
result = FileLogger::append("data2.txt", buffer, length);

Resuts were:"failure to initialize", "failure to append"
I tried several times, then went back to "data.txt" then things worked ok.
(BTW, yes, I added data to the cd file 'data2.txt' before applying it to fileloggerdemo)

Where does one "call the function append()?

When a person opens a file on a cd card, how many 'characters' should be added to the file?


Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 616
Posts: 49444
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Where does one "call the function append()?

Right here:

Code:
result = FileLogger::[glow]append[/glow]("data2.txt", buffer, length);

Quote
When a person opens a file on a cd card, how many 'characters' should be added to the file?

When you open the file, no characters should be appended. When you use the append function to append to a file, the 3rd argument is the number of characters in buffer to copy into the file.


Logged

ND, USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 81
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm getting ascii results on my sd card.  I've tried several different things to get actual numbers to appear on the card, but only with partial success.  Too many things to remember.
I've temporarily stopped at the following code, which gives me ascii code on my card.

Code:
#include "FileLogger.h"
  int x;
  byte seqn;
  int length = 5;
  int tme = 0;

void setup() {
  Serial.begin(9600);
}

void loop() {
 while (tme < 7000){
 seqn = 80;
 while (seqn <=85){
  byte buffer[5] = {seqn,32,65,13,10};
   byte result;
     x = buffer[0];
     int z = buffer[1];
   result = FileLogger::append("data.txt", buffer, length);
   Serial.print(" A: ");
        if( result == 0) {
          Serial.println("OK");
        } else if( result == 1) {
          Serial.println("Fail initializing");
        } else if( result == 2) {
          Serial.println("Fail appending");
        }
        
            Serial.print(x, DEC);     // 3
            Serial.print("\t");              // prints a tab
            Serial.print(z, DEC);     // 3
            Serial.println();              // prints a tab

    delay(1000);
    seqn = (seqn +1);
    
 }
   tme = millis();
  Serial.println(tme);// 0
 }
}


Looking at this part of the code:
   /glow]
seqn is a variable, which are numbers 80-85, I chose those #'s, since they show up as ascii 'P - U'
32 =  space,  65 = A, 13= carriage return, 10 = line feed

The extra while loop, controlled by millis(), is just to be sure the thing will stop after approx 7 seconds.

So, on my cd card I get the following result, in a notepad text file:
[glow]
Q A
R A
S A
T A
U A[/glow]

Q - U are the result of a changing variable (seqn), A is the constant # 65

What I want to do is feed numerical values into variables, then save those values on my cd card as numbers, rather than ascii code.
  • 1) time, from 0 seconds to several minutes
2) electronic pulses from a speed sensor, from 0 to about 3000 pulses/second
[/list]
I suppose I can copy from the cd's file to excel, then use excel to change to numerical values.  My intent is to store data on the card, then enter the data to a spread sheet.

I'm kinda at a quandary at this point.
Can someone help figure out how to get actual numbers on the card?

Paddy
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 616
Posts: 49444
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you store numbers on the card, and those numbers are larger than one byte, as in an int, you will need to use bitshifting to get the most significant byte and least significant byte from the int, and then write the bytes out in the correct order (least, most or most, least).

If the number is larger than 2 bytes, you'll need to split the number into the appropriate number of bytes, and write them in the correct order.

The proper order depends on the software that is going to read the card later.

If that software is excel, you will need to construct a completely properly formatted binary file for excel to read. Good luck with that task.

If the software is excel, and the file is to be a csv (comma separated values file), the file is all text (all ascii values).

I think that what you need to do is to think about whether you really want to write the numbers AS NUMBERS to the file.
Logged

Pages: 1 ... 3 4 [5] 6   Go Up
Jump to: