2017-03-13 23:01:39 +08:00
|
|
|
// +build example
|
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
2017-07-13 08:08:46 +08:00
|
|
|
/*
|
|
|
|
How to run
|
|
|
|
Pass serial port to use as the first param:
|
|
|
|
|
|
|
|
go run examples/firmata_mpu6050.go /dev/ttyACM0
|
|
|
|
*/
|
|
|
|
|
2014-11-10 07:37:12 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-07-13 08:08:46 +08:00
|
|
|
"os"
|
2014-11-10 07:37:12 +08:00
|
|
|
"time"
|
|
|
|
|
2016-12-08 20:24:03 +08:00
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/drivers/i2c"
|
|
|
|
"gobot.io/x/gobot/platforms/firmata"
|
2014-11-10 07:37:12 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2017-07-13 08:08:46 +08:00
|
|
|
firmataAdaptor := firmata.NewAdaptor(os.Args[1])
|
2016-10-03 22:58:43 +08:00
|
|
|
mpu6050 := i2c.NewMPU6050Driver(firmataAdaptor)
|
2014-11-10 07:37:12 +08:00
|
|
|
|
|
|
|
work := func() {
|
|
|
|
gobot.Every(100*time.Millisecond, func() {
|
2017-02-11 17:37:34 +08:00
|
|
|
mpu6050.GetData()
|
|
|
|
|
2014-11-10 07:37:12 +08:00
|
|
|
fmt.Println("Accelerometer", mpu6050.Accelerometer)
|
|
|
|
fmt.Println("Gyroscope", mpu6050.Gyroscope)
|
|
|
|
fmt.Println("Temperature", mpu6050.Temperature)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("mpu6050Bot",
|
|
|
|
[]gobot.Connection{firmataAdaptor},
|
|
|
|
[]gobot.Device{mpu6050},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
2016-10-19 03:08:25 +08:00
|
|
|
robot.Start()
|
2014-11-10 07:37:12 +08:00
|
|
|
}
|