So I continued tinkering around and I found a weird solution. I changed the printTemperature orders around, basically putting printTemperatureB before printTemperatureA. Suddenly it works and no sensor returns 85°. But I really do not understand what was actually changed and why it's working now. I tried putting printTemperaturesB after printTemperaturesA again, but then the "BETA" Sensors return 85° again. Can somebody explain? My new code (ignore the comments :)):
//Bibliotheken aufstellen
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SD.h>
#include <SPI.h>
#include <Button.h>
#define ONE_WIRE_BUS_PIN_ALPHA 2 //Pin festlegen über den one_wire laueft
#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; //Pin des Knopfes
int buttonState = LOW; //Anfangsstatus des Pins
int measureState = 0;
long lastDebounceTime = 0;
long debounceDelay = 100;
void setup() //Setup läuft nur einmal
{
Serial.begin(9600);
Serial.print("Initializing Temperature Control Library Version ");
Serial.println(DALLASTEMPLIBVERSION);
sensorsA.begin();
sensorsB.begin();
//Aufloesung auf 10 Bit setzen (Kann von 9 bis 12 sein, je geringer umso schneller)
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...");
//Ueberpruefen ob SD-Karte vorhanden ist
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();
//Serial.print schreibt auf den seriellen Monitor (sprich: PC)
//mySensordata.print schreibt auf die SD-Karte (obriger Teil in diesem Fall noch fehlerhaft, da Datei noch nicht geöffnet, aber irrelevant)
pinMode(buttonPin, INPUT);
}//--(end setup )---
void loop() //loop laeuft immer wieder ab
{
buttonState = digitalRead(buttonPin);
//filter out any noise by setting a time buffer
if ( (millis() - lastDebounceTime) > debounceDelay) {
if ( (buttonState == HIGH) && (measureState == 0) ) {
measureState = 1; //now the LED is on, we need to change the state
lastDebounceTime = millis(); //set the current time
}
else if ( (buttonState == HIGH) && (measureState == 1) ) {
measureState = 0; //now the LED is off, we need to change the state
lastDebounceTime = millis(); //set the current time
Serial.println();
Serial.println("Bitte Knopf druecken");
Serial.println();
delay(1000);
}
if (measureState == 1){
//alle Sensoren sollen die Temperatur messen
sensorsA.requestTemperatures();
sensorsB.requestTemperatures();
mySensorData = SD.open("datalog.txt", FILE_WRITE);
//falls Datei vorhanden, darauf schreiben
if (mySensorData) {
printTemperatureB(Probe04);
Serial.print(" ");
mySensorData.print(" ");
printTemperatureB(Probe05);
Serial.print(" ");
mySensorData.print(" ");
printTemperatureB(Probe06);
Serial.print(" ");
mySensorData.print(" ");
printTemperatureA(Probe01);
Serial.print(" ");
mySensorData.print(" ");
printTemperatureA(Probe02);
Serial.print(" ");
mySensorData.print(" ");
printTemperatureA(Probe03);
Serial.print(" ");
mySensorData.print(" ");
mySensorData.println();
Serial.println();
mySensorData.close();
delay(1000);
}
//falls die Datei nicht geoeffnet werden kann ->Fehlermeldung
else {
Serial.println("error opening datalog.txt");
}
}
}
}
//Nutzung der Temperature-Bibliothek
void printTemperatureA(DeviceAddress DeviceAddress)
{
float tempCA = sensorsA.getTempC(DeviceAddress);
if (tempCA == -127.00)
{
Serial.print("Error getting temperature ALPHA "); //Falls ein Sensor nicht planmaessig funktioniert
}
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 "); //Falls ein Sensor nicht planmaessig funktioniert
}
else
{
Serial.print(tempCB);
mySensorData.print(tempCB);
}
}
//End
Greetings, Baerlax