Hey!
I am working on a project to log data from 6 Temperature sensors (DS18B20) with an arduino UNO and Ubuntu 15.10 OS.
I am using a DS3231 Real Time clock and a MicroSD board using SPI. I am running the Temperature sensors in parasite mode as described in the datasheet.
From the code I expected to get an output of Date, time and 6 temperature values in each row of the serial monitor as well as in the .txt file on the sd card. The first time i uploaded the code to the arduino it worked perfectly.
From thwe 2nd time I dont get any output on the Serial Monitor. On the SD card the file is created and the headers are written in the .txt file, but there is no values of measurments logged.
I can find the adresses of all the temperature sensors with the programm provided here , I checked the availability of the SD card with a small programm and the red light on the RTC is on as soon as I connect it with my computer.
I cannot figure out why it is not working and I would apreciate any Ideas. Below you will find the code I uploaded and a fritzing diagramm.
include <OneWire.h>
#include <DallasTemperature.h> #include <SPI.h>
#include <SD.h>
#include <DS3231.h>
int chipSelect=10;//Set chipselect 10d
File sensorData ;// Variable for writing our Data File
// Init the DS3231 using the hardware interface
// DS3231 SDA is connected to Analog 4, SCL to Analog 5
DS3231 rtc(SDA, SCL);
// The data wire is plugged into port 2 on the Arduino
#define oneWire_BUS 2
// ADC resolution of 12 bit
#define temperatureResolution 12
unsigned int delay_milliseconds = 168;
// ...
unsigned int seconds = 0;
/* Setup a oneWire instance to communicate with any OneWire devices
* (not just Maxim/Dallas temperature ICs) */
OneWire oneWire(oneWire_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Arrays to hold device addresses
DeviceAddress Sensor_B = { 0x28, 0xFF, 0x7F, 0xCD, 0x00, 0x16, 0x04, 0xC9 };
DeviceAddress Sensor_C = { 0x28, 0xFF, 0x6F, 0xC2, 0x00, 0x16, 0x04, 0x2F };
DeviceAddress Sensor_D = { 0x28, 0xFF, 0x4F, 0xF8, 0x00, 0x16, 0x04, 0x84 };
DeviceAddress Sensor_E = { 0x28, 0xFF, 0xFD, 0x0D, 0x01, 0x16, 0x04, 0x13 };
DeviceAddress Sensor_G = { 0x28, 0xFF, 0x4D, 0xE5, 0x00, 0x16, 0x04, 0xA2 };
DeviceAddress Sensor_H = { 0x28, 0xFF, 0xD8, 0x15, 0x05, 0x16, 0x03, 0x00 };
// Variables to store temperature values
float tB;
float tC;
float tD;
float tE;
float tG;
float tH;
void setup(void)
{ // Start serial port
Serial.begin(9600);
//Initialize the rtc object
//rtc.begin();
//rtc.setDOW(WEDNESDAY); // Set Day-of-Week to SUNDAY
//rtc.setTime(12, 28, 0); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(20, 4, 2016); //Set the date to January 1st, 2014
// Start up the library
sensors.begin();
// Set the resolution to 12 bit
sensors.setResolution(Sensor_B, temperatureResolution);
sensors.setResolution(Sensor_C, temperatureResolution);
sensors.setResolution(Sensor_D, temperatureResolution);
sensors.setResolution(Sensor_E, temperatureResolution);
sensors.setResolution(Sensor_G, temperatureResolution);
sensors.setResolution(Sensor_H, temperatureResolution);
SD.begin(chipSelect);//Initialize SD Card with Chipselect
sensorData= SD.open("testData.txt", FILE_WRITE); //open File DATA.txt on SD card as file to write to
if (sensorData) {
sensorData.print("Date"); sensorData.print("\t");
sensorData.print("Time"); sensorData.print("\t");
sensorData.print("C"); sensorData.print("\t");
sensorData.print("B"); sensorData.print("\t");
sensorData.print("D"); sensorData.print("\t");
sensorData.print("E"); sensorData.print("\t");
sensorData.print("G"); sensorData.print("\t");
sensorData.print("H"); sensorData.print("\t");
sensorData.println();
}
sensorData.close();
}
// Function to get the temperature for a device
float getTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC <= -127.00)
{
Serial.print("NA");
}
else
{
return(tempC);
}
}
// Function to print the temperature or temperature difference
void printTemperatures(void)
{ Serial.print(rtc.getDateStr()); Serial.print("\t");
Serial.print(rtc.getTimeStr()); Serial.print("\t");
Serial.print(tB); Serial.print("\t");
Serial.print(tC); Serial.print("\t");
Serial.print(tD); Serial.print("\t");
Serial.print(tE); Serial.print("\t");
Serial.print(tG); Serial.print("\t");
Serial.print(tH); Serial.print("\t");
Serial.println();
sensorData= SD.open("testData.txt", FILE_WRITE); //open File DATA.txt on SD card as file to write to
if (sensorData) {
sensorData.print(rtc.getDateStr()); sensorData.print("\t");
sensorData.print(rtc.getTimeStr()); sensorData.print("\t");
sensorData.print(tB); sensorData.print("\t");
sensorData.print(tC); sensorData.print("\t");
sensorData.print(tD); sensorData.print("\t");
sensorData.print(tE); sensorData.print("\t");
sensorData.print(tG); sensorData.print("\t");
sensorData.print(tH); sensorData.print("\t");
sensorData.println();
}
sensorData.close();
}
void loop(void)
{
// Issue a global temperature request to all devices on the bus
sensors.requestTemperatures();
// Get temperature values
tC = getTemperature(Sensor_B);
tB = getTemperature(Sensor_C);
tD = getTemperature(Sensor_D);
tE = getTemperature(Sensor_E);
tG = getTemperature(Sensor_G);
tH = getTemperature(Sensor_H);
// Print the device information
printTemperatures();
// Delay time
delay(delay_milliseconds);
}