Skip to content

Commit

Permalink
Add Edison Support
Browse files Browse the repository at this point in the history
Digital write works

Add PWMWrite

Add AnalogRead

Refactor edison adaptor

Enable more digital pins

Enable all digital pins

Add i2c support

Properly close i2c device

Restore proper examples

Add test stub

Add Edison README

Conflicts:
	scripts/travis.sh
  • Loading branch information
zankich committed Sep 24, 2014
1 parent 885376e commit 55fd5b1
Show file tree
Hide file tree
Showing 16 changed files with 869 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PACKAGES := gobot gobot/api $(shell ls ./platforms | sed -e 's/^/gobot\/platforms\//')
PACKAGES := gobot gobot/api gobot/platforms/intel-iot/edison $(shell ls ./platforms | sed -e 's/^/gobot\/platforms\//')

.PHONY: test cover robeaux

Expand Down
32 changes: 32 additions & 0 deletions examples/edison_blink.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"time"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/gpio"
"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
)

func main() {
gbot := gobot.NewGobot()

e := edison.NewEdisonAdaptor("edison")
led := gpio.NewLedDriver(e, "led", "13")

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

robot := gobot.NewRobot("blinkBot",
[]gobot.Connection{e},
[]gobot.Device{led},
work,
)

gbot.AddRobot(robot)

gbot.Start()
}
36 changes: 36 additions & 0 deletions examples/edison_blinkm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"fmt"
"time"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/i2c"
"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
)

func main() {
gbot := gobot.NewGobot()

e := edison.NewEdisonAdaptor("edison")
blinkm := i2c.NewBlinkMDriver(e, "blinkm")

work := func() {
gobot.Every(3*time.Second, func() {
r := byte(gobot.Rand(255))
g := byte(gobot.Rand(255))
b := byte(gobot.Rand(255))
blinkm.Rgb(r, g, b)
fmt.Println("color", blinkm.Color())
})
}

robot := gobot.NewRobot("blinkmBot",
[]gobot.Connection{e},
[]gobot.Device{blinkm},
work,
)

gbot.AddRobot(robot)
gbot.Start()
}
35 changes: 35 additions & 0 deletions examples/edison_button.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/gpio"
"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
)

func main() {
gbot := gobot.NewGobot()

e := edison.NewEdisonAdaptor("edison")

button := gpio.NewButtonDriver(e, "myButton", "2")
led := gpio.NewLedDriver(e, "myLed", "7")

work := func() {
gobot.On(button.Event("push"), func(data interface{}) {
led.On()
})
gobot.On(button.Event("release"), func(data interface{}) {
led.Off()
})
}

robot := gobot.NewRobot("buttonBot",
[]gobot.Connection{e},
[]gobot.Device{led, button},
work,
)

gbot.AddRobot(robot)

gbot.Start()
}
39 changes: 39 additions & 0 deletions examples/edison_led_brightness.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import (
"time"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/gpio"
"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
)

func main() {
gbot := gobot.NewGobot()

e := edison.NewEdisonAdaptor("edison")
led := gpio.NewLedDriver(e, "led", "3")

work := func() {
brightness := uint8(0)
fadeAmount := uint8(15)

gobot.Every(100*time.Millisecond, func() {
led.Brightness(brightness)
brightness = brightness + fadeAmount
if brightness == 0 || brightness == 255 {
fadeAmount = -fadeAmount
}
})
}

robot := gobot.NewRobot("pwmBot",
[]gobot.Connection{e},
[]gobot.Device{led},
work,
)

gbot.AddRobot(robot)

gbot.Start()
}
38 changes: 38 additions & 0 deletions examples/edison_led_brightness_with_analog_input.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"fmt"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/gpio"
"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
)

func main() {
gbot := gobot.NewGobot()

e := edison.NewEdisonAdaptor("edison")
sensor := gpio.NewAnalogSensorDriver(e, "sensor", "0")
led := gpio.NewLedDriver(e, "led", "3")

work := func() {
gobot.On(sensor.Event("data"), func(data interface{}) {
brightness := uint8(
gobot.ToScale(gobot.FromScale(float64(data.(int)), 0, 4096), 0, 255),
)
fmt.Println("sensor", data)
fmt.Println("brightness", brightness)
led.Brightness(brightness)
})
}

robot := gobot.NewRobot("sensorBot",
[]gobot.Connection{e},
[]gobot.Device{sensor, led},
work,
)

gbot.AddRobot(robot)

gbot.Start()
}
13 changes: 13 additions & 0 deletions platforms/intel-iot/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright (c) 2014 The Hybrid Group

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
6 changes: 6 additions & 0 deletions platforms/intel-iot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Intel IoT

