We publish and print to demonstrate what's happening.
Your solution is in the code, I only had it outputting the same way you output the data., Perhaps you didn't see your way over the goal line.
The key is to get the function to return a double
, which is a trivial excercise.
Here is an example (sorry it prints, but you can edit that out if you want) that uses an array of sensors, passed to a function, that returns a double that is stored into an array for future evaluation/analysis/etc.
I obviously cannot test it, the ID's are from your code.
#include "ds18x20.h"
#include "onewire.h"
#include "math.h"
uint8_t tempSensor[][8] = { // Array of sensor ID's
{0x28, 0xFF, 0x0D, 0x4C, 0x05, 0x16, 0x03, 0xC7},
{0x28, 0xFF, 0x25, 0x1A, 0x01, 0x16, 0x04, 0xCD},
{0x28, 0xFF, 0x89, 0x19, 0x01, 0x16, 0x04, 0x57},
{0x28, 0xFF, 0x21, 0x9F, 0x61, 0x15, 0x03, 0xF9},
{0x28, 0xFF, 0x16, 0x6B, 0x00, 0x16, 0x03, 0x08},
{0x28, 0xFF, 0x90, 0xA2, 0x00, 0x16, 0x04, 0x76},
{0x10, 0xE9, 0x6B, 0x0A, 0x03, 0x08, 0x00, 0xAC},
{0x10, 0x44, 0x4E, 0x0B, 0x03, 0x08, 0x00, 0x1F}
};
double thermo[8]; // array of floating point numbers
void setup()
{
Serial.begin(9600);
}
void loop()
{
for (int i = 0; i < 8; i++)
{
double t = (getTemp(2, tempSensor[i], i));
if(isfinite(t))
{
thermo[i] = t;
}
}
for (int i = 0; i < 8; i++)
{
Serial.print("Temperature");
Serial.print(i);
Serial.print(" = ");
Serial.println((isnan(thermo[i])? "NaN" : String(thermo[i])));
}
delay(5000);
}
double getTemp(int pulsePin, uint8_t sensor[], int num)
{
ow_setPin(pulsePin);
int res;
uint8_t subzero, cel, cel_frac_bits;
ATOMIC_BLOCK()
{
DS18X20_start_meas( DS18X20_POWER_EXTERN, NULL ); //(Was DS18X20_POWER_PARASITE ) Asks all DS18x20 devices to start temperature measurement, takes up to 750ms at max resolution
}
delay(750);
ATOMIC_BLOCK()
{
res = DS18X20_read_meas(sensor, &subzero, &cel, &cel_frac_bits);
}
if(res == DS18X20_OK)
{
char msg[100];
int frac = cel_frac_bits * DS18X20_FRACCONV;
sprintf(msg, "%c%d.%04d", (subzero) ? "-" : "", cel, frac);
return atof(msg);
}
else
{
return sqrt(-1); //NaN
}
}
I don't use a lot of work with double
data types, so maybe others out there can comment on recognizing/screening for a bad sensor read.
have fun with it!