5

I've just got access to a 51515 Hub and I tried to connect to it as a serial port (with baudrate 115200), however it's spamming the console with motor/sensor data:

{"m":0,"p":[[62, [11]], [0, []], [0, []], [0, []], [0, []], [0, []], [-30, -9, 1008], [0, 0, 0], [0, 0, 1], "", 12105]}
{"m":0,"p":[[62, [11]], [0, []], [0, []], [0, []], [0, []], [0, []], [-30, -8, 1007], [0, 0, 0], [0, 0, 1], "", 12105]}
{"m":0,"p":[[62, [11]], [0, []], [0, []], [0, []], [0, []], [0, []], [-30, -8, 1006], [0, 0, 0], [0, 0, 1], "", 12105]}
{"m":0,"p":[[62, [11]], [0, []], [0, []], [0, []], [0, []], [0, []], [-30, -8, 1006], [0, 0, 0], [0, 0, 1], "", 12105]}
{"m":0,"p":[[62, [11]], [0, []], [0, []], [0, []], [0, []], [0, []], [-29, -7, 1007], [0, 0, 0], [0, 0, 1], "", 12105]}
{"m":0,"p":[[62, [11]], [0, []], [0, []], [0, []], [0, []], [0, []], [-30, -8, 1007], [0, 0, 0], [0, 0, 1], "", 12105]}

I found a few related posts:

I haven't found any info related to the sensor data which is preventing me from inputting new commands via USB VCP. (My hunch is because I've connected via bluetooth and used the app the getting started exercises).

In this case, what's the easiest way to connect to the hub via USB VCP and use the Python REPL ?

Update I've noticed that I can send Ctrl+C(KeyboardInterrupt) via VCP and with a bit of luck on timing the spam stops and I can type commands prototype directly on the REPL.

I've also tried rshell. Initially, because of my unorthodox Python setup I couldn't run rshell. Even though it didn't get added to PATH I could still run the command manually:

c:\users\george.profenza\.pyenv\pyenv-win\versions\3.6.4-amd64\Scripts\rshell.exe -p COM3
Using buffer-size of 512
Connecting to COM3 (buffer-size 512)...
Trying to connect to REPL  connected
Testing if ubinascii.unhexlify exists ... Y
/ /commands/ /event_loop/ /mindstorms/ /programrunner/ /protocol/ /sounds/ /spike/ /ui/ /hub_runtime.mpy/ /version.py/ /.runtime_hash/ /etc/ /extra_files/ /.extra_files_hash/ /runtime.log/
Setting time ... Feb 05, 2022 01:01:53
Evaluating board_name ... pyboard
Retrieving time epoch ... Jan 01, 2000
Welcome to rshell. Use the exit command to exit rshell.

I could list hub content, but I couldn't figure out how to start a REPL session to type Python commands for the hub to execute directly.

https://lego.github.io/MINDSTORMS-Robot-Inventor-hub-API/pkg_hub.html

1 Answer 1

5

I've used rshell for this. It's available on PyPI, so it can be installed using:

sudo pip3 install rshell

You may need to provide the device to connect to such as:

rshell -p /dev/ttyACM0

To get a Python repl, you can either type repl at the shell on the device, or you can run rshell as:

rshell repl

That gives me an interactive repl without all of the data logging noise that you mentioned.

5
  • Thank you very much for the answer(+1). I did get rshell setup, however I'm missing something: I couldn't run Python ommands in rshell. How would I go about using rshell to type Python commands on my laptop so the hub can executre Feb 6 at 20:59
  • @GeorgeProfenza You should be able to run repl from the shell or run rshell as rshell repl.
    – jncraton
    Feb 6 at 21:42
  • Just had a d'oh moment: there's a repl command :))) Thank you so much! I'll post a follow-up question on how to programmatically send commands to the hub from a computer via VCP. Feb 7 at 9:04
  • Just saw your github repos: OMG! Awesome stuff (e.g. connectiongrammar). robot-inventor-cli is just what I was looking for as my next step. Also, using pyserial without timeout=0 works too. Many thanks! Feb 7 at 13:21
  • @GeorgeProfenza Thanks! I'm glad you got it figured out.
    – jncraton
    Feb 7 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.