johnwasser:
It looks like you are connecting the Slave Select line to pin 53 but then telling the SD library to use pin 10 for Slave Select. Tell it to use 53.
I'm far from certain about what's going on here, but I think it is down to libraries and hardware.
I got most of my stuff going on a Uno and was then obliged to move to a Mega. What I have that appears to be different from the above is.
-
A sketch that uses the library SPI.h
-
An Ethernet+SD shield that uses the 6-pin ICSP cluster which is common to both Uno and Mega. The pins 11,12,13 thereon appear to be just pass-through, but pin 10 is connected.
All I did was plug it all in, uploaded the Uno sketch, and we were off and running without even thinking about it. Now, after a couple of months of reliable datalogging, I read this and wonder how it all happened. I have the line
pinMode(10, OUTPUT);
and pin 53 doesn't get a mention. Maybe the library handled it. Maybe this line should be removed. Looking back at my oldest identifiable sketch that uses the SD in the Uno, I now see that the library SPI.h is not listed. I also note that, in my recent attempt to account for each library, I haven't done so with this one, but my code will not compile without it.
I have made mistakes before. I have a display on the SPI bus on the Uno but it is now clear that it is simply on pins 11, 13 when I plug it into the Mega. And quite happy about it.
Here is my preamble and setup, the SD section of which may be of use.
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <Ethernet.h> // Ethernet
#include <HttpClient.h> // Cosm lib
#include <Cosm.h> // Cosm lib
#include <PCD8544.h> // Nokia 5110
#include <SD.h> // SD card
#include <string.h> // from Date As Filename
#include "RTClib.h" // from Date As Filename
#include "Wire.h" // Original RTC lib for LCD disp, SD card, and serial
#define DS1307_ADDRESS 0x68
RTC_DS1307 RTC;
static PCD8544 lcd;
File myFile;
char filename[] = "00000000.CSV";
// Custom symbols
static const byte DEGREES_CHAR = 1;
static const byte degrees_glyph[] = { 0x00, 0x07, 0x05, 0x07, 0x00 };
static const byte SLASH_CHAR = 2;
static const byte slash_glyph[] = {0x00,0x20,0x10,0x08};
byte InThermo[8] = {
0x28, 0x69, 0xC2, 0xB0, 0x03, 0x00, 0x00, 0X9F};
byte OutThermo[8] = {
0x28, 0x7A, 0x8B, 0xC0, 0x03, 0x00, 0x00, 0x2F};
byte DrainThermo[8] = {
0x28, 0x09, 0xA9, 0xC0, 0x03, 0x00, 0x00, 0x95};
#define ONE_WIRE_BUS 3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char cosmKey[] = "l6... la dadedahdah...0Zz0g";
int second, minute, hour, weekDay, monthDay, month, year;
int k=0;
float InTemp, OutTemp, DrainTemp; // used for SD write only
// Define the strings for our datastream IDs
char sensorId0[] = "InThermo";
char sensorId1[] = "OutThermo";
char sensorId2[] = "DrainThermo";
char calcId1[] = "diff";
const int bufferSize = 140;
char bufferValue[bufferSize]; // enough space to store the string we're going to send
CosmDatastream datastreams[] = {
CosmDatastream(sensorId0, strlen(sensorId0), DATASTREAM_FLOAT),
CosmDatastream(sensorId1, strlen(sensorId1), DATASTREAM_FLOAT),
CosmDatastream(sensorId2, strlen(sensorId2), DATASTREAM_FLOAT),
CosmDatastream(calcId1, strlen(calcId1), DATASTREAM_FLOAT),
};
// Finally, wrap the datastreams into a feed
CosmFeed feed(83153, datastreams, 4); //put your number of feeds here
EthernetClient client;
CosmClient cosmclient(client);
void setup() {
lcd.begin(84, 48);
// Register the custom symbols...
lcd.createChar(DEGREES_CHAR, degrees_glyph);
lcd.createChar(SLASH_CHAR, slash_glyph);
Wire.begin();
Serial.begin(9600);
Serial.print(" filename ");
delay(300);//Wait for newly restarted system to stabilize
lcd.setCursor (0,0);
lcd.print("Initializing");
delay(2000);
lcd.setCursor (0,1);
pinMode(10, OUTPUT);
if (!SD.begin(4))
{
lcd.print("failed!");
delay (2000);
return;
}
lcd.print("init. OK!");
delay(2000);
getFileName();
Serial.println(filename);
lcd.clear();
Serial.println("LABEL,Time,InTemp,OutTemp,diff,DrainTemp");
sensors.setResolution(InThermo, 12);
sensors.setResolution(OutThermo, 12);
sensors.setResolution(DrainThermo, 12);
Serial.println("Starting multiple datastream upload to Cosm...");
Serial.println();
while (Ethernet.begin(mac) != 1)
{
Serial.println("Error getting IP address via DHCP, trying again...");
delay(10000);
}
}