Go Down

Topic: Datalogger cannot open text (Read 150 times) previous topic - next topic

noobcoder22

Good day everyone

Im having trouble encoding data using a SD card module.

the problem is that the initialization fails, and i dont know why.

Code: [Select]

#include <OneWire.h>
#include <DallasTemperature.h>
#include <SD.h>
#include <SPI.h>
#include <DHT.h>
#include <Wire.h>


#include "RTClib.h"
#define ONE_WIRE_BUS_PIN 5
#define DHTPIN1 3
#define DHTPIN2 6
#define DHTTYPE1 DHT22 // DHT 22 (AM2302)
#define DHTTYPE2 DHT22 // DHT 22 (AM2302)

#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
   #define Serial SerialUSB
#endif
//Variables

DHT dht1(DHTPIN1, DHTTYPE1);
DHT dht2(DHTPIN2, DHTTYPE2);
RTC_DS1307 rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

OneWire oneWire(ONE_WIRE_BUS_PIN);

DallasTemperature sensors(&oneWire);

DeviceAddress Probe01 = { 0x28, 0xFF, 0xBC, 0x3F, 0x71, 0x17, 0x03, 0xD0};
DeviceAddress Probe02 = { 0x28, 0xFF, 0x49, 0x42, 0x71, 0x17, 0x03, 0x91 };
DeviceAddress Probe03 = { 0x28, 0xFF, 0xE5, 0x8C, 0x83, 0x16, 0x03, 0xA9 };
DeviceAddress Probe04 = { 0x28, 0xFF, 0x79, 0x1D, 0x71, 0x17, 0x03, 0x57 };
DeviceAddress Probe05 = { 0x28, 0xFF, 0xB9, 0x3C, 0x71, 0x17, 0x03, 0x8A };
DeviceAddress Probe06 = { 0x28, 0xFF, 0x24, 0x19, 0xA0, 0x16, 0x05, 0x8B };
int chk;
float hum1;  //Stores humidity value
float temp1; //Stores temperature value
float hum2;  //Stores humidity value
float temp2; //Stores temperature value


File probe01;
  void setup() {
   
 Serial.begin(9600);

  // SD Card Initialization
  if (SD.begin())
  {
   
    Serial.println("SD card is ready to use.");
      sensors.begin();
      sensors.setResolution(Probe01, 10);
      sensors.setResolution(Probe02, 10);
      sensors.setResolution(Probe03, 10);
      sensors.setResolution(Probe04, 10);
      sensors.setResolution(Probe05, 10);
      sensors.setResolution(Probe06, 10);


  } else
  {
    Serial.println("SD card initialization failed");
    return;
  }
  rtc.begin();   
}
void loop() {
DateTime now = rtc.now();

 
   
    sensors.requestTemperatures();
  probe01 = SD.open("PROBE01.txt", FILE_WRITE);
  if (probe01) {   
   
    probe01.print(now.year(), DEC);
    probe01.print('/');
    probe01.print(now.month(), DEC);
    probe01.print('/');
    probe01.print(now.day(), DEC);
    probe01.print(" (");
    probe01.print(daysOfTheWeek[now.dayOfTheWeek()]);
    probe01.print(") ");
    probe01.print(now.hour(), DEC);
    probe01.print(':');
    probe01.print(now.minute(), DEC);
    probe01.print(':');
    probe01.print(now.second(), DEC);
    probe01.print(",");

   

  Serial.print("Probe 01 temperature is:   ");
  printTemperature(Probe01);
  Serial.println();

  Serial.print("Probe 02 temperature is:   ");
  printTemperature(Probe02);
  Serial.println();
 
  Serial.print("Probe 03 temperature is:   ");
  printTemperature(Probe03);
  Serial.println();
   
  Serial.print("Probe 04 temperature is:   ");
  printTemperature(Probe04);
  Serial.println();
 
  Serial.print("Probe 05 temperature is:   ");
  printTemperature(Probe05);
  Serial.println();

  Serial.print("Probe 06 temperature is:   ");
  printTemperature(Probe06);
  Serial.println();


   
   
  probe01.println();
    probe01.close();
    // close the file
                                                 
  }
  // if the file didn't open, print an error:
  else {
    Serial.println("error opening test.txt");
  }

  delay(3000);
}

void printTemperature(DeviceAddress deviceAddress)
{

float tempC = sensors.getTempC(deviceAddress);

   if (tempC == -127.00)
   {
   Serial.print("Error getting temperature  ");
   }
   else
   {
   Serial.print(tempC);
   Serial.print(",");
   probe01.print(tempC);
   probe01.print(",");
   }


}

ieee488

First step may be to try a simple Examples --> ReadWrite sketch .

Go Up