Electronic – arduino – Problem stacking accelerometer and SD card shields on Arduino UNO

accelerometerarduinosd

I have an ADXL345 accelerometer on a Makershield stacked on top of a Seeed SD card shield. Both of those are stacked on an Arduino UNO R2.

I've got each working individually, but when stacked they share pin 12. The SD Card shield uses 12 for MISO of SPI and the ADXL345 uses it for SDO/Alt address.

I'm new to Arduino and have not stacked shields like this before. I'm not sure what the best course of action is here to get them both working, Ultimately, I want to log the data from the accelerometer to the SD card, but first things first!

I'd be grateful for any help. I've linked the data sheets for the ADXL345 and the SD shield above.

Best Answer

Your best solution will depend on which mode you are operating the ADXL345 in.

If you are operating it in SPI mode, then pin 12 is being used for the same role on both boards, and they should be able to share simply by taking turns - only the one which has (had) its slave select activated should be driving return data.

If you are operating it in I2C mode, then you can cut the trace or remove the pin from the shield and permanently wire it high or low depending on which address you want to select. It's also possible that you could reconfigure pin 12 as an ouput and drive it high or low whenever you want to talk to the ADXL345, then make it an input again when talking to the SD. Even putting a pullup resistor on it would be likely to work - that would let the ADXL345 see it as a high (just a reliable value to control the address) and still let the SD card override it to send data.

If you don't know which mode is being used, look through the code (for the library) you are using to interact with it. (As a guess, it's probably I2C mode, because if it were SPI it would probably want to use most of the same pins the SD shield were using, instead of just one). Or check the /CS pin - if it's wired high you have I2C mode, if it's connected to an Arduino pin you might have SPI.