problem with reading vars on wipy 2 w/ext board and ds18b20
import machine import sys import os import time import onewire import ds18x20 from machine import Pin from onewire import OneWire from ds18x20 import DS18X20 while True: d3=DS18X20(Pin('P4', mode=Pin.OUT)) d2=DS18X20(Pin('P8', mode=Pin.OUT)) d1=DS18X20(Pin('P9', mode=Pin.OUT)) d=DS18X20(Pin('P10', mode=Pin.OUT)) result=(d.read_temps()) result1=(d1.read_temps()) result2=(d2.read_temps()) result3=(d3.read_temps()) if result and result1 and result2 and result3: a=str(result) b=str(result1) c=str(result2) d=str(result3) average=int((result+result1+result2+result3)/4) else: print("Sensor not Found") print("Temp1= ", a) print( "\nTemp2= ", b) print("\ntemp2= ", c) print("\ntemp3= ", d ) print("\nAverage",average ,"\n") time.sleep(0)
so code above should work but I'm getting "name is not defined" error and don't know what to do with this code :(
Error msg is "Variable name not defined" a, b, c, d and average when it comes to print statements.
PS @livius can You show me how to use one pin for 2 or more? I'm just beginning with IoT and electronics. Btw code I gave worked for them at first but after connecting 4th it started all the problems.
livius last edited by livius
format your post
and show exact error message with line number
and why you connect your DS18X20 to different pins? You can support few sensors on the same pin.
DS18X20 work on onewire protocol.
I do not know about which implementation of DS18X20 lib you have
but parameter for DS18X20 is onewire bus not pin
Pin can not be
OUTif you need to read something from it
oWire=OneWire(Pin('P22', Pin.PULL_UP)) temp=DS18X20(oWire, True) # you can ommit True if your lib does not have this param