I was wondering what is the best way to program my arduino to get information from let's say 8 DS18B20 sensors connected in parasite power mode?
Is it better to collect their ROM address and loop through an array of the addresses?
Or maybe to call by index? but then I need to understand how the indexing works.... is it working as the first is the lowest? (trying to make sure I understand everything).
I saw few functions on the Dallas libraries and I'm not sure what's the best one to call...
"requestTemperatures(void)" - How can I understand what is the temp at what sensor? is it collecting the temps by indexing them from the first to the last or by other method that I can't count on?
"requestTemperaturesByAddress(const uint8_t*)" - but then I have to iterate through them all.
"requestTemperaturesByIndex(uint8_t)" - and then I have to understand about the indexing and then iterate through them as well and assign the correct index to the correct place.
Please help me understand what is better and faster for the program.
Well, here is one way: You can collect the addresses with an address sniffer programme one at a time. You write the address on a sticky label using a pen, and fix that to the sensor cable. You also write where it is to go. You then place the sensor where you want, and are left in no doubt which is which. Works every time but, to make extra sure, you also have a note stored on your computer with each sensor address and its location, just in case the cockatoos get in and eat the labels. An additional option is to code the cable with different coloured heatshrink. I just use that for groups in different locations.
Using this method, you are able to assign sensible names like "input" against the addresses, although I don't think it is really necessary.
There may be a way of doing this without pencil and paper. Maybe the index method does this, but it is beyond my comprehension.
I bet you don't have a good reason for using parasite power.
I probably don't have a good reason but I do want to try it to understand it and I think it's a better way for me.... but we won't argue on that.
About the way to distinguish between the sensors I liked what you offered and maybe I'll use it so thank you... but I was wondering if there is a way to have a clean code of this without calling all the time to get the index and whatnot....
In the Dallas library there is a function "getDeviceCount" which returns the number of onewire sensors on the bus.
If you just want to read their temperatures but don't care where they are you can use "getTempCByIndex" or "getTempFByIndex" for each of the devices.
Otherwise you have to determine their addresses and label them so that you know where you put each one. You then have to make an array of device addresses so that you can use requestTemperaturesByAddress to get each one in turn after you have called requestTemperatures. (Or you could put the array in ROM address order since you now know which address matches which sensor and use ByIndex).
Don't use parasite power for multiple sensors, you can only do one conversion at a time on the bus
with parasite power (strong pullup must be active for the entire conversion). Parasite power is much
fussier and more likely to bring grief.
With 8 sensors you would want to convert in parallel, initiating conversions on all of them, waiting 0.75s
and then collecting the results from all of them.
[ Well, to be less dogmatic about it, I strongly suggest getting it working first in normal mode, and
then start experimenting with parasite power ]