Open gnbl opened 4 years ago
So I've just seen https://virantha.github.io/bricknil/readme.html#installation and https://virantha.github.io/bricknil/pi_setup.html
I've reinstalled bricknil with sudo and the above error does not occur. However, nothing happens when I spin the front wheels manually.
pi@raspberrypi:~ $ sudo python3 brick.py
started thread for curio
inside curio run loop
INFO:BLE Event Q.0:using bleak
INFO:BLE Event Q.0:Starting scan for UART 00001623-1212-efde-1623-785feabcd123
INFO:BLE Event Q.0:Looking for first matching hub
Awaiting on bleak discover
Done Awaiting on bleak discover
INFO:BLE Event Q.0:checking manufacturer ID for device named Train Base for Train Base
INFO:BLE Event Q.0:found device Train Base
INFO:BLE Event Q.0:Device advertised: {'00001624-1212-efde-1623-785feabcd123': {'UUID': '00001624-1212-efde-1623-785feabcd123', 'Service': '/org/bluez/hci0/dev_18_04_ED_EB_FB_BB/service0009', 'Value': [10, 0, 70, 19, 0, 2, 140, 0, 0, 0], 'Notifying': False, 'Flags': ['write-without-response', 'write', 'notify'], 'WriteAcquired': False, 'NotifyAcquired': False, 'Path': '/org/bluez/hci0/dev_xx_xx_xx_xx_xx_xx/service0009/char000a'}}
INFO:BLE Event Q.0:Connected to device Train Base:xx:xx:xx:xx:xx:xx
INFO:train.5:Waiting for peripheral motor to attach to a port
INFO:train.5:Waiting for peripheral motor to attach to a port
INFO:speed_sensor.3:ASSIGNING PORT 19 on speed_sensor
INFO:train.5:Movement detected: starting...
INFO:train.5:Speed sensor changed speed: 133
INFO:train.5:Speed sensor changed speed: 134
INFO:train.5:Speed sensor changed speed: 135
INFO:train.5:Waiting for peripheral motor to attach to a port
INFO:train.5:Speed sensor changed speed: 0
INFO:train.5:Waiting for peripheral motor to attach to a port
INFO:train.5:Waiting for peripheral motor to attach to a port
INFO:train.5:Waiting for peripheral motor to attach to a port
INFO:train.5:Waiting for peripheral motor to attach to a port
^CTraceback (most recent call last):
File "brick.py", line 70, in <module>
start(system)
File "/usr/local/lib/python3.7/dist-packages/bricknil/bricknil.py", line 214, in start
ble.run()
File "/usr/local/lib/python3.7/dist-packages/bricknil/bleak_interface.py", line 52, in run
self.loop.run_until_complete(self.asyncio_loop())
File "/usr/lib/python3.7/asyncio/base_events.py", line 571, in run_until_complete
self.run_forever()
File "/usr/lib/python3.7/asyncio/base_events.py", line 539, in run_forever
self._run_once()
File "/usr/lib/python3.7/asyncio/base_events.py", line 1739, in _run_once
event_list = self._selector.select(timeout)
File "/usr/lib/python3.7/selectors.py", line 468, in select
fd_event_list = self._selector.poll(timeout, max_ev)
KeyboardInterrupt
INFO:train.5:Waiting for peripheral motor to attach to a port
INFO:train.5:Waiting for peripheral motor to attach to a port
INFO:train.5:Waiting for peripheral motor to attach to a port
^CException ignored in: <module 'threading' from '/usr/lib/python3.7/threading.py'>
Traceback (most recent call last):
File "/usr/lib/python3.7/threading.py", line 1281, in _shutdown
t.join()
File "/usr/lib/python3.7/threading.py", line 1032, in join
self._wait_for_tstate_lock()
File "/usr/lib/python3.7/threading.py", line 1048, in _wait_for_tstate_lock
elif lock.acquire(block, timeout):
KeyboardInterrupt
The sample code says the hub button needs to be pushed, which turns off the train.
INFO:BLE Event Q.0:Connected to device Train Base:xx:xx:xx:xx:xx:xx
INFO:train.5:Waiting for peripheral motor to attach to a port
INFO:train.5:Waiting for peripheral motor to attach to a port
INFO:vision_sensor.1:ASSIGNING PORT 18 on vision_sensor
INFO:speed_sensor.3:ASSIGNING PORT 19 on speed_sensor
INFO:train.5:Waiting for peripheral motor to attach to a port
INFO:train.5:Waiting for peripheral motor to attach to a port
INFO:train.5:Waiting for peripheral motor to attach to a port
Ok so I got it to work once by connecting, shutting down the train when connected, starting the train again. But I can't reproduce.
Got a Bluetooth 4.0 dongle, and it starts working on Windows, although the Bricknil commands seem to be interrupted by the train:
>py -3.7 brick.py
started thread for curio
inside curio run loop
INFO:BLE Event Q.0:using bleak
INFO:BLE Event Q.0:Starting scan for UART 00001623-1212-efde-1623-785feabcd123
INFO:BLE Event Q.0:Looking for first matching hub
Awaiting on bleak discover
Done Awaiting on bleak discover
INFO:BLE Event Q.0:Rescanning for 00001623-1212-efde-1623-785feabcd123 (60 tries left)
Awaiting on bleak discover
Done Awaiting on bleak discover
INFO:BLE Event Q.0:Rescanning for 00001623-1212-efde-1623-785feabcd123 (59 tries left)
Awaiting on bleak discover
Done Awaiting on bleak discover
INFO:BLE Event Q.0:Rescanning for 00001623-1212-efde-1623-785feabcd123 (58 tries left)
Awaiting on bleak discover
Done Awaiting on bleak discover
INFO:BLE Event Q.0:checking manufacturer ID for device named Unknown for Train Base
INFO:BLE Event Q.0:found device Unknown
INFO:BLE Event Q.0:Device advertised: {'00001624-1212-efde-1623-785feabcd123': <Windows.Devices.Bluetooth.GenericAttributeProfile.GattCharacteristic object at 0x03A56650>, '00002a00-0000-1000-8000-00805f9b34fb': <Windows.Devices.Bluetooth.GenericAttributeProfile.GattCharacteristic object at 0x03A56850>, '00002a01-0000-1000-8000-00805f9b34fb': <Windows.Devices.Bluetooth.GenericAttributeProfile.GattCharacteristic object at 0x03A56B30>, '00002a04-0000-1000-8000-00805f9b34fb': <Windows.Devices.Bluetooth.GenericAttributeProfile.GattCharacteristic object at 0x03A565B0>}
INFO:BLE Event Q.0:Connected to device Bluetooth xx:xx:xx:xx:xx:xx:XX:XX:XX:XX:XX:XX
INFO:train.5:Waiting for peripheral motor to attach to a port
INFO:train.5:Waiting for peripheral motor to attach to a port
INFO:motor.4:ASSIGNING PORT 0 on motor
INFO:led.2:ASSIGNING PORT 17 on led
INFO:vision_sensor.1:ASSIGNING PORT 18 on vision_sensor
INFO:speed_sensor.3:ASSIGNING PORT 19 on speed_sensor
INFO:BLE Event Q.0:Waiting for hubs to end
INFO:train.5:Running
INFO:train.5:Please move the train to start the program
INFO:train.5:Movement detected: starting...
INFO:train.5:Speed sensor changed speed: 90
INFO:train.5:Set speed to 0
INFO:motor.4:Setting speed to 0
INFO:train.5:Speed sensor changed speed: 125
INFO:train.5:Speed sensor changed speed: 148
INFO:motor.4:Setting speed to 1
INFO:train.5:Speed sensor changed speed: 4
INFO:train.5:Speed sensor changed speed: 67
INFO:motor.4:Setting speed to 2
INFO:train.5:Speed sensor changed speed: 109
INFO:train.5:Speed sensor changed speed: 137
INFO:motor.4:Setting speed to 3
INFO:train.5:Speed sensor changed speed: 156
INFO:train.5:Speed sensor changed speed: 169
INFO:motor.4:Setting speed to 4
INFO:train.5:Speed sensor changed speed: 0
INFO:motor.4:Setting speed to 5
INFO:motor.4:Setting speed to 6
INFO:motor.4:Setting speed to 7
INFO:motor.4:Setting speed to 8
INFO:motor.4:Setting speed to 9
INFO:motor.4:Setting speed to 10
INFO:motor.4:Setting speed to 11
INFO:motor.4:Setting speed to 12
INFO:motor.4:Setting speed to 13
INFO:motor.4:Setting speed to 14
INFO:motor.4:Setting speed to 15
INFO:motor.4:Setting speed to 16
INFO:motor.4:Setting speed to 17
INFO:motor.4:Setting speed to 18
INFO:motor.4:Setting speed to 20
INFO:motor.4:Setting speed to 20
INFO:train.5:Set speed to 1
INFO:motor.4:Setting speed to 20
INFO:motor.4:Setting speed to 20
INFO:motor.4:Setting speed to 21
INFO:motor.4:Setting speed to 22
INFO:motor.4:Setting speed to 23
INFO:motor.4:Setting speed to 23
INFO:motor.4:Setting speed to 24
INFO:motor.4:Setting speed to 25
INFO:motor.4:Setting speed to 26
INFO:motor.4:Setting speed to 26
INFO:motor.4:Setting speed to 27
INFO:motor.4:Setting speed to 28
INFO:motor.4:Setting speed to 29
INFO:motor.4:Setting speed to 29
INFO:motor.4:Setting speed to 30
INFO:motor.4:Setting speed to 31
INFO:motor.4:Setting speed to 32
INFO:motor.4:Setting speed to 32
INFO:motor.4:Setting speed to 33
INFO:motor.4:Setting speed to 35
INFO:motor.4:Setting speed to 35
INFO:train.5:Set speed to 2
INFO:motor.4:Setting speed to 35
INFO:motor.4:Setting speed to 35
INFO:motor.4:Setting speed to 36
INFO:motor.4:Setting speed to 37
INFO:motor.4:Setting speed to 38
INFO:motor.4:Setting speed to 38
INFO:motor.4:Setting speed to 39
INFO:motor.4:Setting speed to 40
INFO:motor.4:Setting speed to 41
INFO:motor.4:Setting speed to 41
INFO:motor.4:Setting speed to 42
INFO:motor.4:Setting speed to 43
INFO:motor.4:Setting speed to 44
INFO:motor.4:Setting speed to 44
INFO:motor.4:Setting speed to 45
INFO:motor.4:Setting speed to 46
INFO:motor.4:Setting speed to 47
INFO:motor.4:Setting speed to 47
INFO:motor.4:Setting speed to 48
INFO:motor.4:Setting speed to 50
INFO:motor.4:Setting speed to 50
INFO:train.5:Set speed to 3
INFO:motor.4:Setting speed to 50
INFO:motor.4:Setting speed to 50
INFO:motor.4:Setting speed to 51
INFO:motor.4:Setting speed to 52
INFO:motor.4:Setting speed to 53
INFO:motor.4:Setting speed to 53
INFO:motor.4:Setting speed to 54
INFO:motor.4:Setting speed to 55
INFO:motor.4:Setting speed to 56
INFO:motor.4:Setting speed to 56
INFO:motor.4:Setting speed to 57
INFO:motor.4:Setting speed to 58
INFO:motor.4:Setting speed to 59
INFO:motor.4:Setting speed to 59
INFO:motor.4:Setting speed to 60
INFO:motor.4:Setting speed to 61
INFO:motor.4:Setting speed to 62
INFO:motor.4:Setting speed to 62
INFO:motor.4:Setting speed to 63
INFO:motor.4:Setting speed to 65
INFO:motor.4:Setting speed to 65
INFO:train.5:Set speed to 4
INFO:motor.4:Setting speed to 65
INFO:motor.4:Setting speed to 65
INFO:motor.4:Setting speed to 66
INFO:motor.4:Setting speed to 67
INFO:motor.4:Setting speed to 68
INFO:motor.4:Setting speed to 68
INFO:motor.4:Setting speed to 69
INFO:motor.4:Setting speed to 70
INFO:motor.4:Setting speed to 71
INFO:motor.4:Setting speed to 71
INFO:motor.4:Setting speed to 72
INFO:motor.4:Setting speed to 73
INFO:motor.4:Setting speed to 74
INFO:motor.4:Setting speed to 74
INFO:motor.4:Setting speed to 75
INFO:motor.4:Setting speed to 76
INFO:motor.4:Setting speed to 77
INFO:motor.4:Setting speed to 77
INFO:motor.4:Setting speed to 78
INFO:motor.4:Setting speed to 80
INFO:motor.4:Setting speed to 80
INFO:train.5:Done
INFO:BLE Event Q.0:Hubs end
INFO:train.5:Terminating peripheral
INFO:BLE Event Q.0:Terminating and disconnecxting
quitting
INFO:root:quitting
quit
Thanks @gnbl, by following these instructions I was finally able to get an example running on Windows 10.
Summary:
On Windows 10 with the latest Python 3.8.1,
pip3 install bricknil
(following https://virantha.github.io/bricknil/readme.html#installation) fails when installingpythonnet
due to missing dependencywheel
.pip3 install wheel
resolves that, but building fails due toModuleNotFoundError: No module named 'pycparser'
.pip3 install pycparser
solves that, but building fails.Digging deeper:
https://pypi.org/project/pythonnet/#files last wheel release from mid 2019, so Python 3.7 needed, e.g.
https://www.python.org/ftp/python/3.7.6/python-3.7.6.exe
works.
Then, running https://virantha.github.io/bricknil/readme.html#using-the-duplo-train-and-playing-sounds as brick.py:
Google finds this issue and solution: https://github.com/hbldh/bleak/issues/53#issuecomment-473875499
i.e.
%localappdata%\Programs\Python\Python37-32\Scripts\bleak-lescan
runs without error, albeit not giving any output.The bricknil example does not find anything (Android nrF Connect has no issue connecting to the train) and "crashes":
which I cannot quit (CTRL+C or anything else).
So my Bluetooth 4.0 dongle (CSR) and Windows likely are the actual problem.
https://www.lego.com/en-us/service/device-guide/duplo-connected-train
Although BLE is part of Bluetooth since 4.0!?
I'll try this on Linux.
Same error on Timeout in Ubuntu:
error.txt
Issue with bluetooth adapter ("dongle")?
So it seems it's only a Bluetooth 2.0 Dongle and does not support BLE... Argh!
Trying on RPi Zero W with current Raspbian Lite:
Following
https://raspberrypi.stackexchange.com/questions/71333/bluetooth-does-not-work-with-raspbian-stretch-and-raspberry-pi-3
seems to fix the access problem, but there is another Exception: