-
Notifications
You must be signed in to change notification settings - Fork 20
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
Maximum number of OneWireNg_CurrentPlatform objects? #71
Comments
Hi @Ing-Dom, yes for RP2040 there is a limit for number of 1-wire masters with PIO driver (the default driver for the platform). Please take a look here for details: arduino/ArduinoCore-mbed#316 (comment) |
ok, thank you for your reply. OneWireNg/src/OneWireNg_Config.h Line 332 in c4d21d0
you stated
Do I understand correctly: Anyway, I need to poll 16 DS18B20, connected to 16 different GPIO. |
Yes, you need to create 4 OneWireNg_PicoRP2040PIO objects 2 of them with 0 as 3rd arg for the class constructor and 2 with 1. See
What I don't understand it's why you need 16 masters to handle 16 sensors, instead having them all connected to single wire controlled by a single master. |
because my hardware main purpose was to be able to connect up to 8 SHT3x (or other I2C Sensors) which only can be used once on one Bus. Is it possible to re-assign a different pin to a specific driver in programm flow? |
Yes you may destroy the driver na calling it's destructor and recreating it by calling new in-place constructor with different GPIO. EDIT: I just realized that there is no destructor implementation for the PIO driver, so it won't help you. I need to investigate the PIO API if it supports freeing the loaded PIO program to properly implement the destructor. |
I just wanted to answer you, that that would have been my first guess also, but there is no destructor :) I'll check the bitbang drivers in the meantime and thanks for your help ! Really appreciate it. |
I don't recommend the BB driver for RP2040, the PIO one is much better. I'm gonna do some fixes for the PIO driver soon and give you for tests. |
Take a look at branch I've also updated the README to contain information how to create many PIO drivers controlling different buses. I hope that will give some insight for more advanced library users. |
ohhhh :) that was fast, thanks, Ill give it a try immidiatelly |
ok - this way it does not anymore crash. I continue testing sensor readings..
|
Not exactly, if you are using in-place driver creation: Placeholder<OneWireNg_PicoRP2040PIO> ow;
new (&ow) OneWireNg_PicoRP2040PIO(pin0, false);
DSTherm drv(ow);
// ...
// virtually calls destructor in-place w/o actual memory deallocation
(*ow).~OneWireNg(); for classic allocation/deallocation case: OneWireNg *ow = new OneWireNg_PicoRP2040PIO(pin0, false);
DSTherm drv(*ow);
// ...
// delete the object
delete ow; EDIT: If you create |
hmm there seems to be some problem.
the first two sensor - regardless which pin - work. |
Thanks, I will look at this later today... |
I've just tested the fix on my setup (RP2040, PicoSDK lib) and works as expected. Code as follows: static void printScratchpad(const DSTherm::Scratchpad& scrpd)
{
const uint8_t *scrpd_raw = scrpd.getRaw();
printf(" Scratchpad:");
for (size_t i = 0; i < DSTherm::Scratchpad::LENGTH; i++)
printf("%c%02x", (!i ? ' ' : ':'), scrpd_raw[i]);
printf("; Th:%d; Tl:%d; Resolution:%d",
scrpd.getTh(), scrpd.getTl(),
9 + (int)(scrpd.getResolution() - DSTherm::RES_9_BIT));
long temp = scrpd.getTemp2();
printf("; Temp:");
if (temp < 0) {
temp = -temp;
printf("-");
}
printf("%d.%04d C\n", (int)temp / 16, (10000 * ((int)temp % 16)) / 16);
}
int main()
{
stdio_init_all();
Placeholder<DSTherm::Scratchpad> scrpd;
for(int i = 0;; i++) {
int pin = (i % 16);
printf("[PIN %d]\n", pin);
auto ow = OneWireNg_CurrentPlatform(pin, false);
DSTherm drv(ow);
drv.convertTempAll(DSTherm::MAX_CONV_TIME, false);
for (const auto& id: ow) {
OneWireNg::ErrorCode ec = drv.readScratchpad(id, scrpd);
if (ec == OneWireNg::EC_SUCCESS) {
printScratchpad(scrpd);
} else {
printf(" ERROR: %d\n", ec);
}
}
}
return 0;
} so, I'm probing GPIOs 0-15 in the main loop against connected sensors printing readouts on the console. Try this code on your setup. |
I had to modify you code a little bit to run within my arduino-pico environment.
it prints;
so, it seems to work if you do it the right way. I'll try again to integrate into my setup.. |
Wow, what timing, we have a bug related to destroying and reinitialising the pio driver (user adds/removes DS18b20 pin device and we initialise/delete the bus - works 1st and 2nd time and crashes 3rd), I was going to suggest implementing the destructor, but you did yesterday! Looks like I missed turning off the outputs (instead just unclaiming them). I'll retest with your PR tomorrow morning. |
@pstolarz looks good, thank you! Retested this PR. A release shouldn't be necessary as we git clone this repo. |
Hi!
Thanks for that great lib.
I recently ran into a problem.. I think when I create more then 2 OneWireNg_CurrentPlatform objects
new (&m_ow) OneWireNg_CurrentPlatform(pin0, false);
my programm chrashes. 2 are fine.
Is this a limitation?
due to the wiring of my project (star topology) I would ne up to 16..
Running on RP2040 with arduino-pico core (within a PlattformIO project..)
for reference
https://github.com/OpenKNX/OFM-THPSensorModule/blob/v1/src/HWSensorchannel_DS18B20.cpp
The text was updated successfully, but these errors were encountered: