DS18B20 not working in WiPy 2.0



  • Hello There

    I have copied and paste following code

    from machine import Pin
    from ds18x20 import DS18X20
    d=DS18X20(Pin((Pin.exp_board.G23, mode=Pin.OUT)))
    result=d.read_temps()
    print(result)
    

    The only difference is that I am using the WyPy expansion board. it throwing following error in Atom

    Traceback (most recent call last):
    File "<stdin>", line 28
    SyntaxError: invalid syntax

    Line 28 is

    result=d.read_temps()

    any ideas?

    Cheers
    Colombian1976



  • @colombianaus said in DS18B20 not working in WiPy 2.0:

    d=DS18X20(Pin.exp_board.G23, mode=Pin.OUT)

    now you miss Pin class...
    d=DS18X20(Pin(Pin.exp_board.G23, mode=Pin.OUT))



  • @seb

    hey mate,...

    OK so all code below, but as you can notice first 24 lines are commented. Furthermore, I have deleted extra parentheses for the line

    d=DS18X20(Pin.exp_board.G23, mode=Pin.OUT)

    it now throws following error:

    Traceback (most recent call last):
    File "<stdin>", line 28, in <module>
    TypeError: function does not take keyword arguments

    line 28 is

    result=d.read_temps()

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

    the device is on GPIO23, expansion board

    dat = Pin(Pin.exp_board.G23, mode=Pin.OUT)

    create the onewire object

    ds = ds18x20.DS18X20(onewire.OneWire(dat))

    scan for devices on the bus

    roms = ds.scan()
    print('found devices:', roms)

    loop 10 times and print all temperatures

    for i in range(10):
    print('temperatures:', end=' ')
    ds.convert_temp()
    time.sleep_ms(750)
    for rom in roms:
    print(ds.read_temp(rom), end=' ')
    print()
    """
    from machine import Pin
    from ds18x20 import DS18X20
    d=DS18X20(Pin.exp_board.G23, mode=Pin.OUT)
    result=d.read_temps()
    print(result)

    Thank you for your assistance mate

    Cheers
    Wilson



  • First thing I notice is that you are passing Pin a tuple:

    (Pin.exp_board.G23, mode=Pin.OUT)
    

    I think you have used one too many pairs of parentheses.

    Secondly, can you share all your code? because the code you posted is only 5 lines long but the error says line 28


 

Pycom on Twitter