I recently purchased an arduino uno, a dfrobot ethernet shield and iteadstudio SD card shield. from what i can make out it directly relates to this SPI sharing issue, according to the docs both devices share exactly the same pins, 10, 11, 12 ,13. I can get each device as a standalone working fine but the second i power up the with the ethernet shield on top the SD goes to custard.
I've spent many hours reading an it seems so simle that ... if i shutdown pin 10 with a high signal all should be fine and i can open up the SD card ... but the fact is .. for some reason its NOT working ... i just cannot get that SD card up and running. so its it a hardware fix i am needing or can this be done with software.
Also I think the relevant info re spcecs of each device.
Pin of Arduino With iteadstudio SD Card
Arduino SD Card
5V VCC - 3v3
GND GND
D13 SD_CLK
D12 SD_OUT
D11 SD_IN
D10 SD_CS
dfrobot Ethernet Card w5100
D13 / SCK
D12 / MISO
RESET D11 / MOSI ~
D10 / SS ~
My code is as follows .. seems to work perfectly untill i plug in the ethernet.
/*
SD card datalogger
- SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 10
#include <OneWire.h>
#include <DallasTemperature.h>
// SD card Library
#include <SD.h>
#include <SPI.h>
// CLOCK Library
#include <DS3231.h>
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
DS3231 Clock;
bool Century=false;
bool h12;
bool PM;
byte ADay, AHour, AMinute, ASecond, ABits;
bool ADy, A12h, Apm;
byte year, month, date, DoW, hour, minute, second;
// SD card
const int chipSelect = 10;
// // Temperature wires connected to Pin 3 on the Arduino (4 sensors in bus configuration)
#define ONE_WIRE_BUS 3
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// relay Digital pin 6
#define RELAY1 6
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Assign the addresses of your 1-Wire temp sensors.
DeviceAddress insideThermometer = { 0x28, 0x02, 0xA7, 0xA9, 0x03, 0x00, 0x00, 0xCC };
DeviceAddress outsideThermometer = { 0x28, 0x7E, 0x9F, 0xA9, 0x03, 0x00, 0x00, 0x93 };
DeviceAddress firehotwaterThermometer = { 0x28, 0xBB, 0x73, 0xA9, 0x03, 0x00, 0x00, 0x1C };
DeviceAddress radiatorThermometer = { 0x28, 0xA7, 0x9A, 0xA9, 0x03, 0x00, 0x00, 0x13 };
void setup()
{
//
// disable the ethernet ???
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);
// Open serial communications and wait for port to open:
// Start the I2C interface
Wire.begin();
// set up relay as output
Serial.begin(57600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("Initializing SD card...");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
// Start up the library of temp sensors
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(insideThermometer, 10);
sensors.setResolution(outsideThermometer, 10);
sensors.setResolution(firehotwaterThermometer, 10);
sensors.setResolution(radiatorThermometer, 10);
}
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
Serial.print("Error getting temperature");
} else {
Serial.print("C: ");
Serial.print(tempC);
//Who Want farenheight!
// Serial.print(" F: ");
// Serial.print(DallasTemperature::toFahrenheit(tempC));
}
}
void loop()
{
Clock.getTime(year, month, date, DoW, hour, minute, second);
// make a string for assembling the data to log:
String dataString = "";
// read three sensors and append to the string:
/*
for (int analogPin = 0; analogPin < 3; analogPin++) {
int sensor = analogRead(analogPin);
dataString += String(sensor);
if (analogPin < 2) {
dataString += ",";
}
}
*/
float tempA;
float tempB;
float tempC;
float tempD;
float tempTEST;
String pumpStatus = "unknown";
Serial.print("Getting temperatures...\n\r");
sensors.requestTemperatures();
tempA = sensors.getTempC(insideThermometer);
tempB = sensors.getTempC(outsideThermometer);
tempC = sensors.getTempC(firehotwaterThermometer);
tempD = sensors.getTempC(radiatorThermometer);
tempTEST = tempC - tempD;
if (int(float(tempTEST > 5))) {
digitalWrite(RELAY1,LOW); // Turns ON Relays 1
pumpStatus = "On";
}
else
{
digitalWrite(RELAY1,HIGH);
pumpStatus = "Off";
}
// open the file. note that only one file can be open at a time, so you have to close this one before opening another.
File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
// dataFile.println(dataString);
dataFile.print(date, DEC);
dataFile.print("/");
dataFile.print(month, DEC);
dataFile.print("/");
dataFile.print("2");
if (Century) { // Won't need this for 89 years.
dataFile.print("1");
} else {
dataFile.print("0");
dataFile.print(year, DEC);
}
dataFile.print(" ");
dataFile.print(hour, DEC);
dataFile.print(":");
dataFile.print(minute, DEC);
dataFile.print(":");
dataFile.print(second, DEC);
// Start Dumping the Temperatures
dataFile.print(" ");
dataFile.print(tempA);
dataFile.print(" ");
dataFile.print(tempB);
dataFile.print(" ");
dataFile.print(tempC);
dataFile.print(" ");
dataFile.print(tempD);
dataFile.print(" ");
dataFile.println(pumpStatus);
// Close the file
dataFile.close();
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
// temps to serial port
Serial.print("Inside temperature is: ");
printTemperature(insideThermometer);
Serial.print("\n\r");
Serial.print("Outside temperature is: ");
printTemperature(outsideThermometer);
Serial.print("\n\r");
Serial.print("Fire Water temperature is: ");
printTemperature(firehotwaterThermometer);
Serial.print("\n\r");
Serial.print("Radiator temperature is: ");
printTemperature(radiatorThermometer);
Serial.print("\n\r\n\r");
Serial.print("Temprature Difference:");
Serial.print (tempTEST);
Serial.print("\n\r");
Serial.print("Pump status: ");
Serial.print(pumpStatus);
// print to the serial port too:
Serial.println(dataString);
Serial.print(date, DEC);
Serial.print("/");
Serial.print(month, DEC);
Serial.print("/");
Serial.print("2");
if (Century) { // Won't need this for 89 years.
Serial.print("1");
} else {
Serial.print("0");
}
Serial.print(year, DEC);
//Serial.print("day of the week :");
// Serial.println(DoW, DEC);
Serial.print(" ");
Serial.print(hour, DEC);
Serial.print(":");
Serial.print(minute, DEC);
Serial.print(":");
Serial.println(second, DEC);
Serial.print(" ");
Serial.print(tempA);
Serial.print(" ");
Serial.print(tempB);
Serial.print(" ");
Serial.print(tempC);
Serial.print(" ");
Serial.print(tempD);
Serial.print(" ");
Serial.print(pumpStatus);
// Lets delay before write to the log file again.
delay(30000);
}