Tyrone Smith
08/20/2024, 6:54 AMimport gpio // Sensors
import ds18b20 show Ds18b20 // Temperatursensor
GPIO-PIN-NUM1 ::= 2 // Outside Temperature GPIO
GPIO-PIN-NUM2 ::= 5 // Inside top Temperature GPIO
main:
temp1 := gpio.Pin GPIO-PIN-NUM1 --input --pull-up=true //Temperature-sensor Outside
ds1 := Ds18b20 temp1
temp2 := gpio.Pin GPIO-PIN-NUM2 --input --pull-up=true //Temperature-sensor Outside
ds2 := Ds18b20 temp2
temperatur1 := ds1.read-temperature // Outside
temperatur2 := ds2.read-temperature // Inside top
print "Temperatur 1: $temperatur1"
print "Temperatur 2: $temperatur2"
I found this comment in the ds18b20.toit lib but i honestly don't know how to make use of it.
Assumes there is only one sensor connected to the given $pin.
If there are multiple sensors, then the driver misbehaves. In that
case use $(Ds18b20.constructor --id --bus) instead.floitsch
08/20/2024, 7:06 AMfloitsch
08/20/2024, 7:10 AMTyrone Smith
08/20/2024, 7:10 AMfloitsch
08/20/2024, 7:11 AMTyrone Smith
08/20/2024, 7:12 AMfloitsch
08/20/2024, 7:13 AMTyrone Smith
08/20/2024, 7:14 AMfloitsch
08/20/2024, 7:24 AMTyrone Smith
08/20/2024, 7:25 AMfloitsch
08/20/2024, 8:26 AMfloitsch
08/20/2024, 8:27 AMfloitsch
08/20/2024, 8:27 AMTyrone Smith
08/20/2024, 8:31 AMfloitsch
08/20/2024, 8:31 AMTyrone Smith
08/20/2024, 8:32 AMfloitsch
08/20/2024, 8:32 AMfloitsch
08/20/2024, 8:33 AMTyrone Smith
08/20/2024, 8:38 AMimport gpio // Sensors
import ds18b20 show Ds18b20 // Temperatursensor
GPIO-PIN-NUM1 ::= 2 // Outside Temperature GPIO
GPIO-PIN-NUM2 ::= 5 // Inside top Temperature GPIO
main:
temp1 := gpio.Pin GPIO-PIN-NUM1 --input --pull-up=true //Temperature-sensor Outside
ds1 := Ds18b20 temp1
temperatur1 := ds1.read-temperature // Outside
print "Temperatur 1: $temperatur1"
ds1.close
temp1.close
temp2 := gpio.Pin GPIO-PIN-NUM2 --input --pull-up=true //Temperature-sensor Outside
ds2 := Ds18b20 temp2
temperatur2 := ds2.read-temperature // Inside top
print "Temperatur 2: $temperatur2"
ds2.close
temp2.close
It works perfectly fine like this:floitsch
08/20/2024, 8:39 AMTyrone Smith
08/20/2024, 8:39 AMfloitsch
08/20/2024, 8:47 AMTyrone Smith
08/20/2024, 8:49 AMfloitsch
08/20/2024, 8:51 AM