2

Good day,

I am using a Raspberry Pi Pico W with a temperature sensor among other things. I tried finding code online to make the temperature sensor work and it returns the following error.

Found DS devices:  []
Traceback (most recent call last):
  File "<stdin>", line 14, in <module>
  File "ds18x20.py", line 1, in convert_temp
  File "onewire.py", line 1, in reset
OneWireError: 

This is my code, does anyone know what is going wrong?

import machine, onewire, ds18x20, time
from machine import Pin


led = Pin(15, Pin.OUT)
button = Pin(14, Pin.IN, Pin.PULL_DOWN)
ds_pin = machine.Pin(16)
ds_sensor = ds18x20.DS18X20(onewire.OneWire(ds_pin))
roms = ds_sensor.scan()
print('Found DS devices: ', roms)

while True:
    
    ds_sensor.convert_temp()
    time.sleep_ms(70)
    for rom in roms:
        print(rom)
        print(ds_sensor.read_temp(rom))
    time.sleep(5)

    if button.value()==0:
        led.on()
        print('Door is open!')
        time.sleep(1)

    else:
        led.off()
        print('Door is closed!')
        time.sleep(1)

Thanks for reading. I don't have indent errors that might just be the StackExchange formatting.

1 Answer 1

5

Your sensor can not be found, this is what is going wrong. Check the connections. Without further information it is not possible to answer why it is not found.

1
  • Yes thank you, I accidentally connected it to GPIO 18 instead of ground. This was the error.
    – Pranav
    Oct 17, 2022 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.