artificial-intelligence-class / spherov2.py

Licence: MIT license
Unofficial Python API for all Sphero toys

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to spherov2.py

Esp32 Ble Mouse
Bluetooth LE Mouse library for the ESP32 (Arduino IDE compatible)
Stars: ✭ 180 (+400%)
Mutual labels:  bluetooth, ble
py-bluetooth-utils
Python module containing bluetooth utility functions, in particular for easy BLE scanning and advertising
Stars: ✭ 60 (+66.67%)
Mutual labels:  bluetooth, ble
Golden Gate
Framework to connect wearables and other IoT devices to mobile phones, tablets and PCs with an IP-based protocol stack over Bluetooth Low Energy
Stars: ✭ 223 (+519.44%)
Mutual labels:  bluetooth, ble
Androidblemanager
android BLE device scan and connect manager
Stars: ✭ 174 (+383.33%)
Mutual labels:  bluetooth, ble
contact-tracer
A prototype contact tracer app for COVID-19 pandemic response
Stars: ✭ 50 (+38.89%)
Mutual labels:  bluetooth, ble
Continuity
Apple Continuity Protocol Reverse Engineering and Dissector
Stars: ✭ 180 (+400%)
Mutual labels:  bluetooth, ble
bluetooth-terminal
ES6 class for serial communication with your own Bluetooth Low Energy (Smart) devices
Stars: ✭ 43 (+19.44%)
Mutual labels:  bluetooth, ble
Ble
Connect to and interact with Bluetooth LE peripherals.
Stars: ✭ 156 (+333.33%)
Mutual labels:  bluetooth, ble
ganglion-ble
Web Bluetooth client for the Ganglion brain-computer interface by OpenBCI
Stars: ✭ 27 (-25%)
Mutual labels:  bluetooth, ble
BTLinker
🔥空祖家的蓝牙连接封装库,适用于智能硬件蓝牙通讯
Stars: ✭ 64 (+77.78%)
Mutual labels:  bluetooth, ble
Reactivebeacons
Android library scanning BLE beacons nearby with RxJava
Stars: ✭ 171 (+375%)
Mutual labels:  bluetooth, ble
ioBroker.ble
Monitor Bluetooth Low Energy beacons
Stars: ✭ 39 (+8.33%)
Mutual labels:  bluetooth, ble
H Ble
Android Ble类库,基于回调,暴露搜索、连接、发送、接收、断开连接等接口,无需关心细节操作即可进行Ble通信。
Stars: ✭ 171 (+375%)
Mutual labels:  bluetooth, ble
app-xyo-nodejs
XYO Archivist/Diviner CLI
Stars: ✭ 41 (+13.89%)
Mutual labels:  bluetooth, ble
Node Ble
Bluetooth Low Energy (BLE) library written with pure Node.js (no bindings) - baked by Bluez via DBus
Stars: ✭ 159 (+341.67%)
Mutual labels:  bluetooth, ble
Bluetooth
Cross-platform Bluetooth API for Go and TinyGo.
Stars: ✭ 246 (+583.33%)
Mutual labels:  bluetooth, ble
Esp32 Blecollector
ᛡᛒ BLE Scanner + Data persistence on SD Card for M5Stack, Odroid-Go, ESP32-Wrover-Kit and other models
Stars: ✭ 145 (+302.78%)
Mutual labels:  bluetooth, ble
Easyble
Android BLE framework
Stars: ✭ 155 (+330.56%)
Mutual labels:  bluetooth, ble
RejsaRubberTrac
RejsaRubberTrac - A wireless thermal camera for monitoring tire temperatures
Stars: ✭ 77 (+113.89%)
Mutual labels:  bluetooth, ble
ble
Bluetooth Low Energy for Linux / macOS
Stars: ✭ 264 (+633.33%)
Mutual labels:  bluetooth, ble

spherov2.py

status python version pypi docs license last commit

An unofficial Python library for Sphero toys that supports its Version 2 Bluetooth low energy API described here. Toys that are supported includes (implemented ones are checked):

  • Sphero 2.0 / SPRK
  • Sphero Ollie
  • Sphero BB-8
  • Sphero BB-9E
  • Sphero R2-D2 / R2-Q5
  • Sphero BOLT (In Progress)
  • Sphero SPRK+ / SPRK 2.0
  • Sphero Mini
  • Sphero RVR

Current Progress:

  • Found a better way to decompile, fixing a few things like Controls, Command Queueing, and Waiting for responses
  • Controls
    • Animation Control
    • Drive Control
    • LED Control
    • Sensor Control
    • Stats Control
    • Streaming Control

The logic is written based on reverse-engineering the official Sphero Edu for Android, with the help from available documentation and other unofficial community-based Sphero libraries like igbopie/spherov2.js and EnotYoyo/pysphero.

This project uses the hbldh/bleak Bluetooth Low Energy library, which works across all platforms.

Usage

To install the library, run pip install spherov2. Python version >= 3.7 are supported.

The library currently has two adapters, BleakAdapter and TCPAdapter. BleakAdapter is used by default when adapter is not specified, which connects to toys using the local Bluetooth adapter. For example:

from spherov2 import scanner

with scanner.find_toy() as toy:
    ...

TCPAdapter allows the user to send and receive Bluetooth packets connected to another host via a server running on that host as a relay. To start the server, run python -m spherov2.adapter.tcp_server [host] [port], with host and port by default being 0.0.0.0 and 50004. To use the adapter, for example:

from spherov2 import scanner
from spherov2.adapter.tcp_adapter import get_tcp_adapter

with scanner.find_toy(adapter=get_tcp_adapter('localhost')) as toy:
    ...

The TCP server is written in asynchronous fashion using asyncio, so that it supports bleak on all platforms.

On whichever device you decide to connect to the toys, you have to first install the BLE library by pip install bleak.

Scanner

You can scan the toys around you using the scanner helper. To find all possible toys, simply call scanner.find_toys(). To find only a single toy, use scanner.find_toy().

You can also find toys using specific filters. Please refer to the document for more information.

APIs

There are two ways you can interact with the toys, one is to use the low-level APIs implemented for each toy with the commands they support. Low-level APIs can be found for each toy under spherov2.toy.*, and is not documented.

The other and recommended way is to use the high level API spherov2.sphero_edu.SpheroEduAPI, which is an implementation of the official Sphero Edu APIs. Documentations can be found inside the source files with the docstrings, or here as an HTML rendered version. For example:

from spherov2 import scanner
from spherov2.sphero_edu import SpheroEduAPI

toy = scanner.find_toy()
with SpheroEduAPI(toy) as api:
    api.spin(360, 1)

Acknowledgments

This library is made for educational purposes. It is used by students in CIS 521 - Artificial Intelligence at the University of Pennsylvania, where we use Sphero robots to help teach the foundations of AI.

It is published as an open-source library under the MIT License.

Authors

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].