gobot.io/x/gobot/v2@v2.1.0/examples/tinkerboard_mpu6050.go (about) 1 //go:build example 2 // +build example 3 4 // 5 // Do not build by default. 6 7 package main 8 9 import ( 10 "fmt" 11 "time" 12 13 "gobot.io/x/gobot/v2" 14 "gobot.io/x/gobot/v2/drivers/i2c" 15 "gobot.io/x/gobot/v2/platforms/tinkerboard" 16 ) 17 18 // Wiring 19 // PWR Tinkerboard: 1 (+3.3V, VCC), 2(+5V), 6, 9, 14, 20 (GND) 20 // I2C1 Tinkerboard: 3 (SDA-ws), 5 (SCL-gn) 21 // MPU6050 plate: VCC, GND, SDL, SDA 22 func main() { 23 a := tinkerboard.NewAdaptor() 24 mpu6050 := i2c.NewMPU6050Driver(a) 25 26 work := func() { 27 var err error 28 29 gobot.Every(1000*time.Millisecond, func() { 30 if err = mpu6050.GetData(); err != nil { 31 fmt.Println(err) 32 } else { 33 fmt.Printf("Acc: %v Gyr: %v Temp: %v\n", mpu6050.Accelerometer, mpu6050.Gyroscope, mpu6050.Temperature) 34 } 35 }) 36 } 37 38 robot := gobot.NewRobot("mpBot", 39 []gobot.Connection{a}, 40 []gobot.Device{mpu6050}, 41 work, 42 ) 43 44 robot.Start() 45 }