1-wire array

Hello All,

I am after some general programming guidance, I have a need to measure a variable number of 1-wire temperature sensors. The sensors won't be hot-swapped etc but one project might need 3 sensors whilst another project might need 8 sensors.

I had a look at the libraries that exist, and whilst a number do exist for the 1-wire they tend to be more about scanning the device addresses, or using a fixed address to report a temperature.

I would like to output the temperature and the address as a delimited string, so thought I could loop through the address finder, then with the address find the respective temperature for that address.

What I am a bit lost about is how to report this, for simplicity on the PC side I would like to do a string something like address;temperature,address;temperature,address;temperature and process that on the PC but if I use the address finder approach it would be more like

address;temperature
address;temperature

which I would prefer not to do if possible, is the easiest way to store the address;temperature in a string and then just print the string?

e.g.

String stringOne = "";

// loop through 1-wire here
stringOne += Address;
stringOne += ";";
stringOne += temperature;
stringOne += ",";
//loop to next

Is there a better way to achieve this, am I reinventing the wheel or are they any major issues anyone can foresee?

Conside the above pseudocode as well, I have just done it off the top of my head.

Many Thanks!

What I am a bit lost about is how to report this, for simplicity on the PC side I would like to do a string something like address;temperature,address;temperature,address;temperature and process that on the PC but if I use the address finder approach it would be more like

address;temperature
address;temperature

One approach appears to use print() calls exclusively, while the other mixes print() and println(). I can't imagine why you would use println() except after sending the last piece of data.

Is there a better way to achieve this

Of course there is. Serial data, once it gets in the buffer, is nothing more than a bunch of bytes. Whether the data was put there using one messy process that needs to unpack the data from a String instance or several calls to print() for discrete variables makes NO difference to the other end. So, quit pissing away resources on the String class.

Thanks for the suggestions :slight_smile: