Hello!
I'm currently trying to program a Temperature logger. I'm using an Arduino UNO with an Wireless SD Shield. I was using three DS18B20 sensors on Onewire and everything worked fine; the temperature was logged to the SD-Card.
However, when I added another three DS18B20 on a separate OneWire I faced a new problem: The first temperatures returned are correct, however after the second response the three "new" Sensors all respond with 85°.
Now, I started looking in the forums to solve this problem, and I think there are two possibilities: Either the hardware is defunct (bad cables) or I need to add somekind of delay to let the Sensors do their Conversion. I don't believe it's a hardware issue, because it works in the first loop. I also tried to add delays, however nothing worked yet. Thats why I am asking you for help.
Here is my Code:
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SD.h>
#include <SPI.h>
#include <Button.h>
#define ONE_WIRE_BUS_PIN_ALPHA 2
#define ONE_WIRE_BUS_PIN_BETA 4
OneWire oneWireA(ONE_WIRE_BUS_PIN_ALPHA);
OneWire oneWireB(ONE_WIRE_BUS_PIN_BETA);
int chipSelect=4;
int counter = 0;
File mySensorData;
DallasTemperature sensorsA(&oneWireA);
DallasTemperature sensorsB(&oneWireB);
DeviceAddress Probe01 = { 0x28, 0x15, 0x5F, 0x4D, 0x07, 0x00, 0x00, 0x53 };
DeviceAddress Probe02 = { 0x28, 0x75, 0xC5, 0x4B, 0x07, 0x00, 0x00, 0x93 };
DeviceAddress Probe03 = { 0x28, 0xC0, 0xDC, 0x4C, 0x07, 0x00, 0x00, 0x76 };
DeviceAddress Probe04 = { 0x28, 0x81, 0x55, 0x4D, 0x07, 0x00, 0x00, 0x83 };
DeviceAddress Probe05 = { 0x28, 0xF1, 0xD2, 0x4B, 0x07, 0x00, 0x00, 0x88 };
DeviceAddress Probe06 = { 0x28, 0x9F, 0x84, 0x4C, 0x07, 0x00, 0x00, 0xD7 };
const int buttonPin = 3;
int buttonState = LOW;
int measureState = 0;
long lastDebounceTime = 0;
long debounceDelay = 100;
void setup()
{
Serial.begin(9600);
Serial.print("Initializing Temperature Control Library Version ");
Serial.println(DALLASTEMPLIBVERSION);
sensorsA.begin();
sensorsB.begin();
sensorsA.setResolution(Probe01, 10);
sensorsA.setResolution(Probe02, 10);
sensorsA.setResolution(Probe03, 10);
sensorsB.setResolution(Probe04, 10);
sensorsB.setResolution(Probe05, 10);
sensorsB.setResolution(Probe06, 10);
Serial.print("Initializing SD card...");
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
Serial.println(); }
Serial.print("Number of Devices found on bus ALPHA = ");
Serial.println(sensorsA.getDeviceCount());
Serial.print("Number of Devices found on bus BETA = ");
Serial.println(sensorsB.getDeviceCount());
Serial.print("Getting temperatures... ");
Serial.println();
Serial.println();
Serial.println("card initialized.");
Serial.println();
Serial.println();
Serial.print("Temp1 ");
mySensorData.print("Temp1 ");
Serial.print("Temp2 ");
mySensorData.print("Temp2 ");
Serial.print("Temp3 ");
mySensorData.print("Temp3 ");
mySensorData.println();
Serial.println();
pinMode(buttonPin, INPUT);
}//--(end setup )---
void loop()
{
buttonState = digitalRead(buttonPin);
//filter out any noise by setting a time buffer
if ( (millis() - lastDebounceTime) > debounceDelay) {
if ( (buttonState == HIGH) && (measureState == 0) ) {
measureState = 1;
lastDebounceTime = millis();
}
else if ( (buttonState == HIGH) && (measureState == 1) ) {
measureState = 0;
lastDebounceTime = millis();
Serial.println();
Serial.println("Bitte Knopf druecken");
Serial.println();
delay(1000);
}
if (measureState == 1){
sensorsA.requestTemperatures();
sensorsB.requestTemperatures();
delay(1000);
mySensorData = SD.open("datalog.txt", FILE_WRITE);
if (mySensorData) {
printTemperatureA(Probe01);
Serial.print(" ");
mySensorData.print(" ");
printTemperatureA(Probe02);
Serial.print(" ");
mySensorData.print(" ");
printTemperatureA(Probe03);
Serial.print(" ");
mySensorData.print(" ");
printTemperatureB(Probe04);
Serial.print(" ");
mySensorData.print(" ");
printTemperatureB(Probe05);
Serial.print(" ");
mySensorData.print(" ");
printTemperatureB(Probe06);
Serial.print(" ");
mySensorData.print(" ");
mySensorData.println();
Serial.println();
mySensorData.close();
delay(1000);
}
else {
Serial.println("error opening datalog.txt");
}
}
}
}
void printTemperatureA(DeviceAddress DeviceAddress)
{
float tempCA = sensorsA.getTempC(DeviceAddress);
if (tempCA == -127.00)
{
Serial.print("Error getting temperature ALPHA ");
}
else
{
Serial.print(tempCA);
mySensorData.print(tempCA);
}
}
void printTemperatureB(DeviceAddress DeviceAddress)
{
float tempCB = sensorsB.getTempC(DeviceAddress);
if (tempCB == -127.00)
{
Serial.print("Error getting temperature BETA ");
}
else
{
Serial.print(tempCB);
mySensorData.print(tempCB);
}
}
//End
Here is also a picture of the serial monitor
I am really looking forward to your ideas! ![]()
Greetings, Baerlax