-
Notifications
You must be signed in to change notification settings - Fork 487
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
getDeviceCount() returns 0 #257
Comments
My Solution to the Problem was to rename getDeviceCount(void) to getValidDeviceCount(void) and implement a new getDeviceCount(void) . I've done this simply for tracing down the original problem to the while (_wire->search(deviceAddress)) in begin(void) function. For some reason it simply doesn't work in the begin(void), but outside of it it's OK.
|
I've been having trouble with getDS18count() on NodeMCU returning 0 when called in setup(). I have found five ways to make getDS18count() return the correct number instead of zero (see commented-out lines in code snippet below):
Hopefully this information will provide some clues, as I'm puzzled about what kind of issue could have such a variety of workarounds, and especially perplexed how changing code after the call to getDS18count() could affect its result! I'm also surprised that changing the optimisation level helps: I looked at the assembly output and the main difference seemed to be whether the n_devices variable was written back to memory or held in a register between the call to getDS18count() and the printf(). // Change to ("O0") [that's a capital letter O followed by zero] to fix getDS18Count()
#pragma GCC optimize ("Os")
void setup() {
Serial.begin(74880); // Default for NodeMCU
delay(100);
lcd.init();
lcd.clear(); // Sets cursor to 0, 0
lcd.backlight(); // Make sure backlight is on
lcd.print("Starting");
sensors.begin(); // Re-enumerates the bus.
// sensors.begin(); // Fixes getDS18Count()
uint8_t n_devices = sensors.getDS18Count();
// delay(0); // Fixes getDS18Count()
lcd.setCursor(0, 1);
lcd.printf("%hhu/%d devs", n_devices, MAX_SENSORS);
// Serial.printf("%hhu/%d devs", n_devices, MAX_SENSORS); // Fixes getDS18Count()
delay(1000);
}
#pragma GCC optimize ("Os") |
Thanks chaps. Let me investigate |
This is most bizzar... getDS18count() is basicly a return(value) and it needs a call for delay() to work? (Not tested my self) |
My friend believes it could be a memory consistency issue. Hopefully he doesn't mind me sharing this email:
I thought it was a race condition but I don't have an IC to test at the moment. PR #259 could be our answer but could someone test it out for us? |
Hi Miles,
If there is any way I can help (eg send you the complete code I am using
with my ESP8266 / NodeMCU 1.0), please let me know.
Kind regards,
Tim
…On Sat, 4 Jan 2025 at 12:10, Miles Burton ***@***.***> wrote:
Thanks chaps. Let me investigate
—
Reply to this email directly, view it on GitHub
<#257 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABE6CIHPNCL2CJWMABRUV432I7FS5AVCNFSM6AAAAABSWQ7AYKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNZRGI3DSNZXGA>
.
You are receiving this because you commented.Message ID:
<milesburton/Arduino-Temperature-Control-Library/issues/257/2571269770@
github.com>
|
Hey Tim, that's very kind of you. Let me get PR #259 passing and if you could run that on your device and give it a sanity check that'd be awesome. |
Sometimes getDeviceCount() method returns 0 sensors.
If I use the method by parsdc, it gets correct count.
The text was updated successfully, but these errors were encountered: