logo elektroda
logo elektroda
X
logo elektroda

Extending DS18(B)20 driver - multiple GPIOs and multiple sensors per GPIO

max4elektroda 5928 108

TL;DR LABEL_AI_GENERATED

  • OpenBeken’s DS1820 full driver extends the existing DS18(B)20 code to support multiple GPIO buses and multiple sensors per bus.
  • It scans all DS1820_IO pins, discovers sensor addresses with the OneWire search algorithm, and stores per-sensor name, GPIO, channel, and last-read metadata.
  • Configuration uses commands like startDriver DS1820, DS18B20_setsensor, DS1820_SetResolution, and DS18B20_scansensors; the example backlog manages 10 sensors.
  • A simple GUI generates backlog commands so sensor names and channels persist after reboot, and the main page shows per-sensor updates.
  • The full driver adds about 6k on W800, and many clone DS18B20s ignore resolution settings and stay at 12-bit.
AI summary based on the discussion. May contain errors.
ADVERTISEMENT
Listen:
  • #91 21622509
    max4elektroda
    Level 24  
    Posts: 758
    Help: 49
    Rate: 189
    Your logs/tests look good, so why not!
    Thanks for testing again

    Added after 14 [minutes]:

    Compiled this time ;-)
  • ADVERTISEMENT
  • Repeated DS1820 readings show stable 12-bit conversion

    #92 21622568
    divadiow
    Level 38  
    Posts: 5220
    Help: 449
    Rate: 918
    OpenBK7252 web interface showing DS1820 temperature sensor and system stats

    Code: Text
    Log in, to see the code
    Attachments:
    • ds1820_bk7252u68_p24_1727_merge_243359742dca.zip (2.09 KB) You must be logged in to download this attachment.
  • #94 21622586
    max4elektroda
    Level 24  
    Posts: 758
    Help: 49
    Rate: 189
    Wow, looks quite good, only 20us is a bit short with 16us in real:

    500 479
    200 193
    100 97
    50 49
    20 16
    10 9
    6 6
    4 4

    Thank you so much!
  • ADVERTISEMENT
  • #95 21622588
    divadiow
    Level 38  
    Posts: 5220
    Help: 449
    Rate: 918
    no, thank you!

    good stuff
  • #96 21622795
    max4elektroda
    Level 24  
    Posts: 758
    Help: 49
    Rate: 189
    I almost forgot: is PowerSave possible for BK7525?
    Then we should try if we need adjustments here, too.
    And the same for BK7238. Did I miss something about PowerSave? Should it work?
  • #97 21623607
    divadiow
    Level 38  
    Posts: 5220
    Help: 449
    Rate: 918
    max4elektroda wrote:
    I almost forgot: is PowerSave possible for BK7525?


    appears to. powersave 0 = 0.11A. Powersave 1 = ~0.2A

    these higher-latency pings are powersave 1

    Ping results to 192.168.137.157 with times ranging from 1ms to 116ms
  • ADVERTISEMENT
  • #98 21623698
    max4elektroda
    Level 24  
    Posts: 758
    Help: 49
    Rate: 189
    Sorry, bad question: will powersave change timing, if it's available?

    Added after 6 [minutes]:

    Do you recall if/how PowerSave works for BK7238?
    I didn't get it to work but probably only missed how it works there...
  • #99 21623703
    divadiow
    Level 38  
    Posts: 5220
    Help: 449
    Rate: 918
    max4elektroda wrote:
    Sorry, bad question: will powersave change timing, if it's available?

    will check

    max4elektroda wrote:
    Do you recall if/how PowerSave works for BK7238?

    not sure it does! https://www.elektroda.com/rtvforum/topic4127149.html

    unless fixed since. can check

    Added after 41 [minutes]:

    good timing @insmod

    Code: Text
    Log in, to see the code


    https://github.com/openshwprojects/OpenBK7231T_App/pull/1745
  • BK7238 powersave adjustment added for DS18B20 driver

    #100 21624160
    max4elektroda
    Level 24  
    Posts: 758
    Help: 49
    Rate: 189
    BK7238 will need some powersave-adjustment, added the code.
    As soon as @insmod s PR fixing powersave is merged, it should work after syncing this PR


    Logic analyzer screenshot of signal on pin D7 with timing and pulse duration measurements
    Screenshot from logic analyzer showing D7 line signal timings and pulse durations

    I saw some timeouts and a few CRCs, but generally its working o.k. with powersave:
    
    Info:SENSOR:DS1820[9] - Temp=25.00
    Info:MAIN:Time 667, idle 61945/s, free 115104, MQTT 0(42), bWifi 1, secondsWithNoPing 601, socks 2/24 POWERSAVE
    Info:MAIN:Time 668, idle 64117/s, free 113928, MQTT 0(42), bWifi 1, secondsWithNoPing 602, socks 2/24 POWERSAVE
    Info:MAIN:Time 669, idle 57772/s, free 115088, MQTT 0(42), bWifi 1, secondsWithNoPing 603, socks 3/24 POWERSAVE
    Info:SENSOR:DHT start, pin is 7
    Info:MAIN:Time 670, idle 55622/s, free 123992, MQTT 0(42), bWifi 1, secondsWithNoPing 604, socks 2/24 POWERSAVE
    Info:SENSOR:DS1820[9] - Starting conversion
    Info:MAIN:Time 671, idle 61380/s, free 115688, MQTT 0(42), bWifi 1, secondsWithNoPing 605, socks 2/24 POWERSAVE
    Info:SENSOR:DS1820[9] - Temp=25.00
    Info:MAIN:Time 672, idle 64249/s, free 123408, MQTT 0(42), bWifi 1, secondsWithNoPing 606, socks 3/24 POWERSAVE
    Info:SENSOR:DHT start, pin is 7
    Info:MAIN:Time 673, idle 49489/s, free 115688, MQTT 0(42), bWifi 1, secondsWithNoPing 607, socks 2/24 POWERSAVE
    Info:MAIN:Time 674, idle 61657/s, free 115688, MQTT 0(42), bWifi 1, secondsWithNoPing 608, socks 2/24 POWERSAVE
    Info:MAIN:Time 675, idle 27978/s, free 115688, MQTT 0(42), bWifi 1, secondsWithNoPing 609, socks 2/24 POWERSAVE
    Info:SENSOR:DHT start, pin is 7
    Info:SENSOR:DHT timeout waiting for start signal high pulse.
    Info:SENSOR:DS1820[9] - Starting conversion
    Info:MAIN:Time 676, idle 51902/s, free 114016, MQTT 0(42), bWifi 1, secondsWithNoPing 610, socks 2/24 POWERSAVE
    Info:SENSOR:DS1820[9] - Temp=25.00
    Info:MAIN:Time 677, idle 68400/s, free 115600, MQTT 0(42), bWifi 1, secondsWithNoPing 611, socks 2/24 POWERSAVE
    Info:MAIN:Time 678, idle 60156/s, free 115584, MQTT 0(42), bWifi 1, secondsWithNoPing 612, socks 2/24 POWERSAVE
    Info:SENSOR:DHT start, pin is 7
    Info:MAIN:Time 679, idle 59934/s, free 115600, MQTT 0(42), bWifi 1, secondsWithNoPing 613, socks 2/24 POWERSAVE
    Info:MAIN:Time 680, idle 69868/s, free 115688, MQTT 0(42), bWifi 1, secondsWithNoPing 614, socks 2/24 POWERSAVE
    Info:SENSOR:DS1820[9] - Starting conversion
    Info:MAIN:Time 681, idle 62448/s, free 115688, MQTT 0(43), bWifi 1, secondsWithNoPing 615, socks 2/24 POWERSAVE
    Info:SENSOR:DHT start, pin is 7
    Info:SENSOR:DS1820[9] - Temp=25.00
    Info:MAIN:Time 682, idle 64128/s, free 115080, MQTT 0(43), bWifi 1, secondsWithNoPing 616, socks 2/24 POWERSAVE
    Info:MAIN:Time 683, idle 60101/s, free 114056, MQTT 0(43), bWifi 1, secondsWithNoPing 617, socks 2/24 POWERSAVE
    Info:MAIN:Time 684, idle 62179/s, free 115688, MQTT 0(43), bWifi 1, secondsWithNoPing 618, socks 2/24 POWERSAVE
    Info:SENSOR:DHT start, pin is 7
    Info:MAIN:Time 685, idle 62701/s, free 110968, MQTT 0(43), bWifi 1, secondsWithNoPing 619, socks 3/24 POWERSAVE
    Info:SENSOR:DS1820[9] - Starting conversion
    Info:MAIN:Time 686, idle 67751/s, free 111352, MQTT 0(43), bWifi 1, secondsWithNoPing 620, socks 3/24 POWERSAVE
    Info:SENSOR:DS1820[9] - Temp=25.00
    Info:MAIN:Time 687, idle 60005/s, free 114144, MQTT 0(43), bWifi 1, secondsWithNoPing 621, socks 2/24 POWERSAVE
    Info:SENSOR:DHT start, pin is 7
    Info:MAIN:Time 688, idle 60500/s, free 114016, MQTT 0(43), bWifi 1, secondsWithNoPing 622, socks 2/24 POWERSAVE
    Info:MAIN:Time 689, idle 64545/s, free 115688, MQTT 0(43), bWifi 1, secondsWithNoPing 623, socks 2/24 POWERSAVE
    Info:MAIN:Time 690, idle 45499/s, free 115088, MQTT 0(43), bWifi 1, secondsWithNoPing 624, socks 3/24 POWERSAVE
    Info:SENSOR:DHT start, pin is 7
    Info:SENSOR:DS1820[9] - Starting conversion
    Info:MAIN:Time 691, idle 101536/s, free 115688, MQTT 0(43), bWifi 1, secondsWithNoPing 625, socks 2/24 POWERSAVE
    Info:SENSOR:DS1820[9] - Temp=25.00
    Info:MAIN:Time 692, idle 58883/s, free 115104, MQTT 0(43), bWifi 1, secondsWithNoPing 626, socks 3/24 POWERSAVE
  • #101 21624172
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14770
    Help: 659
    Rate: 12912
    Hey is @insmod PS fix tested and ready to merge?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #102 21624381
    insmod
    Level 31  
    Posts: 1432
    Help: 168
    Rate: 455
    >>21624172
    I guess? The only untested thing is spi on BK7231U/T_ALT and BK7238/N_ALT.
    I don't have anything to test it with.
    Though it can be merged even if it's not working.
  • #103 21624798
    max4elektroda
    Level 24  
    Posts: 758
    Help: 49
    Rate: 189
    Updated PR #1727, BK2738 now also works with powersave (tested DS18B20 and DHT11) .
    Maybe @divadiow can check with DHT22, too?
  • #104 21624810
    divadiow
    Level 38  
    Posts: 5220
    Help: 449
    Rate: 918
    powersave 1
    OpenBK7238 interface showing chip temperature -24.5°C and DHT22 sensor readings

    chip temp isn't quite right on BK7238
  • #105 21624824
    max4elektroda
    Level 24  
    Posts: 758
    Help: 49
    Rate: 189
    You also recognized it "freezing" from time to time??

    I only saw this with powersave, but must admit I didn't try too long without ...
  • #106 21624828
    divadiow
    Level 38  
    Posts: 5220
    Help: 449
    Rate: 918
    not noticed any freezing. chip temp is the same with 1.18.145 and no powersave
  • #107 21624835
    max4elektroda
    Level 24  
    Posts: 758
    Help: 49
    Rate: 189
    Sorry, meant as a joke: temp below -40°C --> "freezing" ;-)

    Chip temperature: -45.1°C displayed on a dark background

    Chip temperature reading: 188.5°C on dark background with technical text
  • #108 21624836
    divadiow
    Level 38  
    Posts: 5220
    Help: 449
    Rate: 918
    ah! knew it. I did wonder but.. nm ;)
  • SPI/PixelAnim works but colours are off

    #109 21626918
    divadiow
    Level 38  
    Posts: 5220
    Help: 449
    Rate: 918
    insmod wrote:
    The only untested thing is spi on BK7231U/T_ALT and BK7238/N_ALT.


    dug this out
    LED control panel with RGB settings, animation modes, and system diagnostics

    4m/60 WS2812B. OTA to latest _ALT
    LED control panel with animations, RGB color, and system information display

    SPI/PixelAnim works but the colours are off. Less noticeable when the animation, especially rainbow, is running, but here's the starting RGB at power-on.

    WS2812B LED strip glowing pink, green, and blue on a carpet
Listen:

Topic summary

LABEL_AI_GENERATED
Discussion about extending the OpenBeken DS18(B)20 sensor driver to support multiple GPIOs and multiple sensors per GPIO, with a split between a lightweight simple driver and a more capable full driver. The thread covers code sharing between drivers, flash-size impact, GUI changes, channel assignment rules, duplicate-channel checks, and startup command formatting. Extensive cross-platform testing was performed on BK7231N/T/U/S, BK7238, BK7252/BK7252N, BL602, W800, LN882H, ESP32, ESP32S2, ESP32-C6, and ECR6600, uncovering issues such as ESP32 reset timing, startup-command length limits, channel conflicts, and timing differences on Beken chips. The full driver was refined with shorter command names, compact sensor IDs, clearer unset-channel display, and restrictions against reusing occupied channels. Later parts of the discussion shifted to Beken timing fixes for HAL_Delay_us, logic-analyzer measurements, testus timing diagnostics, and power-save behavior, with DS18B20 and DHT drivers used as validation cases.
AI summary based on the discussion. May contain errors.
ADVERTISEMENT