Files
Daniel Esteban 5cc21329a6 first implementation of 1-wire protocol (#505)
onewire: initial implementation for protocol and ds18b20 device
2023-04-22 17:55:37 +02:00

41 lines
554 B
Go

package main
import (
"encoding/hex"
"time"
"tinygo.org/x/drivers/onewire"
)
func main() {
pin := machine.D2
ow := onewire.New(pin)
for {
time.Sleep(3 * time.Second)
println()
println("Device:", machine.Device)
romIDs, err := ow.Search(onewire.SEARCH)
if err != nil {
println(err)
}
for _, romid := range romIDs {
println(hex.EncodeToString(romid))
}
if len(romIDs) == 1 {
// only 1 device on bus
r, err := ow.ReadAddress()
if err != nil {
println(err)
}
println(hex.EncodeToString(r))
}
}
}