-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try to connect to LEGO HUB #21
Comments
Hi @rasenderhase, I walked through the web page of "LEGO Mindstorms robot inventor set". Yes, it will a big fun if we could connect it to Scratch 3.0 :) My guess is that the LEGO HUB of "robot inventor set" is not compatible to EV3 Intelligent brick. The appearance is different. LED and display look different also. So, I'm afraid that both official scratch-link and pyscrlnk cannot connect the "robot inventor set" to Scratch 3.0. I found a discussion thread to wish that in Scratch discussion forum. Some robot inventor set owners have same wish as yours, but Scratch 3.0 and official scratch-link do not provide the feature. In theory, pyscrlink could be modified to convert the messages from "robot inventor set" as if they are from "EV3 Intelligent brick. If we could do this, Scratch 3.0 would be able to control robot inventor set remotely. Said that, It will need certain amount of engineering effort by robot inventor set owners. |
Hi @kawasaki, |
I tried to use the LEGO BOOST library in scratch 3. Now the output of scratch_link is different:
Do you have an idea? |
Hi, @rasenderhase , it will be some fun to dig into the LEGO HUB :) There are two flavors of bluetooth technologies: "Bluetooth Classic" and "Bluetooth Low Energy or BLE". Lego EV3 uses Bluetooth Classic, and Lego Boost uses "BLE". My first question is which of the two the LEGO HUB of robot inventor set uses. I found a description here. It says that the LEGO HUB uses Bluetooth Classic. (It also notes that Bluetooth Low Energy 4.0 also, then it confuses me. Most likely, LEGO HUB uses Bluetooth Classic.) This means that it is the better to try out with Scratch Extension for Lego EV3, than the Scratch Extension for Lego Boost. I think you can confirm that LEGO HUB uses Bluetooth Classic, using the "info" command on bluetoothctl prompt. Please try the command specifying the device address. If the LEGO HUB is a BLE device, some UUIDs for "Generic Access Profile" or "Generic Attribute Profile" will be printed. If LEGO HUB is a Bluetooth Classic device, I expect those UUIDs not printed. Assuming that LEGO HUB is the Bluetooth Classic device, next question is what is the device class of the LEGO HUB. Looking in the source code of Scratch Extension for EV3, it specifies majorDevceClass = 8, and minorDeviceClass = 1. These numbers are sent from the Scratch Extension to pyscrlink, and passed to constructor of BTThread class. These device class numbers 8 and 1 are used to find out EV3 Intelligent Brick. To find out LEGO HUB, we need to replace these numbers with the correct numbers for LEGO HUB. My guess is that "info" command of the bluetoothctl can be a help again. It will show "Class" attribute. Please try that command for LEGO HUB, and check the "Class" attribute. Once we know the correct numbers, we can tweak the pyscrlink code to make it find the LEGO HUB. These are my thoughts about the next steps to dig in. Wish this helps :) |
Hi @kawasaki , it's been a while ;-) here is the output of info:
|
@rasenderhase Thank you for the info. LEGO HUB has the device class numbers 8 and 4. I will teak the pyscrlink code to make LEGO Hub pretend to be LEGO EV3 (class numbers 8 and 1), hopefully on next Sunday :) |
To try out LEGO Hub connection as LEGO EV3, tweak BTSession device discovery code. When the device name has "LEGO Hub", prented its device class (major/minor=8/4) as LEGO EV3's device class (major/minor=8/1). This is a trial code for the GitHub issue #21. Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
I have done a tweak on the code with the commit 18e0818. It's in dev branch. Can you try that branch on your system? I have no Bluetooth device (I only have BLE device), so the code is completely untested. (I assume you are familiar to git commands and can checkout the dev branch on your system. If that is not the case, please let me know). |
Hi @kawasaki , thanks for all the effort. I replaced the modified script in
Is that correct? The scratch web site doe not find the device. This is the output of
and of
All this doesn't look so helpful. What else can I provide to you? Best regards |
Hi @rasenderhase , thank you for trying the modified code. It is correct that you replaced the file under /home/pi/.local. Another way to try the dev branch is to run pyscrlink/scratch_link.py in the checked out working copy, instead of the scratch_link command. Anyway, your approach should work fine. I suppose you ran the scratch_link command without -d option, Can you try it with -d option? It will output more messages. I wish it will help me to understand what is going on. |
It seems to go into an infinite loop. However sometimes there "flash" some other lines. I tried to capture them:
And from time to time this:
Is that helpful? |
@rasenderhase Thank you for sharing the debug log. Though it does not clarify everything, it is definitely helpful. I found two things from it.
For these two findings, I made another commit 3cf61a1 in the dev branch. It adds more debug print to track session status and discovery work, and add one more code tweak for LEGO Hub. Can you try the dev branch tip? (I expect that I will need to ask you some more trials based on the results.). |
@kawasaki I wll try it. |
@rasenderhase Yeah, you have the device, so your debug can accelerate it, hopefully. Unfortunately, I'm not familiar with python IDE. I'm a rather old guy, and emacs and print debug with python logger library are enough for me. With quick web search, "Spyder" or "Ninja" would be a good one, but I have no experience on them. I'm not sure if pyscrlink on Mac either, since pyscrlink is not aimed for Mac :) pyscrlink uses pybluez for BT devices, and pybluez works on Mac. So BT device handling should work on Mac. However, pyscrlink also depends on bluepy for BLE devices which works only on Linux. Certification handling for Linux users may be different on Mac, and it is another factor which makes me doubt about pyscrlink run on Mac. |
And another try:
Third try:
|
@rasenderhase Thank you for trying the dev branch. According to the log, it looks the pyscrlink is trying to find the LEGO Hub correctly (major/minor = 8/4), but it finds no device. So bluetooth.DeviceDiscoverer API of pybluez does now look working. My idea of next step is to run simple scripts which use pybluez on your system. Let me have some time to write and try them on my system. pybluez has some example scripts. I will check if those are useful to test pybluez on your system. |
HI @rasenderhase It's been a while. Finally, I had some time to work on this. I have attached a simple python script (archived with gzip) to check that LEGO Hub can be detected with PyBluez. |
Hi @kawasaki,
I have got a LEGO HUB from the LEGO Mindstorms robot inventor set. I am not sure if it should connect aswell using the
scratch_link
script. Is it compatible with LEGO HUB?I managed to pair the LEGO HUB using bluetoothctl:
Output from scratch_link:
But Scratch is not finding the device. ("No devices found").
Is the LEGO HUB equal / compatible to LEGO MINDSTORMS EV3?
Thanks for your support :-)
Best regards
Andy
The text was updated successfully, but these errors were encountered: