mirror of
https://github.com/kidoman/embd
synced 2025-07-04 20:37:46 +02:00
added mpu6050 gyro/accel/temp sensor
Signed-off-by: Krasi Georgiev <krasi.root@gmail.com>
This commit is contained in:
parent
d3d8c0c5c6
commit
1f5b11a03e
2 changed files with 310 additions and 0 deletions
48
samples/mpu6050.go
Normal file
48
samples/mpu6050.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"time"
|
||||
|
||||
"github.com/kidoman/embd"
|
||||
"github.com/kidoman/embd/sensor/mpu6050"
|
||||
|
||||
_ "github.com/kidoman/embd/host/all"
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
if err := embd.InitI2C(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer embd.CloseI2C()
|
||||
|
||||
bus := embd.NewI2CBus(1)
|
||||
|
||||
sensor, _ := mpu6050.New(bus, &mpu6050.Config{GiroScale: "1000", Dlpf: "6"})
|
||||
|
||||
sensor.Start()
|
||||
defer sensor.Close()
|
||||
|
||||
// catch ctrl+c and ctrl+x so the sensor.Close is executed
|
||||
stop := make(chan os.Signal, 1)
|
||||
signal.Notify(stop, os.Interrupt, os.Kill)
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-stop:
|
||||
return
|
||||
default:
|
||||
v := sensor.Read().Orientation()
|
||||
print("\033[H\033[2J") // clear the screen for every read
|
||||
fmt.Println(v)
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue