Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only updates the supplied deviceAddress if a valid index is specified #251

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mitchyboy9
Copy link

This change addresses #229. I ran into the same problem described in that issue while using the Multiple.ino example.

I only had 1 sensor connected, but was confusingly getting temperature readings for both the sensors declared in the example. I had received the "Unable to find address for Device 1" output from the Setup() method but the code used the address for my single sensor as the address for the nonexistent sensor.

Output from Multiple.ino example (with only 1 DS18B20 connected) before this change. Notice that device address 2861640AF24BE40D is used twice:

Dallas Temperature IC Control Library Demo
Locating devices...Found 1 devices.
Parasite power is: OFF
Unable to find address for Device 1
Device 0 Address: 2861640AF24BE40D
Device 1 Address: 2861640AF24BE40D
Device 0 Resolution: 12
Device 1 Resolution: 12
Requesting temperatures...DONE
Device Address: 2861640AF24BE40D Temp C: 23.50 Temp F: 74.30
Device Address: 2861640AF24BE40D Temp C: 23.50 Temp F: 74.30

Output from Multiple.ino example (with only 1 DS18B20 connected) after this change. The nonexistent sensor is now given the address 0000000000000000:

> Dallas Temperature IC Control Library Demo
> Locating devices...Found 1 devices.
> Parasite power is: OFF
> Unable to find address for Device 1
> Device 0 Address: 2861640AF24BE40D
> Device 1 Address: 0000000000000000
> Device 0 Resolution: 12
> Device 1 Resolution: 0
> Requesting temperatures...DONE
> Device Address: 2861640AF24BE40D Temp C: 23.56 Temp F: 74.41
> Device Address: 0000000000000000 Error: Could not read temperature data

@RobTillaart
Copy link
Contributor

RobTillaart commented May 19, 2024

Thanks,
Not reviewed it in depth.
One question pops up.
what happens if devices is not set before call to validAddress()? Can that happen?

@mitchyboy9
Copy link
Author

This is a good concern, but I think we're fine because devices is initialised to zero when setOneWire is called, which is called by the constructor.

I have only implemented this for getTempC because that's the method I use in project (i.e. not getTempF).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants