I have been struggling with this and am at a total loss as to why its not working. Here is my program:
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is Arduino pin A0
#define ONE_WIRE_BUS A0
// Setup a oneWire instance
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Define array for holding all the sensors addresses and load addresses.
//======================================================================
DeviceAddress SensorAddr [13] =
{
( 0x28, 0xAA, 0x30, 0x41, 0x38, 0x14, 0x01, 0x14 ), // Sensor 1
( 0x28, 0xAA, 0x24, 0x31, 0x38, 0x14, 0x01, 0xDF ), // Sensor 2
( 0x28, 0xAA, 0xE4, 0x30, 0x38, 0x14, 0x01, 0x72 ), // Sensor 3
( 0x28, 0xAA, 0xD4, 0xC2, 0x38, 0x14, 0x01, 0x80 ), // Sensor 4
( 0x28, 0xAA, 0x6C, 0xDA, 0x38, 0x14, 0x01, 0xD5 ), // Sensor 5
( 0x28, 0xAA, 0xCA, 0x39, 0x38, 0x14, 0x01, 0xBB ), // Sensor 6
( 0x28, 0xAA, 0x75, 0x28, 0x38, 0x14, 0x01, 0x2C ), // Sensor 7
( 0x28, 0xAA, 0xFB, 0xB2, 0x38, 0x14, 0x01, 0xBF ), // Sensor 8
( 0x28, 0xAA, 0x0F, 0x3A, 0x38, 0x14, 0x01, 0xC3 ), // Sensor 9
( 0x28, 0xAA, 0x6F, 0x26, 0x38, 0x14, 0x01, 0xF8 ), // Sensor 10
( 0x28, 0xFF, 0x64, 0x1E, 0x1E, 0x6A, 0x74, 0xF1 ), // Sensor 11
( 0x28, 0xFF, 0x64, 0x1E, 0x1E, 0x7D, 0x29, 0x55 ), // Sensor 12
( 0x28, 0xFF, 0x64, 0x1E, 0x1E, 0x73, 0xAC, 0x3A ) // Sensor 13
};
void setup(void)
{
Serial.begin(9600);
sensors.begin();
//Test first Sensor Address - This works
//=======================================
byte Sensor1Test[8] = { 0x28, 0xAA, 0x30, 0x41, 0x38, 0x14, 0x01, 0x14};
Serial.print("Test Sensor 1: ");
float tempTest = sensors.getTempC( Sensor1Test );
Serial.print(tempTest, 2);
Serial.print("\xC2\xB0"); // shows degree symbol
Serial.print("C");
Serial.println();
}
void loop(void)
// Get all temperatures - This does not work??
//============================================
{
sensors.requestTemperatures();
for (int S =0; S<13; S++)
{
Serial.print("Sensor # "); Serial.print(S+1); Serial.print(": ");
float tempC = sensors.getTempC(SensorAddr [S]);
Serial.print(tempC,2);
Serial.print("\xC2\xB0"); // shows degree symbol
Serial.print("C");
Serial.println();
delay(1000);
}
Serial.println();
}
jsotola
1,5342 gold badges12 silver badges20 bronze badges
asked Nov 18, 2022 at 18:44
-
1please, no pictures of text ... delete the picture and add the textjsotola– jsotola2022年11月18日 19:10:43 +00:00Commented Nov 18, 2022 at 19:10
-
Go through the tutorial at lastminuteengineers.com/multiple-ds18b20-arduino-tutorial. Try using their code for reading multiple sensors by address (or index, but you are trying to read by address). Try doing the read loop the way they are doing it and using uint8_t arrays - it can't hurt. Let us know how that goes please.DrG– DrG2022年11月18日 19:47:07 +00:00Commented Nov 18, 2022 at 19:47
-
1that is not how this site works ... please post the updated code in an answer and explain how the problem was solved ... rolled back your editjsotola– jsotola2022年11月18日 23:06:09 +00:00Commented Nov 18, 2022 at 23:06
1 Answer 1
The DeviceAddress
internally is defined as an array of uint8_t
(see definition:
typedef uint8_t DeviceAddress[8];
That is, each address is an array itself.
DeviceAddress Sensor1 = { 0x28, 0xAA, 0x30, 0x41, 0x38, 0x14, 0x01, 0x14 };
So if you have 13 DeviceAdrress
, you are dealing with a two-dimension array, and you need to declare it as:
#define NUMBER_OF_SENSORS 13
DeviceAddress SensorAddr [NUMBER_OF_SENSORS] = {
{ 0x28, 0xAA, 0x30, 0x41, 0x38, 0x14, 0x01, 0x14 }, // Sensor 1
{ 0x28, 0xAA, 0x24, 0x31, 0x38, 0x14, 0x01, 0xDF }, // Sensor 2
{ 0x28, 0xAA, 0xE4, 0x30, 0x38, 0x14, 0x01, 0x72 }, // Sensor 3
{ 0x28, 0xAA, 0xD4, 0xC2, 0x38, 0x14, 0x01, 0x80 }, // Sensor 4
{ 0x28, 0xAA, 0x6C, 0xDA, 0x38, 0x14, 0x01, 0xD5 }, // Sensor 5
{ 0x28, 0xAA, 0xCA, 0x39, 0x38, 0x14, 0x01, 0xBB }, // Sensor 6
{ 0x28, 0xAA, 0x75, 0x28, 0x38, 0x14, 0x01, 0x2C }, // Sensor 7
{ 0x28, 0xAA, 0xFB, 0xB2, 0x38, 0x14, 0x01, 0xBF }, // Sensor 8
{ 0x28, 0xAA, 0x0F, 0x3A, 0x38, 0x14, 0x01, 0xC3 }, // Sensor 9
{ 0x28, 0xAA, 0x6F, 0x26, 0x38, 0x14, 0x01, 0xF8 }, // Sensor 10
{ 0x28, 0xFF, 0x64, 0x1E, 0x1E, 0x6A, 0x74, 0xF1 }, // Sensor 11
{ 0x28, 0xFF, 0x64, 0x1E, 0x1E, 0x7D, 0x29, 0x55 }, // Sensor 12
{ 0x28, 0xFF, 0x64, 0x1E, 0x1E, 0x73, 0xAC, 0x3A } // Sensor 13
};
for (int s=0; s<NUMBER_OF_SENSORS; S++) {
float tempC = sensors.getTempC(SensorAddr[s]);
}
answered Nov 19, 2022 at 2:14