Closed indy99 closed 5 years ago
I assume you are referring to the watcher example, or your code is drawn from that?
That example was deficient in that it did not check for errors (you added a check for that), nor guarantee to release resources (in this case the watched pin) if the process is killed. I have updated the example to do both, which should fix the issue.
Btw, you can manually clear the busy state that is causing the reported error in this case using
echo 4 > /sys/class/gpio/unexport
from a shell.
echo 4 > /sys/class/gpio/unexport
Probably somehow my GPIO pin has been keep open. After unexport it with your command, problem solved. Thank you.
no error on first run. when I cancel the program with ctrl-c getting this error. (Raspberry pi 3 B+)
err=pin.Watch(gpio.EdgeBoth, func(pin *gpio.Pin) { fmt.Printf("Pin 4 is %v\n", pin.Read()) }) if err!=nil { panic(err) }
panic: pin already in use
goroutine 1 [running]: panic(0xd2b10, 0x1040c198) /usr/lib/go-1.7/src/runtime/panic.go:500 +0x33c