It looks like Raspberry pi needs some time after export to link the digital pin properly.
package main
import (
"fmt"
"os"
"time"
)
func main() {
exporter, _:= os.OpenFile("/sys/class/gpio/export", os.O_WRONLY, os.ModeExclusive)
defer exporter.Close()
exporter.WriteString("10")
defer func() {
unexporter, _:= os.OpenFile("/sys/class/gpio/unexport", os.O_WRONLY, os.ModeExclusive)
defer unexporter.Close()
unexporter.WriteString("10")
}()
// time.Sleep(50 * time.Millisecond)
fi, _:= os.Stat("/sys/class/gpio/gpio10/direction")
fmt.Println(fi.Mode())
}
Without the sleep, the output is -rw-r--r--. With the sleep, the output is -rwxrwx--- which is correct.
This affects SetDirection directly.
It looks like Raspberry pi needs some time after
exportto link the digital pin properly.Without the sleep, the output is
-rw-r--r--. With the sleep, the output is-rwxrwx---which is correct.This affects
SetDirectiondirectly.