Skip to content

RPI gpio delays #52

@wujiang

Description

@wujiang

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions