Skip to content

Commit

Permalink
curie: improve tests and examples
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Jun 15, 2017
1 parent fa74dbe commit cf14909
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 10 deletions.
63 changes: 63 additions & 0 deletions examples/ble_firmata_curie_imu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// +build example
//
// Do not build by default.

/*
How to run
Pass the BLE address or BLE name as first param:
go run examples/ble_firmata_curie_imu.go FIRMATA
NOTE: sudo is required to use BLE in Linux
*/

package main

import (
"log"
"os"
"time"

"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/firmata"
"gobot.io/x/gobot/platforms/intel-iot/curie"
)

func main() {
firmataAdaptor := firmata.NewBLEAdaptor(os.Args[1])
led := gpio.NewLedDriver(firmataAdaptor, "13")
imu := curie.NewIMUDriver(firmataAdaptor)

work := func() {
imu.On("Accelerometer", func(data interface{}) {
log.Println("Accelerometer", data)
})

imu.On("Gyroscope", func(data interface{}) {
log.Println("Gyroscope", data)
})

imu.On("Temperature", func(data interface{}) {
log.Println("Temperature", data)
})

gobot.Every(1*time.Second, func() {
led.Toggle()
})

gobot.Every(100*time.Millisecond, func() {
imu.ReadAccelerometer()
imu.ReadGyroscope()
imu.ReadTemperature()
})
}

robot := gobot.NewRobot("bot",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{led, imu},
work,
)

robot.Start()
}
2 changes: 1 addition & 1 deletion examples/firmata_curie_imu.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func main() {
})
}

robot := gobot.NewRobot("blinkmBot",
robot := gobot.NewRobot("curieBot",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{imu, led},
work,
Expand Down
2 changes: 1 addition & 1 deletion examples/firmata_curie_imu_shock_detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func main() {
imu.EnableShockDetection(true)
}

robot := gobot.NewRobot("blinkmBot",
robot := gobot.NewRobot("curieBot",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{imu, led},
work,
Expand Down
2 changes: 1 addition & 1 deletion examples/firmata_curie_imu_step_counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func main() {
imu.EnableStepCounter(true)
}

robot := gobot.NewRobot("blinkmBot",
robot := gobot.NewRobot("curieBot",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{imu, led},
work,
Expand Down
2 changes: 1 addition & 1 deletion examples/firmata_curie_imu_tap_detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func main() {
imu.EnableTapDetection(true)
}

robot := gobot.NewRobot("blinkmBot",
robot := gobot.NewRobot("curieBot",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{imu, led},
work,
Expand Down
9 changes: 9 additions & 0 deletions platforms/firmata/firmata_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ type firmataBoard interface {
gobot.Eventer
}

type FirmataAdaptor interface {
Connect() (err error)
Finalize() (err error)
Name() string
SetName(n string)
WriteSysex(data []byte) error
gobot.Eventer
}

// Adaptor is the Gobot Adaptor for Firmata based boards
type Adaptor struct {
name string
Expand Down
2 changes: 2 additions & 0 deletions platforms/firmata/firmata_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/drivers/i2c"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/platforms/firmata"
"gobot.io/x/gobot/platforms/firmata/client"
)

Expand All @@ -25,6 +26,7 @@ var _ aio.AnalogReader = (*Adaptor)(nil)
var _ gpio.PwmWriter = (*Adaptor)(nil)
var _ gpio.ServoWriter = (*Adaptor)(nil)
var _ i2c.Connector = (*Adaptor)(nil)
var _ firmata.FirmataAdaptor = (*Adaptor)(nil)

type readWriteCloser struct{}

Expand Down
77 changes: 73 additions & 4 deletions platforms/intel-iot/curie/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Curie

The Intel Curie is a microcontroller for the Internet of Things. It is the platform used by the Intel Arduino/Genuino 101 and the Intel TinyTILE.
The Intel Curie is a tiny computer for the Internet of Things. It is the processor used by the [Arduino/Genuino 101](https://www.arduino.cc/en/Main/ArduinoBoard101) and the [Intel TinyTILE](https://software.intel.com/en-us/node/675623).

For more info about the Curie platform go to: [http://www.intel.com/content/www/us/en/do-it-yourself/edison.html](http://www.intel.com/content/www/us/en/do-it-yourself/edison.html).
In addition to the GPIO, ADC, and I2C hardware interfaces, the Curie also has a built-in Inertial Measurement Unit (IMU), including an accelerometer, gyroscope, and thermometer.

For more info about the Intel Curie platform go to: [https://www.intel.com/content/www/us/en/products/boards-kits/curie.html](https://www.intel.com/content/www/us/en/products/boards-kits/curie.html).

## How to Install

You would normally install Go and Gobot on your workstation. When you execute the program code, it will communicate with the connected microcontroller using the Firmata protocol.
You would normally install Go and Gobot on your computer. When you execute the Gobot program code, it communicates with the connected microcontroller using the [Firmata protocol](https://github.com/firmata/protocol), either using a serial port, or the Bluetooth LE wireless interface.

```
go get -d -u gobot.io/x/gobot/...
Expand All @@ -15,5 +17,72 @@ go get -d -u gobot.io/x/gobot/...
## How To Use

```go
// code here...
package main

import (
"log"
"time"

"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/firmata"
"gobot.io/x/gobot/platforms/intel-iot/curie"
)

func main() {
firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
led := gpio.NewLedDriver(firmataAdaptor, "13")
imu := curie.NewIMUDriver(firmataAdaptor)

work := func() {
imu.On("Accelerometer", func(data interface{}) {
log.Println("Accelerometer", data)
})

imu.On("Gyroscope", func(data interface{}) {
log.Println("Gyroscope", data)
})

imu.On("Temperature", func(data interface{}) {
log.Println("Temperature", data)
})

imu.On("Motion", func(data interface{}) {
log.Println("Motion", data)
})

gobot.Every(1*time.Second, func() {
led.Toggle()
})

gobot.Every(100*time.Millisecond, func() {
imu.ReadAccelerometer()
imu.ReadGyroscope()
imu.ReadTemperature()
imu.ReadMotion()
})
}

robot := gobot.NewRobot("curieBot",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{imu, led},
work,
)

robot.Start()
}
```

## How to Connect

### Installing Firmware

You need to flash your Intel Curie with firmware that uses ConfigurableFirmata along with the FirmataCurieIMU plugin. There are 2 versions of this firmware, once that allows connecting using the serial interface, the other using a Bluetooth LE connection.

### Serial Port

Connect your Arduino 101 or TinyTILE using a serial cable, and connect using the correct serial port name.

### Bluetooth LE

Power up your Arduino 101 or TinyTILE using a battery or other power source, and connect using the BLE address or name.
4 changes: 2 additions & 2 deletions platforms/intel-iot/curie/imu_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ type MotionData struct {
// IMUDriver represents the IMU that is built-in to the Curie
type IMUDriver struct {
name string
connection *firmata.Adaptor
connection firmata.FirmataAdaptor
gobot.Eventer
}

// NewIMUDriver returns a new IMUDriver
func NewIMUDriver(a *firmata.Adaptor) *IMUDriver {
func NewIMUDriver(a firmata.FirmataAdaptor) *IMUDriver {
imu := &IMUDriver{
name: gobot.DefaultName("CurieIMU"),
connection: a,
Expand Down

0 comments on commit cf14909

Please sign in to comment.