artificial-intelligence-class / spherov2.py Goto Github PK
View Code? Open in Web Editor NEWUnofficial Python API for all Sphero toys
License: MIT License
Unofficial Python API for all Sphero toys
License: MIT License
Every time I execute my code my Sphero mini turns off directly and as such I have to restart it by connecting it to a charger, is there any way to avoid this behavior?
I accidentally tried to use set_matrix_pixel on a negative pixel value, which crashes the program in the following way:
"spherov2\controls\v2.py", line 157, in new_packet
packet = Packet(flags, did, cid, self.__seq, tid, sid, bytearray(data or []))
^^^^^^^^^^^^^^^^^^^^^
ValueError: byte must be in range(0, 256)
While it makes sense that calling set_matrix_pixel on a negative pixel location wouldn't work, it should ideally be handled gracefully and at the very least return a specific error rather than crashing the program.
I'm trying to connect to multiple Sphero Bolts at once but when I get to around 3 connections sometimes I'll get the following error
spherov2.controls.PacketDecodingException: Bad response checksum
I modified v2.py
to log the unescaped packet that didn't have the correct checksum
Sphero 1:
0x8d 0x30 0x11 0x2 0x18 0x2 0xff 0x3f 0x7f 0xf3 0x84 0x3c 0x28 0xcf 0xc2 0x3c 0x87 0xcb 0xf5 0x38 0x5f 0xd 0xfc 0x3f 0x97 0x23 0x72 0x3f 0xf3 0x26 0x3a 0xbb 0xc7 0xba 0x18 0x3c 0xff 0xdf 0x38 0xbc 0x6a 0xd5 0x56 0x3f 0x7e 0x5d 0xb8 0x8d 0x30 0x11 0x2 0x18 0x2 0xff 0x3f 0x7f 0xf3 0x8f 0x3c 0x26 0x36 0xdf 0x3c 0x88 0x46 0x62 0x38 0x69 0x11 0xb9 0x3f 0x94 0xcf 0xf8 0x3f 0xf4 0x1 0x9e 0xbb 0xd0 0xb1 0xab 0x23 0x3c 0xff 0x13 0x60 0xbc 0xb5 0x98 0x98 0x3f 0x7e 0x5e 0x4c 0x3f 0x7e 0x8e 0x75 0xb6 0x98 0x56 0xfd 0xb8 0x2d 0x1a 0xfd 0xb6 0x8f 0x38 0x75 0xb7 0x85 0x64 0x50 0x41 0xde 0xbc 0xb1 0x3c 0xca 0xae 0x24 0xbe 0xb3 0x22 0x36 0x0 0x0 0x0 0x0 0x43 0xbd 0xcf 0x5c 0x75 0xd8
Sphero 2:
0x8d 0x30 0x11 0x2 0x18 0x2 0xff 0x3f 0x7f 0xc3 0x25 0x3d 0x6 0x18 0xd0 0xbc 0xe5 0x73 0x85 0xb8 0x2a 0x12 0x8d 0x30 0x11 0x2 0x18 0x2 0xff 0x3f 0x7f 0xc2 0xe9 0x3d 0x6 0xd5 0x43 0xbc 0xe4 0xc6 0xb9 0xb8 0xc 0xa 0x3 0x40 0x71 0x8c 0x74 0xc0 0x4c 0xbc 0x13 0x3b 0x7a 0xf9 0x23 0xbd 0x4d 0x7a 0xdd 0xbd 0x8b 0x7a 0x68 0x3f 0x80 0x5 0x2d 0x3f 0x80 0x7a 0x2c 0x36 0xb6 0x59 0x20 0x39 0x5 0xe0 0x32 0x37 0xc 0xd9 0x11 0xb7 0x87 0xd 0x55 0x41 0xba 0x97 0xa7 0x3c 0xc8 0xb8 0xb4 0x3e 0x58 0x6d 0x91 0x0 0x0 0x0 0x0 0x43 0x9c 0x18 0x0 0xfb 0xd8
Sphero 3:
0x8d 0x30 0x11 0x2 0x18 0x2 0xff 0x3f 0x7f 0xd0 0x2d 0x3d 0x1b 0xeb 0x8c 0xbb 0x4d 0x57 0x17 0xb9 0x45 0xc3 0x93 0x40 0x8b 0x9e 0x83 0xbe 0xb8 0x1e 0x4d 0x3c 0xb1 0x2d 0x42 0xbb 0xb4 0x54 0x9c 0xbd 0x99 0x7e 0x72 0x3f 0x7f 0xc8 0xfb 0x8d 0x30 0x11 0x2 0x18 0x2 0xff 0x3f 0x7f 0xcf 0xdc 0x3d 0x1c 0x77 0xd1 0xbb 0x48 0x8b 0x6b 0xb9 0x4c 0x79 0xde 0x40 0x8c 0x1c 0x29 0xbe 0xb3 0xd7 0xd9 0x3c 0xb7 0x30 0xe6 0xbb 0xb4 0x75 0x53 0xbd 0x99 0x79 0xc 0x3f 0x7e 0xc7 0xe5 0x3f 0x7f 0x81 0x86 0xb5 0xdb 0xb2 0xe9 0x36 0x34 0x2f 0xad 0xb6 0xb 0x58 0x91 0x38 0x30 0xf2 0xaa 0x41 0x50 0x84 0xb5 0xbd 0x87 0x97 0xaf 0xbd 0x2e 0x69 0x9d 0x0 0x0 0x0 0x0 0x42 0xea 0xc3 0xd6 0xa0 0xd8
Looking through the packets each has a SOP byte after the initial SOP byte which is why I assume the checksum is failing
hello,
More a question than an issue
Is there a way to access the value of each of the Ir sensors ?
thanks
Hi, the get_location() api seems to return a value that is either a rounded floating point, or an integer value that was transformed into a floating value. I'm suspecting it's the latter because of the binary locator flags in [1] and the StreamingService classes in spherov2.py/spherov2/controls/v2.py.
[1]:
class LocatorFlags(IntFlag):
AUTO_CALIBRATE = 0x1 # 0b1
To reproduce this:
from spherov2 import scanner
from spherov2.adapter.tcp_adapter import get_tcp_adapter
from spherov2.sphero_edu import SpheroEduAPI
toy = scanner.find_toy()
with SpheroEduAPI(toy) as api:
print(api.get_location())
I am working with Python 3.11.3 64-bit, spherov2 version 0.12, and a Sphero SPRK+.
Other than this issue, this has been a great and simple package to work with, thank you!
Hi, the on_collision method doesn't seem to function properly.
It was giving
"spherov2/commands/sensor.py", line 117, in __collision_detected_notify_helper
unpacked = struct.unpack('>3hB3hBL', packet.data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
struct.error: unpack requires a buffer of 18 bytes
I changed it to ">3hB3hBh" and everything works again.
Hi, Just discovered this repo after dusting off my old Sphere 2.0 and wanted to give it a try but failing. I ran python /main.py
from the main directory but receive an error of file not found. Any pointers would be grateful.
The communication protocol works properly for the sphero mini. However the code for the Sphero Bolt works partially. Led/matrix/connection control works well. Only the Bolt does not move with the phython code.
The following version is installed on my computer:
Pycharm: version 3.8
Sperov2: version 0.10
Firmware Bolt: Nordic 4.2.41, ST 4.2.44
namedtuple is not mutable so it does not allow to set attribute like:
self.__raw_motor.left = ...
This could be fixed by adding
from types import SimpleNamespace
and defining self.__raw_motor
in Class SpheroEduAPI
as
self.__raw_motor = SimpleNamespace(left=0, right=0)
I will try to learn Git over the weekend and maybe create a pull request
I'm on a MacBook running Python 3.8 and have installed bleak
and spherov2
When I run from spherov2.sphero_edu import SpheroEduAPI
I get a TypeError.
Traceback shows:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/wlamb/opt/anaconda3/envs/sphero/lib/python3.8/site-packages/spherov2/sphero_edu.py", line 83, in <module> class SpheroEduAPI: File "/Users/wlamb/opt/anaconda3/envs/sphero/lib/python3.8/site-packages/spherov2/sphero_edu.py", line 414, in SpheroEduAPI def register_matrix_animation(self, frames:list[list[list[int]]], palette:list[Color], fps:int, transition:bool): TypeError: 'type' object is not subscriptable
Hi, I just got a Sphero Bolt and I'm learning to use it with your library. Sadly all sensors return "None". Can you tell me where is the mistake ? Here is my code :
import time
from spherov2 import scanner
from spherov2.sphero_edu import SpheroEduAPI
from spherov2.types import Color
toy = scanner.find_toy()
print(toy)
with SpheroEduAPI(toy) as droid:
droid.reset_aim()
droid.set_main_led(Color(r=0, g=0, b=255))
print(droid.get_acceleration())
print(droid.get_luminosity())
droid.set_speed(60)
time.sleep(0.5)
droid.set_speed(0)
print(droid.get_location())
Hey,
I tried running the example on my Sphero Mini but got an error saying (see the stack trace for the full error):
"Task <Task pending name='Task-3' coro=<BleakClient.connect() running at ... got Future attached to a different loop"
Any ideas?
The code it tried:
from spherov2 import scanner
with scanner.find_Mini() as toy:
print(toy)
Versions:
And the full trace:
Traceback (most recent call last):
File "/home/luc/code/sphero_test/mini_test.py", line 3, in <module>
with scanner.find_Mini() as toy:
File "/home/luc/anaconda3/envs/sphero/lib/python3.8/site-packages/spherov2/toy/__init__.py", line 54, in __enter__
self.__adapter = self.__adapter_cls(self.address)
File "/home/luc/anaconda3/envs/sphero/lib/python3.8/site-packages/spherov2/adapter/bleak_adapter.py", line 25, in __init__
self.__execute(self.__device.connect())
File "/home/luc/anaconda3/envs/sphero/lib/python3.8/site-packages/spherov2/adapter/bleak_adapter.py", line 32, in __execute
return asyncio.run_coroutine_threadsafe(coroutine, self.__event_loop).result()
File "/home/luc/anaconda3/envs/sphero/lib/python3.8/concurrent/futures/_base.py", line 444, in result
return self.__get_result()
File "/home/luc/anaconda3/envs/sphero/lib/python3.8/concurrent/futures/_base.py", line 389, in __get_result
raise self._exception
File "/home/luc/anaconda3/envs/sphero/lib/python3.8/site-packages/bleak/__init__.py", line 392, in connect
return await self._backend.connect(**kwargs)
File "/home/luc/anaconda3/envs/sphero/lib/python3.8/site-packages/bleak/backends/bluezdbus/client.py", line 108, in connect
device = await BleakScanner.find_device_by_address(
File "/home/luc/anaconda3/envs/sphero/lib/python3.8/site-packages/bleak/__init__.py", line 221, in find_device_by_address
return await cls.find_device_by_filter(
File "/home/luc/anaconda3/envs/sphero/lib/python3.8/site-packages/bleak/__init__.py", line 257, in find_device_by_filter
async with cls(detection_callback=apply_filter, **kwargs):
File "/home/luc/anaconda3/envs/sphero/lib/python3.8/site-packages/bleak/__init__.py", line 101, in __aenter__
await self._backend.start()
File "/home/luc/anaconda3/envs/sphero/lib/python3.8/site-packages/bleak/backends/bluezdbus/scanner.py", line 150, in start
self._stop = await manager.active_scan(
File "/home/luc/anaconda3/envs/sphero/lib/python3.8/site-packages/bleak/backends/bluezdbus/manager.py", line 345, in active_scan
reply = await self._bus.call(
File "/home/luc/anaconda3/envs/sphero/lib/python3.8/site-packages/dbus_fast/aio/message_bus.py", line 358, in call
await future
RuntimeError: Task <Task pending name='Task-3' coro=<BleakClient.connect() running at /home/luc/anaconda3/envs/sphero/lib/python3.8/site-packages/bleak/__init__.py:392> cb=[_chain_future.<locals>._call_set_state() at /home/luc/anaconda3/envs/sphero/lib/python3.8/asyncio/futures.py:367]> got Future <Future pending> attached to a different loop
Before digging into the lib' I'd like to know what really isn't implemented in order to interact with Sphero Mini?
Why couldn't it "just" extend https://github.com/artificial-intelligence-class/spherov2.py/blob/master/spherov2/toy/sphero.py ?
(Also worth mentioning another library living at https://github.com/MProx/Sphero_mini)
Hello,
I can't seem to use the events (collision, landing, etc.), even the examples given in the API documentation don't work for me. Can I have a full example if it's my code that is the problem.
I am using a win11 with python 3.8.5.
Here is my code:
import sys
from spherov2 import scanner
from spherov2.sphero_edu import SpheroEduAPI, EventType
from spherov2.types import Color
def on_collision(droid):
droid.stop_roll()
print('Collision')
droid.set_heading(droid.get_heading() + 180)
time.sleep(0.5)
droid.set_main_led(Color(255, 22, 255))
droid.set_speed(100)
toy = scanner.find_toy(toy_name=sys.argv[1])
with SpheroEduAPI(toy) as droid:
for i in range(50):
droid.register_event(EventType.on_collision, on_collision)
droid.set_main_led(Color(255, 255, 255))
droid.set_speed(100)
time.sleep(.5)```
I played around with basic movement and LEDs and all work great.
However, I wanted to test build-in animations and play_animation()
gives me TimeoutError().
I don't see play_animation()
in the documentation so I'm not sure if this is really implemented and if it works how I understand it.
Any help would be greatly appreciated.
droid.play_animation(toy.Animations.WWM_SCARED) File "C:\ProgramData\Anaconda3\lib\site-packages\spherov2\sphero_edu.py", line 285, in play_animation ToyUtil.play_animation(self.__toy, animation, True) File "C:\ProgramData\Anaconda3\lib\site-packages\spherov2\utils.py", line 93, in play_animation toy.play_animation(animation, wait) File "C:\ProgramData\Anaconda3\lib\site-packages\spherov2\commands\animatronic.py", line 28, in play_animation toy._execute(Animatronic._encode(toy, 5, proc, to_bytes(animation, 2))) File "C:\ProgramData\Anaconda3\lib\site-packages\spherov2\toy\__init__.py", line 85, in _execute return self._wait_packet(packet.id) File "C:\ProgramData\Anaconda3\lib\site-packages\spherov2\toy\__init__.py", line 90, in _wait_packet packet = future.result(timeout) File "C:\ProgramData\Anaconda3\lib\concurrent\futures\_base.py", line 441, in result raise TimeoutError() concurrent.futures._base.TimeoutError
Currently, I'm trying to get this code to run:
from spherov2 import scanner
from spherov2.sphero_edu import SpheroEduAPI
from spherov2.types import Color
toy = scanner.find_toy()
with SpheroEduAPI(toy) as droid:
droid.set_main_led(Color(r=0, g=0, b=255))
while droid.get_acceleration()['z'] < 0.1:
droid.set_main_led(Color(r=255, g=0, b=0))
droid.set_main_led(Color(r=0, g=0, b=255))
However, whenever I run the script, find_toy
seems to work OK but it can't be connected to afterwards.
I get the following error:
Traceback (most recent call last):
File "d:\Libraries\Documents\Programming\sphero-test\biggertest.py", line 7, in <module>
with SpheroEduAPI(bb8) as droid:
File "D:\Libraries\Documents\Programming\sphero-test\.venv\Lib\site-packages\spherov2\sphero_edu.py", line 119, in __enter__
self.__toy.__enter__()
File "D:\Libraries\Documents\Programming\sphero-test\.venv\Lib\site-packages\spherov2\toy\__init__.py", line 54, in __enter__
self.__adapter = self.__adapter_cls(self.address)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Libraries\Documents\Programming\sphero-test\.venv\Lib\site-packages\spherov2\adapter\bleak_adapter.py", line 25, in __init__
self.__execute(self.__device.connect())
File "D:\Libraries\Documents\Programming\sphero-test\.venv\Lib\site-packages\spherov2\adapter\bleak_adapter.py", line 32, in __execute
return asyncio.run_coroutine_threadsafe(coroutine, self.__event_loop).result()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Sigmond\AppData\Local\Programs\Python\Python311\Lib\concurrent\futures\_base.py", line 456, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "C:\Users\Sigmond\AppData\Local\Programs\Python\Python311\Lib\concurrent\futures\_base.py", line 401, in __get_result
raise self._exception
File "D:\Libraries\Documents\Programming\sphero-test\.venv\Lib\site-packages\bleak\__init__.py", line 531, in connect
return await self._backend.connect(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Libraries\Documents\Programming\sphero-test\.venv\Lib\site-packages\bleak\backends\winrt\client.py", line 247, in connect
raise BleakDeviceNotFoundError(
bleak.exc.BleakDeviceNotFoundError: Device with address F6:D4:D3:A0:EF:F7 was not found.
I tried troubleshooting this using BLEConsole.exe
and found some interesting things:
The sphero shows up in the list
command:
BLE: list
#00: BB-EFF7
However, connecting to it will intermittently succeed, but then disconnect after about 20 seconds, or fail outright:
BLE: open #0
Device BB-EFF7 is disconnected.
Connecting to BB-EFF7.
Device #0 is unreachable.
The case where it eventually disconnects is shown here:
BLE: open #0
Device BB-EFF7 is disconnected.
Connecting to BB-EFF7.
Found 6 services:
#00: GenericAccess
#01: GenericAttribute
#02: Custom Service: 22bb746f-2ba0-7554-2d6f-726568705327
#03: Custom Service: 22bb746f-2bb0-7554-2d6f-726568705327
#04: Custom Service: 00001016-d102-11e1-9b23-00025b00a5a5
#05: DeviceInformation
BLE: stat
Device BB-EFF7 is connected.
Available services:
#00: GenericAccess
#01: GenericAttribute
#02: Custom Service: 22bb746f-2ba0-7554-2d6f-726568705327
#03: Custom Service: 22bb746f-2bb0-7554-2d6f-726568705327
#04: Custom Service: 00001016-d102-11e1-9b23-00025b00a5a5
#05: DeviceInformation
BLE: print %mac
F6:D4:D3:A0:EF:F7
BLE: print %name
BB-EFF7
BLE: print %mac
BLE: stat
Device BB-EFF7 is disconnected.
I have enough time to get some information about the device (about ~20 seconds) but then print %mac
doesn't return anything and stat
helpfully informs that it has disconnected.
Thoughts on troubleshooting this?
hello, has IR communication been implemented for sphero in general and bolt in particular? because it doesn't look like it has, I've been digging through the library files and I can't seem to find a way to operate the duo start_ir_broadcast(0,1) on one bolt and start_ir_follow(0,1) on another.
I have tried to get the color sensor working on the Sphero RVR. I can see that the enable_color_detection code (56) is being sent to the RVR but the dictionary data streaming back doesn't contain any "color_detection" data.
Hey, I know it's a bit forgotten but nowadays the Force Bands (which can be used to drive sphero's LE robots like Ollie of BB-8 & Co, and even Mini, with just motion control) are pretty cheap now and I'd like to see at least SOME hacking effort for it seeing how it has a speaker, LED, and could work as a very interesting method of input or maybe even body tracking for, say, VR, by putting two on each leg maybe.
EDIT: I realize the EDU app doesn't support it, but still, maybe by revenging the force band app itself we could figure it out? Plus considering how it can connect to every bot but 1.0/2.0/SPRK and (probably?) RVR, I doubt its protocol is THAT different from the bots themselves.
Hi, just bought a BOLT in the hope my daughter will pick it up to learn some programming. Was hoping to impress her abit more with python scripting... but yeah... I come here begging for help :P
With the below version:
OS: windows 10
Python version: 3.10.4 (IDLE shell)
Bleak: 0.19.0 (and the dependencies)
SPHEROV2: 0.11.4
I faced the below issues:
If there is any pointers or reference for me to look up or debug ... it is much appreciated.
semi-noop :P mostly used matplotlib for my plotting works... IO connectivity is kinda new to me ... like to use this opportunity to learn and improve myself too ... before I try to impress my daughter :>
NB: with the Sphero-Edu app... i can use the BOLT normally, so I am ure it is just the python env issue.
Hey, I was just wanted to check if you'd be interested in a PR to add the option to specify the specific Bluetooth adapter bleak should use?
Hey,
I am trying to connect to the Sphero Bolt using the example code for the EduAPI, but i am getting following error:
Traceback (most recent call last):
File "test.py", line 8, in
with SpheroEduAPI(toy) as api:
File "/home/arcky/.local/lib/python3.8/site-packages/spherov2/sphero_edu.py", line 110, in enter
self.__toy.enter()
File "/home/arcky/.local/lib/python3.8/site-packages/spherov2/toy/init.py", line 54, in enter
self.__adapter.write(uuid, data)
File "/home/arcky/.local/lib/python3.8/site-packages/spherov2/adapter/bleak_adapter.py", line 40, in write
self.__execute(self.__device.write_gatt_char(uuid, data, True))
File "/home/arcky/.local/lib/python3.8/site-packages/spherov2/adapter/bleak_adapter.py", line 26, in __execute
return asyncio.run_coroutine_threadsafe(coroutine, self.__event_loop).result()
File "/usr/lib/python3.8/concurrent/futures/_base.py", line 439, in result
return self.__get_result()
File "/usr/lib/python3.8/concurrent/futures/_base.py", line 388, in __get_result
raise self._exception
File "/home/arcky/.local/lib/python3.8/site-packages/bleak/backends/bluezdbus/client.py", line 756, in write_gatt_char
raise BleakError("Characteristic {0} was not found!".format(char_specifier))
bleak.exc.BleakError: Characteristic 22bb746f-2bbd-7554-2d6f-726568705327 was not found!
here is my code:
import time
from spherov2 import scanner
from spherov2.sphero_edu import SpheroEduAPI
from spherov2.types import Color
toy = scanner.find_toy()
with SpheroEduAPI(toy) as api:
api.set_main_led(Color(r=0, g=0, b=255))
This is similar to #16, but for BB8. I have a BB8 and can control lights and movement, but all sensors read None. It looks like no sensor messages are coming back from the robot. I wouldn't mind hacking it myself if I got a little direction on what might be required. Fixing uuids? Message filters?
Hello!
First of all, I love this repo. As somebody trying to use Sphero robots for research and student projects in academia, mostly using ROS, your Python driver is a godsend. Some time ago, my colleague and I developed a driver for Sphero SPRK+ and a ROS wrapper for it (check it out here), so I know how much work it can be.
I think I found a bug in scanner.py
.
This line returns a generator:
spherov2.py/spherov2/scanner.py
Line 54 in 899e7bd
Once you iterate through "all elements" of the generator here:
spherov2.py/spherov2/scanner.py
Line 61 in 899e7bd
The result is that, by using find_toys
without toy_types
, you can find maximally one toy, if you are lucky. If you are not, and there is some other BLE device nearby that is not Sphero, you will find nothing.
I would recommend simply wrapping line 54 with a list:
toy_types = list(all_toys())
It's not a long list, so there shouldn't be any memory problems.
Hi,
I'm trying to use this library with a Sphero Bolt. I'm on macOS using python 3.10
from spherov2 import scanner
from spherov2.sphero_edu import SpheroEduAPI
toy = scanner.find_toy()
I get the following error:
Exception in callback CentralManagerDelegate.did_discover_peripheral(<CBCentralMan...x600003ff0d80>, <CBPeripheral... disconnected>, {
kCBAdvD...erLevel = 8;
}, -97)
handle: <Handle CentralManagerDelegate.did_discover_peripheral(<CBCentralMan...x600003ff0d80>, <CBPeripheral... disconnected>, {
kCBAdvD...erLevel = 8;
}, -97)>
Traceback (most recent call last):
File "/Users/richard/miniforge3/lib/python3.10/asyncio/events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "/Users/richard/Library/Caches/pypoetry/virtualenvs/spherov2-test-L0-TfrQP-py3.10/lib/python3.10/site-packages/bleak/backends/corebluetooth/CentralManagerDelegate.py", line 265, in did_discover_peripheral
callback(peripheral, advertisementData, RSSI)
File "/Users/richard/Library/Caches/pypoetry/virtualenvs/spherov2-test-L0-TfrQP-py3.10/lib/python3.10/site-packages/bleak/backends/corebluetooth/scanner.py", line 116, in callback
service_uuids = [
File "/Users/richard/Library/Caches/pypoetry/virtualenvs/spherov2-test-L0-TfrQP-py3.10/lib/python3.10/site-packages/bleak/backends/corebluetooth/scanner.py", line 117, in <listcomp>
cb_uuid_to_str(u) for u in a.get("kCBAdvDataServiceUUIDs", [])
File "/Users/richard/Library/Caches/pypoetry/virtualenvs/spherov2-test-L0-TfrQP-py3.10/lib/python3.10/site-packages/bleak/backends/corebluetooth/utils.py", line 19, in cb_uuid_to_str
return normalize_uuid_str(uuid.UUIDString())
File "/Users/richard/Library/Caches/pypoetry/virtualenvs/spherov2-test-L0-TfrQP-py3.10/lib/python3.10/site-packages/bleak/uuids.py", line 1167, in normalize_uuid_str
return str(UUID(uuid))
File "/Users/richard/miniforge3/lib/python3.10/uuid.py", line 177, in __init__
raise ValueError('badly formed hexadecimal UUID string')
ValueError: badly formed hexadecimal UUID string
Great module! Thanks!
The only problem is that I spent some time figuring out this error when I was sending any command:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/pi/.local/lib/python3.7/site-packages/spherov2/sphero_edu.py", line 108, in __enter__
self.__toy.__enter__()
File "/home/pi/.local/lib/python3.7/site-packages/spherov2/toy/__init__.py", line 50, in __enter__
self.__adapter = self.__adapter_cls(self.address)
File "/home/pi/.local/lib/python3.7/site-packages/spherov2/adapter/bleak_adapter.py", line 14, in __init__
self.__device = bleak.BleakClient(address, self.__event_loop, timeout=5.0)
TypeError: __init__() takes 2 positional arguments but 3 were given
It turns out that it works only with bleak==0.6.4 (and probably earlier) while the current version is 0.9.1. Maybe you can mention it somewhere in the description to save time for other folks.
The LED api does not work, error below
File "r2d2_hw1_solution.py", line 157, in <module> api.set_front_led(Color(0, 255, 0)) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/colour.py", line 983, in __init__ color = picker(pick_key(pick_for)) TypeError: 'int' object is not callable
And can you change the input to a common tuple instead of a colour object, the students have to import colour before using this api.
I have tried many times, but I can't find my Sphero 2.0/SPRK. I can successfully connect and control with Sphero edu software, but the author's code will report an error as follows:
line 84, in find_ toy
raise ToyNotFoundError
spherov2.scanner.ToyNotFoundError
I hope to get help. Thank you very much
I get this error when trying to import SpheroEduAPI: TypeError: 'type' object is not subscriptable
. See full output below.
$ python3
Python 3.8.10 (default, May 26 2023, 14:05:08)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from spherov2.sphero_edu import SpheroEduAPI
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ignited/.local/lib/python3.8/site-packages/spherov2/sphero_edu.py", line 83, in <module>
class SpheroEduAPI:
File "/home/ignited/.local/lib/python3.8/site-packages/spherov2/sphero_edu.py", line 414, in SpheroEduAPI
def register_matrix_animation(self, frames:list[list[list[int]]], palette:list[Color], fps:int, transition:bool):
TypeError: 'type' object is not subscriptable
I just installed the spherov2 library today. Any ideas why it's not working?
Hi, thanks to you, I am able to write various codes using sphero :)
I'm trying to create a GUI that can operate sphero like the original sphero game app.
Is there a way to make sphero do different action (roll, change color etc.) every time the user clicks a button consecutively without additional scans (using scanner.find_Mini() function) on the droid once sphero is connected?
I want Sphero to act when I click each action button, not to order the whole action at once.
I'm using Sphero mini, Mac OS, Python 3.8.5.
Thanks in advance!!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.