I want to use SD Card Sheild and Centipede Shield at the same time

I want to use SD Card Sheild and centipede_shield at the same time.

http://docs.macetech.com/doku.php/centipede_shield

I tested the SD Card Sheild sample programs and they worked well.Also I tested Centipede Sheild programes and they worked well.But when I had added this centipede's code to the simple SD card code, it wouldn't work.

CS.initialize(); // set all registers to default
 CS.portMode(0, 0b0000000000000000); // set all pins on chip 0 to output

I think it was caused by around SS, how do you think about it?

I think it was caused by around SS, how do you think about it?

We cannot think about it because you don't supply the whole code. The code you posted is most probably not responsible for your problems.

The SD card shield from Seeedstudio and the centipede shield don't have conflicting pin usages so from the hardware perspective it should be OK. That leaves the software but you haven't supplied it.

Thank you for responding pylon!

The SD card shield from Seeedstudio and the centipede shield don’t have conflicting pin usages
This is what I wanted to know.

Sorry for not having supplied the full source code. Here is my test code.

#include <Wire.h>
#include <Centipede.h>
#include <SdFat.h>

#define MAXLINE 10
#define MAXBUF 100

// SD chip select pin
const uint8_t chipSelect = SS;

// file system object
SdFat sd;

// define a serial output stream
ArduinoOutStream cout(Serial);

//define pins
#define DATAOUT     11   //mosi
#define DATAIN	12   //miso
#define SPICLOCK    13   //sck
#define SLAVESELECT 10   //ss//

#define ANALOG4 4//for Wire/I2C
#define ANALOG5 5

Centipede CS; // create Centipede object

//------------------------------------------------------------------------------
void setup() {
  Serial.begin(9600);

  pinMode(DATAOUT, OUTPUT);
  pinMode(DATAIN, INPUT);
  pinMode(SPICLOCK, OUTPUT);
  pinMode(SLAVESELECT, OUTPUT);//??
  
  Wire.begin(); // start I2C
   
   CS.initialize(); // set all registers to default
   CS.portMode(0, 0b0000000000000000); // set all pins on chip 0 to output
  
  // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
  // breadboards.  use SPI_FULL_SPEED for better performance.
  
  if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();
    
   // set current working directory
  if (!sd.chdir("DATA/")) {
    sd.errorHalt("chdir failed. Did you run eventlog.pde?");
  }
  // open file in current working directory
   ifstream file("TEST.TXT");

  if (!file.is_open()) sd.errorHalt("open failed");
  
  char c;
  char buf[MAXLINE];
  int ibuf[MAXBUF];
  int k = 0;
  int m = 0;
  int n;
  // copy the file to Serial
  //while ((c = file.get()) >= 0) cout << c;
  clearBuf(buf, MAXLINE);
  while(true) {
    c = file.get();
    if(c < 0)
      break;
    else
    {
      if(c == ' ' || c == '\n' || c == '\t' || c == ',' || c == '\r')
      {
        if(k > 0)
        {
          n = iatoi(buf);
          //cout << n << '\n';
          ibuf[m++] = n;
          clearBuf(buf, MAXLINE);
        }
        k = 0;
      }
      else
         buf[k++] = c;
     }
  }

  for(int i = 0; i < m; i++)
    cout << ibuf[i] << '\n';
    
  cout << "Done\n" << endl;
}

void clearBuf(char* s, int len)
{
  for(int i = 0; i < len; i++)
    *(s+i) = ' ';
}

int iatoi(char* s)
{
	register int	i, n;
	int	sign;

	for(i = 0; *(s+i) == ' ' || *(s+i) == '\n' || *(s+i) == '\t' || *(s+i) == ','; i++)
		;
	sign = 1;
	if(*(s+i) == '+' || *(s+i) == '-')
		sign = (*(s+i++) == '+') ? 1 : -1;
	for(n = 0; *(s+i) >= '0' && *(s+i) <= '9'; i++)
		n = 10 * n + *(s+i) - '0';
	return(sign * n);
}
//------------------------------------------------------------------------------
void loop() {}

This code wouldn’t work with this error message.

Can't access SD card. Do not reformat.
No card, wrong chip select pin, or SPI problem?
SD errorCode: 0X1

But, when I commented out these lines, It worked!

  //CS.initialize(); // set all registers to default
  //CS.portMode(0, 0b0000000000000000); // set all pins on chip 0 to output

I stacked the SD card sheild and the centipede sheild on an Arduino Duemilanove.The DATA.TXT is like…

1 2 3 4 5
10 20 30 40 50
0 -10 -20 -30 -40

This

const uint8_t chipSelect = SS;

does only work with an UNO or compatible but not with a MEGA or Leonardo.

Set it this way:

const uint8_t chipSelect = 10;

because the pin 10 is fixed for this shield.

I cannot find a problem with the two commented out lines.

How have you defined that line

ArduinoOutStream cout(Serial);

Do you use a current IDE?

Thank you for replying pylon!

I had tried your suggestion "const uint8_t chipSelect = 10;", but it seemed nothing to be changed. I used "cout" only for debugging. I will delete these codes when it works completely.

The conditions are unstable. Actually sometimes it worked well with the "CS" codes, but sometimes it wouldn't work.

You didn't understand my question correctly:

How have you defined that line

ArduinoOutStream cout(Serial);

That meant: Where do you have the class ArduinoOutStream from. I cannot find it in your code and it's not a standard class. You didn't provide a link to it, so I have no clue about it's internals. Have you written it yourself? Did you copy it from somewhere? It's possible that this class is responsible for your problems.