This package contains the Gobot adaptor for the [Intel Edison](http://www.intel.com/content/www/us/en/do-it-yourself/edison.html) IoT platform.

This package currently supports the following Intel IoT hardware:
- Intel Edison with the Arduino breakout board
81 changes: 81 additions & 0 deletions platforms/intel-iot/edison/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Edison

This package contains the Gobot adaptor for the [Intel Edison](http://www.intel.com/content/www/us/en/do-it-yourself/edison.html) IoT platform.

This package currently supports the following Intel IoT hardware:
- Intel Edison with the Arduino breakout board

## Getting Started

First you must install the appropriate Go packages

```
go get github.com/hybridgroup/gobot && go install github.com/hybridgroup/gobot/platforms/intel-iot/edison
```

#### Setting up your Intel Edison

Everything you need to get started with the Edison is in the Intel Getting Started Guide
located [here](https://communities.intel.com/docs/DOC-23147). Don't forget to
configure your Edison's wifi connection and [flash](https://communities.intel.com/docs/DOC-23192)
your Edison with the latest firmware image!

#### Cross compiling for the Intel Edison
You must first configure your Go environment for 386 linux cross compiling

```bash
$ cd $GOROOT/src
$ GOOS=linux GOARCH=386 ./make.bash --no-clean
```

Then compile your Gobot program with
```bash
$ GOARCH=386 GOOS=linux go build examples/edison_blink.go
```

Then you can simply upload your program over the network from your host computer to the Edison
``` bash
$ scp edison_blink [email protected]:/home/root/
```

and execute it on your Edison with
```bash
$ ./edison_blink
```

## Example

```go
package main

import (
"time"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/gpio"
"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
)

func main() {
gbot := gobot.NewGobot()

e := edison.NewEdisonAdaptor("edison")
led := gpio.NewLedDriver(e, "led", "13")

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

robot := gobot.NewRobot("blinkBot",
[]gobot.Connection{e},
[]gobot.Device{led},
work,
)

gbot.AddRobot(robot)

gbot.Start()
}
```
80 changes: 80 additions & 0 deletions platforms/intel-iot/edison/digital_pin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package edison

import (
"io/ioutil"
"strconv"
)

func gpioPath() string {
return "/sys/class/gpio"
}
func gpioExportPath() string {
return gpioPath() + "/export"
}
func gpioUnExportPath() string {
return gpioPath() + "/unexport"
}
func gpioDirectionPath(pin string) string {
return gpioPath() + "/gpio" + pin + "/direction"
}
func gpioValuePath(pin string) string {
return gpioPath() + "/gpio" + pin + "/value"
}

type digitalPin struct {
pin string
dir string
}

func newDigitalPin(pin int) *digitalPin {
d := &digitalPin{pin: strconv.Itoa(pin)}
d.export()
return d
}

func (d *digitalPin) setDir(dir string) {
d.dir = dir
err := writeFile(gpioDirectionPath(d.pin), dir)
if err != nil {
panic(err)
}
}

func (d *digitalPin) digitalWrite(value string) {
if d.dir != "out" {
d.setDir("out")
}
err := writeFile(gpioValuePath(d.pin), value)
if err != nil {
panic(err)
}
}

func (d *digitalPin) digitalRead() int {
if d.dir != "in" {
d.setDir("in")
}

buf, err := ioutil.ReadFile(gpioValuePath(d.pin))
if err != nil {
panic(err)
}

i, err := strconv.Atoi(string(buf[0]))
if err != nil {
panic(err)
}
return i
}

func (d *digitalPin) export() {
writeFile(gpioExportPath(), d.pin)
}

func (d *digitalPin) unexport() {
writeFile(gpioUnExportPath(), d.pin)
}

func (d *digitalPin) close() {
d.unexport()
}
Loading

0 comments on commit 55fd5b1

Please sign in to comment.