I have written a sketch to read multiple ds18B20s across multiple buses as my wiring is set up in a star config and will not read them on a single pin. That is not my problem as the sketch is working properly. My issue is I would like to have the Temp print to two decimal points, it currently prints to a whole number. I have read several posts on print and adding a comma space and then the number of digits I want to print. When I do that I get what looks like a log number rather than the 2 decimal places.
Below is my sketch. Any suggestions??
#include <OneWire.h>
#include <DallasTemperature.h>
/-----( Declare Constants and Pin Numbers )-----/
#define bus1 8 // For BUS 1
#define bus2 9 // for BUS 2
#define bus3 10 // for BUS 3
#define bus4 11 // for BUS 4
/-----( Declare objects )-----/
OneWire oneWireA(bus1); // Create a 1-wire object
OneWire oneWireB(bus2);
OneWire oneWireC(bus3);
OneWire oneWireD(bus4);
DallasTemperature sensorsA (&oneWireA);
DeviceAddress Probe01 = { 0x28, 0x5C, 0x7F, 0x95, 0x09, 0x00, 0x00, 0xA1 };
DallasTemperature sensorsB (&oneWireB);
DeviceAddress Probe02 = { 0x28, 0xD4, 0x63, 0x95, 0x09, 0x00, 0x00, 0xB7 };
DallasTemperature sensorsC (&oneWireC);
DeviceAddress Probe03 = { 0x28, 0x6B, 0x90, 0xBF, 0x6, 0x0, 0x0, 0x48 };
DallasTemperature sensorsD (&oneWireD);
DeviceAddress Probe04 = { 0x28, 0x50, 0xB7, 0x96, 0x0A, 0x00, 0x00, 0xAC };
int Temp1,Temp2,Temp3,Temp4;
void setup() {
Serial.begin(9600);
// Initialize the Temperature measurement library
sensorsA.begin();
sensorsB.begin();
sensorsC.begin();
sensorsD.begin();
delay(500);
// set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
sensorsA.setResolution(Probe01, 9);
sensorsB.setResolution(Probe02, 9);
sensorsC.setResolution(Probe03, 9);
sensorsD.setResolution(Probe04, 9);
}
void loop()
{
// Command all devices on bus to read temperature
sensorsA.requestTemperatures();
sensorsB.requestTemperatures();
sensorsC.requestTemperatures();
sensorsD.requestTemperatures();
Temp1 = sensorsA.getTempC (Probe01);
Temp2 = sensorsB.getTempC (Probe02);
Temp3 = sensorsC.getTempC (Probe03);
Temp4 = sensorsD.getTempC (Probe04);
delay(500);
//next line is Fahrenheit conversion
Temp1=Temp11.8+32; // comment this line out to get celcius
Temp2=Temp21.8+32; // comment this line out to get celcius
Temp3=Temp31.8+32; // comment this line out to get celcius
Temp4=Temp41.8+32; // comment this line out to get celcius
delay(500);
Serial.print("extratemp1=");
Serial.print(Temp1);
Serial.print(",");
Serial.print("extratemp2=");
Serial.print(Temp2);
Serial.print(",");
Serial.print("extratemp3=");
Serial.print(Temp3);
Serial.print(",");
Serial.print("extratemp4=");
Serial.print(Temp4);
Serial.println("#");
delay(3000);
}//--(end main loop )---
/-----( Declare User-written Functions )-----/
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensorsA.getTempC(deviceAddress);
if (tempC == -127.00)
{
Serial.print("Error getting temperature");
}
else
{
//Serial.print(tempC,1);
//Serial.print(" C ");
//Serial.print(" F ");
Serial.print(DallasTemperature::toFahrenheit(tempC));
}
}// End printTemperature
//( THE END )**