I don't want to hard code the Dallas Temperature Sensor addresses as I have seen and done so far, like this global declaration does:
DeviceAddress TankThermometer = { 0x28, 0x2A, 0x3A, 0x59, 0x04, 0x00, 0x00, 0x8B };
I would like to assign them inside the program (a subroutine called assign sensor addresses), but thisTankThermometer = { 0x28, 0x2A, 0x3A, 0x59, 0x04, 0x00, 0x00, 0x8B }; isn't allowed and this
TankThermometer[0] = 0x28;
TankThermometer[1] = 0x2A;
TankThermometer[2] = 0x3A;
TankThermometer[3] = 0x59;
TankThermometer[4] = 0x04;
TankThermometer[5] = 0x00;
TankThermometer[6] = 0x00;
TankThermometer[7] = 0x8B;
isn't very pretty. (You must admit the global declaration looks neater, and neatness does count in programming)
This is just a stop gap to move the assignment. Eventually the sensors will be installed one-by-one, scanned, assigned to the correct location via the LCD/pushbutton menu, and the association and device address stored in the onboard EEPROM. For the time being, I want to install the correct subroutine name with dummy programming to make the control aspect work until I have time to the assignment and EEPROM parts of the program.
Is there a neat way to do the assignment inside the program? Or am I stuck with the one-to-one array assignment above?
Hi,
I'm pretty sure there was discussion of someone who had set up a system with a menu item that READ a DS18B20 address on a separate pin from the main application 1-wire system, and saved that address in EEPROM at the desired index.
Anyone have a pointer??
...that would also allow easy field replacement...
I think I know how to read the address and store to the EEPROM. Or at least I have three examples I hope to combine together to accomplish that. My focus is on the stop gap of assigning the addresses within the program.
As far as I know, you can only use a brace-enclosed initializer list to initialize a variable at compile time. No can do dynamically at run time.
This is not valid C/C++ (you need a type specifier):
TankThermometer = { 0x28, 0x2A, 0x3A, 0x59, 0x04, 0x00, 0x00, 0x8B };
This, for example, is allowed inside a function. The definition need not be global.
char TankThermometer[] = { 0x28, 0x2A, 0x3A, 0x59, 0x04, 0x00, 0x00, 0x8B };
This is not valid C/C++ (you need a type specifier):
TankThermometer = { 0x28, 0x2A, 0x3A, 0x59, 0x04, 0x00, 0x00, 0x8B };
OP's first post had:
DeviceAddress TankThermometer = { 0x28, 0x2A, 0x3A, 0x59, 0x04, 0x00, 0x00, 0x8B };
DeviceAddress is declared in DallasTemperature.h:
typedef uint8_t DeviceAddress[8];
This, for example, is allowed inside a function. The definition need not be global.
char TankThermometer[] = { 0x28, 0x2A, 0x3A, 0x59, 0x04, 0x00, 0x00, 0x8B };
Just so it's understood, even inside a function, this is an initialization, not an assignment.
Instead of:
TankThermometer[0] = 0x28;
TankThermometer[1] = 0x2A;
TankThermometer[2] = 0x3A;
TankThermometer[3] = 0x59;
TankThermometer[4] = 0x04;
TankThermometer[5] = 0x00;
TankThermometer[6] = 0x00;
TankThermometer[7] = 0x8B;
You could use:
DeviceAddress newAddress = { 0x28, 0x2A, 0x3A, 0x59, 0x04, 0x00, 0x00, 0x8B };
for (int i = 0; i < 8; i++)
TankThermometer[i] = newAddress[i];