Libelium microSD module and duemilanove hassle...

Hi,

Found this post while trying to figure out how to make the Libellium microSD Shield/SDuFAT combo work on my Duemilanove as well. My problem seems to be with the log file on the SD card filling up before all the characters have been used. Will try mowcius's tip using "ETX" and hope that it works.

Since SDuFAT only writes strings, I used the floatToString library from Tim Hirzel (Arduino Playground - FloatToString) to convert my temp sensor (LM35CZ) readings into strings which were then saved on my 2GB MicroSD card w/ the Libellium shield.

Here's the code: (if anyone can offer some suggestions regarding my log file problem http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1261141357/7, please let me know)

#include "SDuFAT.h" // needed to write data to SD card
#include "floatToString.h" // needed to convert float values to strings used by SDuFat

// define the pin that powers up the SD card
#define MEM_PW 8
#define BANDGAPREF 14 // indicator that we want to measure the bandgap
// help string to be sent to the serial port
#define HELP "H help\nL file info\nD delete\nP append string\nW init file and write\nR dump to serial\nA append text\n"

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

// initialize variables for sensors
int SensorPin01 = 0;

int itNum = 1;
void setup(void)
{
  // on my MicroSD Module the power comes from a digital pin
  // I activate it at all times
  pinMode(MEM_PW, OUTPUT);
  digitalWrite(MEM_PW, HIGH);
  
  // configure the serial port to command the card and read data
  Serial.begin(19200);
  
}

void loop(void)
{
  // get voltage reading from the internal 1.1V reference analogReference(INTERNAL);
  analogReference(INTERNAL);
  
  int RefReading = analogRead(BANDGAPREF); // first reading
  RefReading = analogRead(BANDGAPREF); // second reading
  RefReading = analogRead(BANDGAPREF); // third reading
  //Serial.println(RefReading);
  
   float SupplyCorrection = (1.05 * 1024) / RefReading;
   int Sensor01 = analogRead(SensorPin01);
   float Voltage01 = 100 * (Sensor01 * SupplyCorrection) / 1024;
   //Serial.println(Voltage01);
  
  
  // Arduino expects one of a series of one-byte commands
  // you can get some help by sending an 'H' over the serial port
  if (Serial.available() > 0) {
    int result = 0;
    char buffer[25];
    SD.println("temp.txt",""); // adds line break each time serial port query is activated

    inSerByte = Serial.read();
    switch (inSerByte) {
    case 'H':
      Serial.println(HELP);
      result = 3; // special output for help message
      break;
    case 'L':
      result = SD.ls("temp.txt");
      break;
    case 'R':
      result = SD.cat("temp.txt");
      break;
    case 'W':
      result = SD.write("temp.txt");
      break;
    case 'A':
      result = SD.append("temp.txt");
      break;
    case 'P':
      //result = SD.println("temp.txt",floatToString(buffer, testNum, 5));
      result = SD.println("temp.txt",floatToString(buffer, Voltage01,5));
      break;
    case 'D':
      result = SD.del("temp.txt");
      break;
    default:
      result = 2; // value for unknown operation
      break;
    }
    
    // print a status message for the last issued command
    // for help (result == 3) won't print anything
    if (result == 1) SD.printEvent(ERROR, "temp.txt");
    else if (result == 2) SD.printEvent(WARNING, "unknown command");
    else if (result == 0) SD.printEvent(SUCCESS, "temp.txt");
  }
  //delay(100);
  char buffer[25];
  SD.print("temp.txt",floatToString(buffer,itNum,0)); SD.print("temp.txt"," "); SD.println("temp.txt",floatToString(buffer, Voltage01,5));
  itNum = itNum++;
}