0

Datalogger + Thermocouple Mux
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Datalogger + Thermocouple Mux

by wilheldp on Tue May 07, 2013 6:18 pm

I am trying to get the Adafruit datalogger shield to work with the Ocean Controls KTA-259V3 8-channel thermocouple mux (http://oceancontrols.com.au/KTA-259V3.html). As far as I can tell, there are no pin conflicts between the two shields. I have fully tested the thermocouple shield, and it is working fine. I am now trying to incorporate the datalogger.

When I try to run the CardInfo sketch with both the datalogger and TCMux shields installed, the Arduino cannot access the SD card. When I remove the Mux shield, it works fine. It doesn't matter which order the shields are installed (Arduino > Mux > DL or Arduino > DL > Mux), I get the same error.

Any thoughts on why these shields may not be compatible, and how to get around it?
wilheldp
 
Posts: 22
Joined: Tue May 07, 2013 6:14 pm

Re: Datalogger + Thermocouple Mux

by adafruit_support_mike on Tue May 07, 2013 10:58 pm

It does look like there's a pin conflict, but you can be forgiven for not seeing it. I had to dig through the SD/utility headers and then check the defaults for the Arduino SPI library.

By default, an UNO uses pins 11, 12, and 13 for SPI signals MOSI, MISO, and SCK respectively. According to the SdCard.cpp file you can call card.init() with any four pins to define the ones you want to use for software SPI. There's a comment that says it needs testing, but at least you have an option for a low-impact solution.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.

adafruit_support_mike
 
Posts: 61796
Joined: Thu Feb 11, 2010 2:51 pm

Re: Datalogger + Thermocouple Mux

by wilheldp on Wed May 08, 2013 8:58 am

What would that "low impact solution" be? Forgive me...I'm relatively new to the Arduino programming community.
wilheldp
 
Posts: 22
Joined: Tue May 07, 2013 6:14 pm

Re: Datalogger + Thermocouple Mux

by adafruit_support_rick on Wed May 08, 2013 10:28 am

I had a look at the Ocean Controls sample sketch. The MUX uses pin 9 as chip select. In cardinfo, you're going to have to set pin 9 to output and drive it high to deselect the MUX. If pin 9 is low, then the MUX is going to be interfering with the SD communications.

See if this works -

Add these two lines to CardInfo setup(), right before card initialization:
Code: Select all | TOGGLE FULL SIZE
  //deselect MUX
  pinmode(TC_MUX_CS, OUTPUT);
  digitalWrite(TC_MUX_CS, HIGH);

  Serial.print("\nInitializing SD card...");
. . . etc . . .


Define TC_MUX_CS somewhere before setup():
Code: Select all | TOGGLE FULL SIZE
//define Ocean Controls Thermocouple MUX chip select pin
#define TC_MUX_CS 9

void setup()
. . . etc . . .

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: Datalogger + Thermocouple Mux

by wilheldp on Wed May 08, 2013 11:06 am

The Mux uses 9, the Datalogger uses 10, and the Arduino uses 11, 12, and 13 for SPI. I still don't see the conflicting pin.

If I deselect the Mux to run the SD initialization, am I going to be able to re-enable the Mux after initialization in my real sketch? Will I need to disable the Mux every time I need to write to the SD card?
wilheldp
 
Posts: 22
Joined: Tue May 07, 2013 6:14 pm

Re: Datalogger + Thermocouple Mux

by adafruit_support_rick on Wed May 08, 2013 11:44 am

There is no pin conflict. It's just a programming issue.

The Ocean Controls sketch turns the chip select on and off as necessary. The SD library will do the same. The problem is that CardInfo doesn't know anything about the MUX, so you have to add that.

I presume you will be integrating the SD stuff into the MUX sketch? You'll see that asserting pin 9 LOW enables reading the MUX and and disables the actual TC readings (and vice-versa). So, you'll have to be manipulating the MUX CS anyway.

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: Datalogger + Thermocouple Mux

by wilheldp on Wed May 08, 2013 12:24 pm

I have tried reading the SD card in the Mux sketch already, and it cannot initialize the card in that sketch either.

I'm not in front of the computer I'm using to program right now, so I can't see exactly what commands I'm using.
wilheldp
 
Posts: 22
Joined: Tue May 07, 2013 6:14 pm

Re: Datalogger + Thermocouple Mux

by adafruit_support_rick on Wed May 08, 2013 1:47 pm

Let's just check the theory first. The MUX sketch is kind of non-standard, so leave that out of it until we can establish that the two shields can live together in harmony.

Make the changes to CardInfo which I suggested. See if the modified CardInfo will work while the MUX shield is connected.

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: Datalogger + Thermocouple Mux

by wilheldp on Wed May 08, 2013 9:21 pm

Theory tested and confirmed. I have tried to incorporate that into my main sketch by setting the MuxCS High prior to the SD initialization in the Setup loop. That seems to break the Mux, though. All of my temps are reading the same value...even on channels that are not wired to anything. I re-tested the TCMux_V3 sketch, and it works fine...so the Mux shield isn't messed up.

I have tried setting the MuxCS Low again after the SD card and RTC are initialized, and setting the DL shield CS pin High and Low at the end of the Setup loop. Nothing seems to fix it.

In other news, my main sketch is setting up the .csv file on the SD card, and inserting the column headers, but no temperature readings are inserted (the file and headers are created in the Setup loop).
wilheldp
 
Posts: 22
Joined: Tue May 07, 2013 6:14 pm

Re: Datalogger + Thermocouple Mux

by adafruit_support_rick on Thu May 09, 2013 9:26 am

If it were me, I'd break down the mux code into some sensible functions to make it a little easier to work with.

Anyway, to make this work, you've got to understand what PINCS (pin 9) does. When it's HIGH, the selected thermocouple is sampling. When it's LOW, sampling stops and data output is enabled.

Meanwhile, the SD card will only work when PINCS is HIGH.

The MUX code, as is, leaves PINCS LOW all the time, and only takes it HIGH for 100msec in order to do a single conversion. So you can't use it as-is. You want to rearrange it so that you have this exact sequence in your loop():

Code: Select all | TOGGLE FULL SIZE
      digitalWrite(PINCS, LOW); //Take SPI bus; stop current conversion
      delay(1);
      <read selected thermocouple>
      <select next thermocouple>
      delay(5);
      digitalWrite(PINCS, HIGH); //Release SPI bus; Begin conversion
 


In setup(), use this sequence to start the first conversion:
Code: Select all | TOGGLE FULL SIZE
      digitalWrite(PINCS, LOW); //Take SPI bus
      select first thermocouple
      delay(5);
      digitalWrite(PINCS, HIGH); //Release SPI bus; Begin conversion


You'll see that both operations only take PINCS low long enough to do something with the MUX, then they return it to HIGH. That will make it play nicely with other SPI devices, like the datalogger.

Now, all you need to do is make sure your loop waits long enough between MUX operations to allow the conversion to complete. The original sketch simply waited 100ms, which is just a waste of time. Instead, adapt the same timing technique that the sketch used to schedule your MUX operation to happen every 100ms (or however long you want)
Code: Select all | TOGGLE FULL SIZE
  if (millis() > (time + 100))  //every 100 mSec
  {
    time = millis();
    <read temperature, select next thermocouple>
  }
  <do whatever else there is to do - read a book, tidy up the SD, polish the flip-flops, etc.>

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: Datalogger + Thermocouple Mux

by wilheldp on Sat May 11, 2013 9:57 am

Man, I'm really confused. You're right that this Mux sketch is bizarre. I'm on board with moving the bulk of the thermocouple data manipulation to a sub-routine, but I really don't know where to cut it the way it's written. The PINCS manipulation happens between the switch that sets the address pins and the actual interpretation of the data into useable temperatures and fault codes. Would I put the...

Code: Select all | TOGGLE FULL SIZE
      digitalWrite(PINCS, LOW); //Take SPI bus; stop current conversion
      delay(1);
      <read selected thermocouple>
      <select next thermocouple>
      delay(5);
      digitalWrite(PINCS, HIGH); //Release SPI bus; Begin conversion


code after the switch, then take everything from Temp[j] = 0; to the end of the failmodes and put that in the subroutine?
wilheldp
 
Posts: 22
Joined: Tue May 07, 2013 6:14 pm

Re: Datalogger + Thermocouple Mux

by adafruit_support_rick on Sat May 11, 2013 5:59 pm

Yeah, it's confusing all right.

See if this make more sense. I broke out the "time" section of loop() into 3 functions: selectThermocouple(), readThermocouple(), and convertTemperature(). The functions take care of doing the right thing with PINCS, so you ought to be able to simply forget about it now.

That makes it a little easier to see what the high-level conversion logic looks like. For that, I set a conversion timeout that I check against millis():

Code: Select all | TOGGLE FULL SIZE
    if (millis() > (conversionTime + CONVERSION_TIME))  //every CONVERSION_TIME milliseconds
    {
      conversionTime = millis();    //reset conversion time-out
 
      readThermocouple(channel);    //stop conversion and read the current thermocouple
     
      channel = (channel + 1) % 8;  //get the next channel number
     
      if (channel = 0)              //if we finished all 8 conversions,
        intervalTime = millis();    // reset the conversion interval time-out.
     
      selectThermocouple(channel);  //select the next thermocouple and begin conversion
     
    } //end CONVERSION_TIME


So, it waits 100ms for a conversion to happen, reads the data, advances to the next TC and starts the next conversion.
The first conversion is started in setup(), to get things rolling.

I also added a conversion interval, because the original code effectively does that. Each conversion is 100ms, and there are 8 TCs, so it takes 800ms to go through the whole set. The original code started the full cycle every 1000ms, so there would have been an interval of 200ms between the end of one complete cycle and the start of the next.

The full sketch is pasted below. It compiles OK, but I didn't run it. So I can't say for sure that it works. But it ought to be close.

The code is still plenty ugly - I just did a cut & paste to make the three functions. But it ought to be enough to get you back on track.

Code: Select all | TOGGLE FULL SIZE
// TCMux shield demo by Ocean Controls
// Sends the data to a serial terminal
// Type @NS1<cr> (don't type <cr> it's the carriage return character, just hit enter) to set the number of sensor to 1
// Type @NS8<cr> to set the number of sensors to 8
// Type @UD1<cr> to set the update delay to 1 second
// Type @SV<cr> to save the number of sensors and update delay variables to eeprom



#include <string.h> //Use the string Library
#include <ctype.h>
#include <EEPROM.h>

//#define SHOWMEYOURBITS // Display the raw 32bit binary data from the MAX31855

#define PINEN 7 //Mux Enable pin
#define PINA0 4 //Mux Address 0 pin
#define PINA1 5 //Mux Address 1 pin
#define PINA2 6 //Mux Address 2 pin
#define PINSO 12 //TCAmp Slave Out pin (MISO)
#define PINSC 13 //TCAmp Serial Clock (SCK)
#define PINCS 9  //TCAmp Chip Select Change this to match the position of the Chip Select Link

int Temp[8], SensorFail[8];
float floatTemp, floatInternalTemp;
char failMode[8];
int internalTemp, intTempFrac;
unsigned int Mask;
//char data[16];
char i, channel, NumSensors =1, UpdateDelay;
char Rxchar, Rxenable, Rxptr, Cmdcomplete, R;
char Rxbuf[32];
char adrbuf[3], cmdbuf[3], valbuf[12];
int val = 0, Param;     
unsigned long conversionTime, intervalTime;

void selectThermocouple(int channel)
{
    digitalWrite(PINCS, LOW); //Take SPI bus

    switch (channel) //select channel
    {
      case 0:
        digitalWrite(PINA0, LOW);
        digitalWrite(PINA1, LOW);
        digitalWrite(PINA2, LOW);
      break;
      case 1:
        digitalWrite(PINA0, HIGH);
        digitalWrite(PINA1, LOW);
        digitalWrite(PINA2, LOW);
      break;
      case 2:
        digitalWrite(PINA0, LOW);
        digitalWrite(PINA1, HIGH);
        digitalWrite(PINA2, LOW);
      break;
      case 3:
        digitalWrite(PINA0, HIGH);
        digitalWrite(PINA1, HIGH);
        digitalWrite(PINA2, LOW);
      break;
      case 4:
        digitalWrite(PINA0, LOW);
        digitalWrite(PINA1, LOW);
        digitalWrite(PINA2, HIGH);
      break;
      case 5:
        digitalWrite(PINA0, HIGH);
        digitalWrite(PINA1, LOW);
        digitalWrite(PINA2, HIGH);
      break;
      case 6:
        digitalWrite(PINA0, LOW);
        digitalWrite(PINA1, HIGH);
        digitalWrite(PINA2, HIGH);
      break;
      case 7:
        digitalWrite(PINA0, HIGH);
        digitalWrite(PINA1, HIGH);
        digitalWrite(PINA2, HIGH);
      break;
      default:
        Serial.print("invalid thermocouple channel: "); Serial.println(channel);
        break;
    }
   
    delay(5);                  //allow for leisurely digestion
    digitalWrite(PINCS, HIGH); //Release SPI bus; Begin conversion
}

float convertTemperature(int channel)
{
      Serial.print("#");
      Serial.print(channel+1,DEC);
      Serial.print(": ");
      if (SensorFail[channel] == 1)
      {
        Serial.print("FAIL");
        if ((failMode[channel] & 0b0100) == 0b0100)
        {
          Serial.print(" SHORT TO VCC");
        }
        if ((failMode[channel] & 0b0010) == 0b0010)
        {
          Serial.print(" SHORT TO GND");
        }
        if ((failMode[channel] & 0b0001) == 0b0001)
        {
          Serial.print(" OPEN CIRCUIT");
        }
      }
      else
      {
        floatTemp = (float)Temp[channel] * 0.25;
        Serial.print(floatTemp,2);
        //This bit doesn't work for neg temps
        /*Serial.print(Temp[channel]>>2,DEC);
        Serial.print(".");
        if ((Temp[channel] & 0b11) == 0b00)
        {
          Serial.print("00");
        }
        if ((Temp[channel] & 0b11) == 0b01)
        {
          Serial.print("25");
        }
        if ((Temp[channel] & 0b11) == 0b10)
        {
          Serial.print("50");
        }
        if ((Temp[channel] & 0b11) == 0b11)
        {
          Serial.print("75");
        }
        */
        Serial.print(" degC");
      //}
        //delay(1000);
    }//end reading sensors
    //Serial.println("");
    Serial.print(" Int: ");
    floatInternalTemp = (float)internalTemp * 0.0625;
    Serial.print(floatInternalTemp,4);
    //This doesn't work for negative values
    /*
    Serial.print(internalTemp>>4);
    Serial.print(".");
    intTempFrac = (internalTemp & 0x0F)*625;
    Serial.print(intTempFrac/1000);
    intTempFrac = intTempFrac%1000;
    Serial.print(intTempFrac/100);
    intTempFrac = intTempFrac%100;
    Serial.print(intTempFrac/10);
    intTempFrac = intTempFrac%10;
    Serial.print(intTempFrac/1);
    */
    Serial.print(" degC");
    Serial.println("");

  return floatTemp;
}

float readThermocouple(int channel)
{
    Temp[channel] = 0;
    failMode[channel] = 0;
    SensorFail[channel] = 0;
    internalTemp = 0;
   
    digitalWrite(PINCS, LOW); //Take SPI bus, stop conversion
   
    for (i=31;i>=0;i--)
    {
        digitalWrite(PINSC, HIGH);
        delay(1);
       
         //print out bits
       #ifdef SHOWMEYOURBITS
       if (digitalRead(PINSO)==1)
        {
          Serial.print("1");
        }
        else
        {
          Serial.print("0");
        }
        #endif
       
      if ((i<=31) && (i>=18))
      {
        // these 14 bits are the thermocouple temperature data
        // bit 31 sign
        // bit 30 MSB = 2^10
        // bit 18 LSB = 2^-2 (0.25 degC)
       
        Mask = 1<<(i-18);
        if (digitalRead(PINSO)==1)
        {
          if (i == 31)
          {
            Temp[channel] += (0b11<<14);//pad the temp with the bit 31 value so we can read negative values correctly
          }
          Temp[channel] += Mask;
          //Serial.print("1");
        }
        else
        {
         // Serial.print("0");
        }
      }
      //bit 17 is reserved
      //bit 16 is sensor fault
      if (i==16)
      {
        SensorFail[channel] = digitalRead(PINSO);
      }
     
      if ((i<=15) && (i>=4))
      {
        //these 12 bits are the internal temp of the chip
        //bit 15 sign
        //bit 14 MSB = 2^6
        //bit 4 LSB = 2^-4 (0.0625 degC)
        Mask = 1<<(i-4);
        if (digitalRead(PINSO)==1)
        {
          if (i == 15)
          {
            internalTemp += (0b1111<<12);//pad the temp with the bit 31 value so we can read negative values correctly
          }
         
          internalTemp += Mask;//should probably pad the temp with the bit 15 value so we can read negative values correctly
          //Serial.print("1");
        }
        else
        {
         // Serial.print("0");
        }
       
      }
      //bit 3 is reserved
      if (i==2)
      {
        failMode[channel] += digitalRead(PINSO)<<2;//bit 2 is set if shorted to VCC
      }
      if (i==1)
      {
        failMode[channel] += digitalRead(PINSO)<<1;//bit 1 is set if shorted to GND
      }
      if (i==0)
      {
        failMode[channel] += digitalRead(PINSO)<<0;//bit 0 is set if open circuit
      }
     
     
      digitalWrite(PINSC, LOW);
      delay(1);
      //delay(1);
    }
   
    digitalWrite(PINCS, HIGH); //Release SPI bus
   
    return convertTemperature(channel);
}



#define CONVERSION_TIME      100            /* number of milliseconds per conversion */
#define CONVERSION_PERIOD   1000            /* start a new set of 8 conversions once every second */
#define CONVERSION_INTERVAL (CONVERSION_PERIOD - (CONVERSION_TIME * 8)) /*interval between the end of a conversion cycle and the start of the next */

void setup()   
{     
  Serial.begin(9600); 
  Serial.println("TCMUXV3");
  if (EEPROM.read(511)==1)
  {
    NumSensors = EEPROM.read(0);
    UpdateDelay = EEPROM.read(1);
  }
  pinMode(PINEN, OUTPUT);     
  pinMode(PINA0, OUTPUT);   
  pinMode(PINA1, OUTPUT);   
  pinMode(PINA2, OUTPUT);   
  pinMode(PINSO, INPUT);   
  pinMode(PINCS, OUTPUT);   
  pinMode(PINSC, OUTPUT);   
 
  digitalWrite(PINEN, HIGH);   // enable on
  digitalWrite(PINA0, LOW); // low, low, low = channel 1
  digitalWrite(PINA1, LOW);
  digitalWrite(PINA2, LOW);
  digitalWrite(PINSC, LOW); //put clock in low
 
  channel = 0;
  selectThermocouple(channel);            //start the first conversion
  conversionTime = millis();              //timestamp start of first conversion
  intervalTime = conversionTime - CONVERSION_INTERVAL;  //back-date the start of the first conversion interval
}

void loop()                     
{
  if (millis() > (intervalTime + CONVERSION_INTERVAL))  //start a new set of 8 conversions every CONVERSION_INTERVAL milliseconds
  {
    if (millis() > (conversionTime + CONVERSION_TIME))  //every CONVERSION_TIME milliseconds
    {
      conversionTime = millis();    //reset conversion time-out
 
      readThermocouple(channel);    //stop conversion and read the current thermocouple
     
      channel = (channel + 1) % 8;  //get the next channel number
     
      if (channel = 0)              //if we finished all 8 conversions,
        intervalTime = millis();    // reset the conversion interval time-out.
     
      selectThermocouple(channel);  //select the next thermocouple and begin conversion
     
    } //end CONVERSION_TIME
  } //end CONVERSION _INTERVAL
 
 
  if (Serial.available() > 0)    // Is a character waiting in the buffer?
  {
    Rxchar = Serial.read();      // Get the waiting character

    if (Rxchar == '@')      // Can start recording after @ symbol
    {
      if (Cmdcomplete != 1)
      {
        Rxenable = 1;
        Rxptr = 1;
      }//end cmdcomplete
    }//end rxchar
    if (Rxenable == 1)           // its enabled so record the characters
    {
      if ((Rxchar != 32) && (Rxchar != '@')) //dont save the spaces or @ symbol
      {
        Rxbuf[Rxptr] = Rxchar;
        //Serial.println(Rxchar);
        Rxptr++;
        if (Rxptr > 13)
        {
          Rxenable = 0;
        }//end rxptr
      }//end rxchar
      if (Rxchar == 13)
      {
        Rxenable = 0;
        Cmdcomplete = 1;
      }//end rxchar
    }//end rxenable

  }// end serial available


   
  if (Cmdcomplete == 1)
  {
    Cmdcomplete = 0;
     cmdbuf[0] = toupper(Rxbuf[1]); //copy and convert to upper case
     cmdbuf[1] = toupper(Rxbuf[2]); //copy and convert to upper case
     cmdbuf[2] = 0; //null terminate        Command = Chr(rxbuf(3)) + Chr(rxbuf(4))
     //   Command = Ucase(command)
  //Serial.println(cmdbuf);
     valbuf[0] = Rxbuf[3]; //        Mystr = Chr(rxbuf(5))
        R = Rxptr - 1;
            for (i = 4 ; i <= R ; i++)//For I = 6 To R
            {
                valbuf[i-3] = Rxbuf[i]; //Mystr = Mystr + Chr(rxbuf(i))
            }
     valbuf[R+1] = 0; //null terminate
     Param = atoi(valbuf);//   Param = Val(mystr)

     //Serial.println(Param); //   'Print "Parameter: " ; Param

       
              if (strcmp(cmdbuf,"NS")==0)       //NumSensors
              {
                   //'Print "command was ON"
                   if ((Param <= 8) && (Param > 0))
                   {
                      NumSensors = Param;                   
                   }
                   
              }
              if (strcmp(cmdbuf,"UD")==0)       //UpdateDelay
              {
                   //'Print "command was ON"
                   if ((Param <= 60) && (Param >= 0))
                   {
                      UpdateDelay = Param;                   
                   }
                   
              }
              if (strcmp(cmdbuf,"SV")==0)       //Save
              {
                   EEPROM.write(0,NumSensors);
                   EEPROM.write(1,UpdateDelay);
                   EEPROM.write(511,1);
              }
         }
}

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: Datalogger + Thermocouple Mux

by wilheldp on Sun May 12, 2013 5:31 pm

I really appreciate it, Rick. I didn't want to ask you to re-write the code, and I kinda understood what you were saying needed to happen, but after staring at the code for several hours, I really had no idea how to implement your solution. I will try your updated code when I get some time and report back if it works.

Thanks again for your help and patience.
wilheldp
 
Posts: 22
Joined: Tue May 07, 2013 6:14 pm

Re: Datalogger + Thermocouple Mux

by adafruit_support_rick on Sun May 12, 2013 5:58 pm

No problem. Good luck!

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: Datalogger + Thermocouple Mux

by wilheldp on Mon May 13, 2013 10:16 pm

OK...got that working with one little fix (if (channel == 8) instead of if (channel = 8) in the main loop). As soon as I tried to add the SD functionality, all of the thermocouples still read 0 degreesC.

All I added was...

Code: Select all | TOGGLE FULL SIZE
 // The objects to talk to the SD card
    Sd2Card card;
    SdVolume volume;
    SdFile root;
    SdFile file;
    File logfile; // The object that represents our datafile
    const byte chipSelect = 10; // chip select pin for SD card, 10 for regular Arduino, 53 for Mega


    //*****************************************************************************************
    // Error handling loop, from the tutorials at ladyada.net listed above
    // If there is a problem accessing the SD card, this loop gets called to display a cryptic
    // error message.
    void error(char *str)
    {
 
      Serial.print("Error:");
      Serial.print(str);
      while(1);
    }


before void selectThermocouple, and...

Code: Select all | TOGGLE FULL SIZE
     
           
      //initialize the SD card
      if (!SD.begin(chipSelect)) {
        error("SD Card failedor not present");
      }
     
      if (!card.init()) error("card.init, Reformat card");
      Serial.print("SD Card Initialized");
      delay(1500);

     
     
      // create a new file
      char name[] = "TEMPS00.CSV"; //File names will follow this format, and increment automatically
      for (uint8_t x = 0; x < 100; x++) {
        name[5] = x/10 + '0';
        name[6] = x%10 + '0';
        if (! SD.exists(name)) {
         logfile = SD.open(name, FILE_WRITE);
         break;
        }
      }
      if (! logfile) {
        error(" Could not    create a file.");
      }
   
 
      //Write the output file header row to our file so that we can identify the data later
      logfile.println("date,time,Ch1,Ch2,Ch3,Ch4,Ch5,Ch6,Ch7,Ch8");
      logfile.flush();
      delay(350);


at the beginning of void Setup.
wilheldp
 
Posts: 22
Joined: Tue May 07, 2013 6:14 pm

Please be positive and constructive with your questions and comments.