Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nicholasjackson/sphero-mini
Library for interacting with the Sphero Mini using Bluetooth LE
https://github.com/nicholasjackson/sphero-mini
go sphero sphero-ble
Last synced: 23 days ago
JSON representation
Library for interacting with the Sphero Mini using Bluetooth LE
- Host: GitHub
- URL: https://github.com/nicholasjackson/sphero-mini
- Owner: nicholasjackson
- Created: 2022-01-21T15:08:32.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-26T07:43:36.000Z (almost 3 years ago)
- Last Synced: 2024-06-20T00:38:21.186Z (5 months ago)
- Topics: go, sphero, sphero-ble
- Language: Go
- Homepage:
- Size: 35.2 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sphero Mini API for Go
This repository contains a Go package for interfacing with the [Sphero Mini](https://sphero.com/products/sphero-mini) using Bluetooth LE.
## Example
To interact with the Sphero Mini you need to connect to it using either the devices short name e.g. `SM-BA93` or the
mac address for the device e.g. `15:DB:E2:E1:D1:77`. The following simple example shows how the `BluetoothAdapter`
can be used for this function.**Scanning bluetooth devices:**
```go
ad, err := sphero.NewBluetoothAdapter(createLogger())
if err != nil {
fmt.Printf("Unable to create a bluetooth adapter: %s\n", err)
os.Exit(1)
}sr := ad.Scan()
fmt.Printf("%-30s %s\n", "Name", "Mac Address")
fmt.Printf("%-30s %s\n", "-----------------------------", "-----------------")
for r := range sr {
fmt.Printf("%-30s %s\n", r.Name, r.Address.String())
}
```**Interacting with the Sphero**
```go
// create a new logger
logger := createLogger()// create a bluetooth adapter
adapter, err := sphero.NewBluetoothAdapter(logger)
if err != nil {
fmt.Printf("Unable to create a bluetooth adapter: %s\n", err)
os.Exit(1)
}// create a new sphero using the Bluetooth short name for the peripheral
ball, err := sphero.NewSphero("SM-34ED", adapter, logger)
if err != nil {
fmt.Printf("Unable to create a new sphero: %s\n", err)
os.Exit(1)
}// Put the ball to sleep, you should always call this method to save battery
defer ball.Sleep()// enable the backlight, this is useful to see which direction the sphero is headed
ball.EnableBackLight()
time.Sleep(5 * time.Second)// flash the LED Red, Green, and Blue for 1 second each
ball.
SetLEDColor(235, 64, 52).For(1*time.Second).
SetLEDColor(52, 235, 88).For(1*time.Second).
SetLEDColor(52, 122, 235).For(1 * time.Second)time.Sleep(5 * time.Second)
// Roll forward for 1 second, wait 1 second, and then roll back for 1 second
ball.
Roll(0, 150).For(1*time.Second).
Wait().For(1*time.Second).
Roll(180, 150).For(1 * time.Second)```
## Bluetooth Support
Bluetooth support is limited to that provided by [TinyGo Bluetooth](https://github.com/tinygo-org/bluetooth)
at present this support covers the following platforms.* Mac Intel - Supported but curently unstable
* Mac Arm64 (M1) - Unknown
* Linux Intel - Supported
* Linux Arm64 - Supported
* Windows - Not supported