Can I create a OneWire object serveral times?

Hello

I have a very big doubt about my DS18B20 library.

I started to code my DS18B20 sensor following this tutorial
As you can see it createa OneWire object before the setup()


OneWire ds(BROCHE_ONEWIRE);

I created my own DS18B20 library for 4 sensors, but I thinks there are errors.
Considering that


pin_read1=15 (A1)
pin_read1=16 (A2)
pin_read1=17 (A3)
pin_read1=18 (A4)

Here I define the pin mode and I scan the bus

in the scan function, I declare an object at line 98. But that doent work?!
I can use the same ds for each pin???

Additionaly, when I read the value, I do the same at line 163 .

Are you agree, it's wrong?

I discovered that issue because for another application, I have the DS18B20 sensor connected to A5, then my library does notwork for a 5th sensors.

Then I need to rethink to be able to have (and use) 4 DS18B20 on the same board and to be free to have anther DS18B20 sensors connected to another pin, as it's the case for my second application. How would you modify the constructor?
Or may be I should define the pin mode in the ino file and not in the library.

Aïe, I think I have to perfect that, isn't?

Cheers
Pierrot

PS: I know we can have all OneWire sensors on the same bus, but I need to have separete.
The reason is, I want to have my board to be "multifunction"

My board has 4 connectors
Connector 1 : GND; +; A1
Connector 2 : GND; +; A2
Connector 3 : GND; +; A3
Connector 4 : GND; +; A4

In my first application, I need 4 DS18B20 (which could be on the same bus). BUT I also want to use the same board for another application which does not need DS18B20 sensors, but need the analog pin for another purpose. That the reason why I did not want to have the analog pin of the connectors linked.

But now my worries is about my library and the fact to have serveral OneWire ds(readPin); which does not sound good, in my point of view, but I am not sure...

The Arduino-Temperature-Control-Library is quite capable of handling multiple sensors per OneWire bus and multiple OneWire bus instances. So, unless you're doing this as a learning exercise, you're likely reinventing something that has already been invented.

Probably not. Best to use a separate OneWire instance for each pin:

OneWire ds1(A1);
OneWire ds2(A2);
OneWire ds3(A3);
OneWire ds4(A4);

or an array of OneWire instances:
OneWire ds[] = {A1, A2, A3, A4};

Hello,
Yes I though about that and I will try later when I will on Windows PC
OneWire ds[] = {A1, A2, A3, A4};

my_array[0]=pin1; //A1 powered by p1 (PCF7584)
my_array[1]=pin2; //A2 powered by p2 (PCF7584)
my_array[2]=pin3; //A3 powered by p3 (PCF7584)
my_array[3]=pin4; //A4 powered by p4 (PCF7584)

OneWire ds[] = my_array;

but I also have a way to associate the pin which power the sensors.
may by that would be solution as lon as the index match to the first array

my_power[0]=1;
my_power[1]=2;
my_power[2]=3;
my_power[3]=4;

May I ask you one thing more.

I do not understand wich constructor, this calls

is this one (L52)or this one (L59)

Yes, it's creating an array of DallasTemperature objects using the default constructor:

DallasTemperature();

Thank you

But this [oneWireCount] confuse me.
Where this parameter is used?

I am not with my pc but i will in a couple pf hours

Find an online tutorial that explains arrays.

It is used in the example code that you linked.

Dear gfvalvo
pls excuse me for that question. I see now

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.