I've got an arduino MEGA 2560 R3 with an Ethernet shield 2 with SD card, a BME280 sensor, a raindrop sensor and a DS3231 RTC. All works fine with an ethernet server running on 2560.
Sensors values are stored on the card without any problem.
I am trying to connect a GPS shield from DuinoPeak with SD card on it.
I have a problem on my sketch SD card initialization failed. Here is my sketch without the main loop section....
Any hint?
#include <SPI.h>
#include <DS3231.h>
#include <Ethernet2.h>
#include <EthernetUdp2.h>
#include <SD.h>
#include "SparkFunBME280.h"
#include <LiquidCrystal_I2C.h>
#include "TinyGPS.h"
#define GPS_TX_DIGITAL_OUT_PIN 5
#define GPS_RX_DIGITAL_OUT_PIN 6
#define LCDDELAY 800
#define SERIALBAUD 9600
#define DEBUG 1
//#define SDCARD 1
#define DELIM ";"
#define KPtoBR 0.01
byte mac[] = { 0x90, 0xA2, 0xDA, 0x11, 0x2E, 0x56 };
IPAddress dnServer(192, 168, 10, 1);
IPAddress gateway(192, 168, 10, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress ip(192, 168, 10, 150);
EthernetUDP Udp;
EthernetServer server(80);
DS3231 rtc(SDA, SCL);
File myFile;
BME280 mySensor;
char writebuffer[100], logfilename[13];
unsigned long tepTimer, rainTimer;
unsigned int localPort = 8888;
LiquidCrystal_I2C lcd(0x27, 16, 2);
TinyGPS gps;
float latitude = 0.0, longitude = 0.0, altitude = 0.0, course = 0.0, speed = 0.0;
long startMillis;
long secondsToFirstLocation = 0;
char sz[32];
const int sensorMin = 0;
const int sensorMax = 1024;
void setup() {
lcd.init(); lcd.backlight(); lcd.setCursor(0, 1); lcd.print("Hello, world!");
#ifdef DEBUG
Serial.begin(SERIALBAUD);
Serial.println("Initializing Serial...");
while (!Serial) { ; }
#endif
#ifdef DEBUG
Serial.println("Initializing RTC...");
#endif
rtc.begin();
delay(LCDDELAY);
// rtc.setDOW(THURSDAY); rtc.setTime(11, 8, 00); rtc.setDate(26, 4, 2018);
strcpy(writebuffer, rtc.getDateStr()); strcat(writebuffer, DELIM); strcat(writebuffer, rtc.getTimeStr()); strcat(writebuffer, DELIM);
#ifdef SDCARD
Serial.println("Initializing SD card...");
pinMode(53, OUTPUT);
while (!SD.begin()) {
Serial.println("initialization failed!");
}
strcpy(logfilename, "meteoint.txt");
myFile = SD.open(logfilename, FILE_WRITE);
delay(LCDDELAY);
writemyfile("Initializing SD card...\n");
writemyfile("IP Setup........\n");
#endif
#ifdef DEBUG
Serial.println("IP Setup ...");
#endif
Ethernet.begin(mac, ip, dnServer, gateway, subnet);
delay(LCDDELAY);
Udp.begin(localPort);
#ifdef SDCARD
writemyfile("Initializing BME280...: 0x\n");
#endif
#ifdef DEBUG
Serial.print("Initializing BME280 card... id--> ");
#endif
bme280setup();
delay(LCDDELAY);
#ifdef DEBUG
Serial.println(mySensor.begin(), DEC);
#endif
#ifdef SDCARD
writemyfile("GPS Setup........\n");
#endif
#ifdef DEBUG
Serial.println("GPS Setup ...");
#endif
Serial1.begin(9600);
pinMode(GPS_TX_DIGITAL_OUT_PIN, INPUT);
pinMode(GPS_RX_DIGITAL_OUT_PIN, INPUT);
startMillis = millis();
delay(LCDDELAY);
#ifdef SDCARD
myFile.close();
#endif
#ifdef DEBUG
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
#endif
server.begin();
#ifdef DEBUG
Serial.println("Server Started");
#endif
}
void loop() {
}