I'm working on a project that has a nRF2.4 radio and uses an SD card (adafruit datalogger shield). I know the card is good. I know that the code works without the SD perfectly. When I add the code for the SD card... The code just goes into a loop at "Initializing SD card... card initialized." Writing it over and over. It writes blank files to the card with no header ("millis,stamp,datetime,light,temp,vcc"), completely blank. How do I fix the dang SPI conflict!? (assuming thats what it is).
Code (Partial to void loop, which it never reaches):
/*
Base only code...
*/
#include <serialGLCDlib.h>
#include <avr/pgmspace.h>
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#include "DHT.h"
#include <Wire.h>
#include "RTClib.h"
#include <SD.h>
#define DHTPIN 2 // DHT Pin
#define DHTTYPE DHT22 // DHT 22
DHT dht(DHTPIN, DHTTYPE);
RTC_DS1307 RTC;
#define LOG_INTERVAL 1000
#define SYNC_INTERVAL 1000
uint32_t syncTime = 0;
#define ECHO_TO_SERIAL 1 // echo data to serial port
#define WAIT_TO_START 0 // Wait for serial input in setup()
const int chipSelect = 10;
// the logging file
File logfile;
void error(char *str)
{
Serial.print("error: ");
Serial.println(str);
// red LED indicates error
// digitalWrite(redLEDpin, HIGH);
while(1);
}
// Avoid spurious warnings
#undef PROGMEM
#define PROGMEM __attribute__(( section(".progmem.data") ))
#undef PSTR
#define PSTR(s) (__extension__({static prog_char __c[] PROGMEM = (s); &__c[0];}))
RF24 radio(8,9); //Radio pins 3(to8),4(to9)
RF24Network network(radio);
// Our node address
uint16_t this_node;
// The message that we send is just an unsigned int, containing a sensor reading.
struct message_t
{
int temp_reading;
int humid_reading;
int voltage_reading;
int reset_reading;
message_t(void): temp_reading(0), humid_reading(0), voltage_reading(0), reset_reading(0) {}//ADD VOLTAGE READING!!!!
};
int lcdCount = 0;
int tempf = 0;
int humidrh = 0;
int voltage = 0;
int reset = 0;
char nodereset[10] = "RS";
char nodetemp1[10] = "ND";
char humid1[10] = "ND";
char voltage1[10] = "ND";
char nodetemp2[10] = "ND";
char humid2[10] = "ND";
char voltage2[10] = "ND";
char nodetemp3[10] = "ND";
char humid3[10] = "ND";
char voltage3[10] = "ND";
int nodetemp4 = 0;
int humid4 = 0;
char voltage4[10] = "ND";
char batstat1[14] = "Odr Bat Low!";
char batstat2[14] = "Idr Bat Low!";
char batstat3[14] = "Atc Bat Low!";
char sysStat[13] = "Sys Stus:";
char sysStatc[14] = "All Ok ";
//-------------------------------------------------------------------------------
void setup(void)
{
Serial.begin(115200);
delay(5000);
// Which node are we?
this_node = 0;
//
//DHT sensor
//
dht.begin();
Wire.begin();
RTC.begin();
// initialize the SD card
Serial.print("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(10, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
error("Card failed, or not present");
}
Serial.println("card initialized.");
// create a new file
char filename[] = "LOGGER00.CSV";
for (uint8_t i = 0; i < 100; i++) {
filename[6] = i/10 + '0';
filename[7] = i%10 + '0';
if (! SD.exists(filename)) {
// only open a new file if it doesn't exist
logfile = SD.open(filename, FILE_WRITE);
break; // leave the loop!
}
}
if (! logfile) {
error("couldnt create file");
}
Serial.print("Logging to: ");
Serial.println(filename);
logfile.println("millis,stamp,datetime,light,temp,vcc");
//
// Bring up the RF network
//
SPI.begin();
radio.begin();
network.begin(/*channel*/ 92, /*node address*/ this_node);
}
serialGLCD lcd; // initialisation
//------------------------------------------------------------------------------------
void loop(void)
{
// lcd.reverseColor();
if ( lcdCount == 0 ){
lcd.clearLCD();
DateTime now = RTC.now();