kubeedge / examples

Examples for KubeEdge
Apache License 2.0
246 stars 172 forks source link

Upgrade Rasp Pi to v4 #30

Open joeblew99 opened 5 years ago

joeblew99 commented 5 years ago

The code here https://github.com/kubeedge/examples/blob/master/led-raspberrypi/light_driver/light_driver.go

can be upgraded to use periph here: https://github.com/google/periph

It now supports rasp pi v4 rasp pi v4 has a new Virtualisation instruction set ISA and so is muh faster running docker machines also btw.

fisherxu commented 5 years ago

@joeblew99 Thanks for your suggestion.

fisherxu commented 5 years ago

Would you help raise a PR to fix it? :)

joeblew99 commented 5 years ago

@fisherxu I can find an exact example for it.

joeblew99 commented 5 years ago

The code is here: https://periph.io/device/led/


package main

import (
    "log"
    "time"

    "periph.io/x/periph/conn/gpio"
    "periph.io/x/periph/host"
    "periph.io/x/periph/host/rpi"
)

func main() {
    // Load all the drivers:
    if _, err := host.Init(); err != nil {
        log.Fatal(err)
    }

    t := time.NewTicker(500 * time.Millisecond)
    for l := gpio.Low; ; l = !l {
        // Lookup a pin by its location on the board:
        if err := rpi.P1_33.Out(l); err != nil {
            log.Fatal(err)
        }
        <-t.C
    }
}

Also you need a button for your demo: https://periph.io/device/button/


package main

import (
    "fmt"
    "log"

    "periph.io/x/periph/conn/gpio"
    "periph.io/x/periph/conn/gpio/gpioreg"
    "periph.io/x/periph/host"
)

func main() {
    // Load all the drivers:
    if _, err := host.Init(); err != nil {
        log.Fatal(err)
    }

    // Lookup a pin by its number:
    p := gpioreg.ByName("GPIO2")
    if p == nil {
        log.Fatal("Failed to find GPIO2")
    }

    fmt.Printf("%s: %s\n", p, p.Function())

    // Set it as input, with an internal pull down resistor:
    if err = p.In(gpio.PullDown, gpio.BothEdges); err != nil {
        log.Fatal(err)
    }

    // Wait for edges as detected by the hardware, and print the value read:
    for {
        p.WaitForEdge(-1)
        fmt.Printf("-> %s\n", p.Read())
    }
}
joeblew99 commented 5 years ago

can i get access to slack ?

fisherxu commented 5 years ago

Have you been in the kubedge slack workspace? can ping me xufei @joeblew99

joeblew99 commented 5 years ago

no because i dont have an invite to that slack workspace. I cant ping you because i dont have an invite to slack.

fisherxu commented 5 years ago

https://join.slack.com/t/kubeedge/shared_invite/enQtNjc0MTg2NTg2MTk0LWJmOTBmOGRkZWNhMTVkNGU1ZjkwNDY4MTY4YTAwNDAyMjRkMjdlMjIzYmMxODY1NGZjYzc4MWM5YmIxZjU1ZDI

@joeblew99 This is the invite link. Thanks for join :)

joeblew99 commented 5 years ago

thanks !

daixiang0 commented 3 years ago

@joeblew99 any update for this?