2016-12-07 02:16:33 +08:00
# Sphero Ollie
2016-12-19 23:07:11 +08:00
The Sphero Ollie is a toy robot from Sphero that is controlled using Bluetooth LE. For more information, go to [http://www.sphero.com/ollie ](http://www.sphero.com/ollie )
2016-12-07 02:16:33 +08:00
## How to Install
2017-06-09 14:42:27 +08:00
2023-06-05 00:36:55 +08:00
Please refer to the main [README.md ](https://github.com/hybridgroup/gobot/blob/release/README.md )
2016-12-07 02:16:33 +08:00
## How to Use
2017-06-09 14:42:27 +08:00
2016-12-07 02:16:33 +08:00
```go
2016-12-19 23:07:11 +08:00
package main
import (
2023-06-05 00:36:55 +08:00
"os"
"time"
2016-12-19 23:07:11 +08:00
2023-06-05 00:36:55 +08:00
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/platforms/ble"
"gobot.io/x/gobot/v2/platforms/sphero/ollie"
2016-12-19 23:07:11 +08:00
)
func main() {
2023-06-05 00:36:55 +08:00
bleAdaptor := ble.NewClientAdaptor(os.Args[1])
ollie := ollie.NewDriver(bleAdaptor)
work := func() {
gobot.Every(1*time.Second, func() {
r := uint8(gobot.Rand(255))
g := uint8(gobot.Rand(255))
b := uint8(gobot.Rand(255))
ollie.SetRGB(r, g, b)
})
}
robot := gobot.NewRobot("ollieBot",
[]gobot.Connection{bleAdaptor},
[]gobot.Device{ollie},
work,
)
robot.Start()
2016-12-19 23:07:11 +08:00
}
2016-12-07 02:16:33 +08:00
```
## How to Connect
2016-12-19 23:07:11 +08:00
The Sphero Ollie is a Bluetooth LE device.
2023-06-05 00:36:55 +08:00
You need to know the BLE ID of the Ollie you want to connect to. The Gobot BLE client adaptor also lets you connect by
friendly name, aka "2B-1247".
2016-12-19 23:07:11 +08:00
### OSX
2023-06-05 00:36:55 +08:00
To run any of the Gobot BLE code you must use the `GODEBUG=cgocheck=0` flag in order to get around some of the issues in
the CGo-based implementation.
2017-10-29 01:32:59 +08:00
2023-06-05 00:36:55 +08:00
If you connect by name, then you do not need to worry about the Bluetooth LE ID. However, if you want to connect by ID,
OS X uses its own Bluetooth ID system which is different from the IDs used on Linux. The code calls thru the XPC interfaces
provided by OSX, so as a result does not need to run under sudo.
2016-12-19 23:07:11 +08:00
For example:
2023-06-05 00:36:55 +08:00
`GODEBUG=cgocheck=0 go run examples/ollie.go 2B-1247`
2016-12-19 23:07:11 +08:00
### Ubuntu
2023-06-05 00:36:55 +08:00
On Linux the BLE code will need to run as a root user account. The easiest way to accomplish this is probably to use
`go build` to build your program, and then to run the requesting executable using `sudo` .
2016-12-19 23:07:11 +08:00
For example:
2023-06-05 00:36:55 +08:00
```sh
go build examples/ollie.go
sudo ./minidrone 2B-1247
```
2016-12-19 23:07:11 +08:00
### Windows
Hopefully coming soon...