<p>I've used <a href="https://github.com/dhylands/rshell" rel="nofollow noreferrer">rshell</a> for this. It's available on PyPI, so it can be installed using:</p>
<pre><code>sudo pip3 install rshell
</code></pre>
<p>You may need to provide the device to connect to such as:</p>
<pre><code>rshell -p /dev/ttyACM0
</code></pre>
<p>To get a Python repl, you can either type <code>repl</code> at the shell on the device, or you can run rshell as:</p>
<pre><code>rshell repl
</code></pre>
<p>That gives me an interactive repl without all of the data logging noise that you mentioned.</p>

CC BY-SA 4.0
2022-02-06T20:59:35.983Z
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
George Profenza
CC BY-SA 4.0
2022-02-06T21:42:07.633Z
@GeorgeProfenza You should be able to run `repl` from the shell or run rshell as `rshell repl`.
jncraton
CC BY-SA 4.0
2022-02-07T09:04:02.207Z
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.
George Profenza
CC BY-SA 4.0
2022-02-07T13:21:02.000Z
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!
George Profenza
CC BY-SA 4.0
2022-02-07T17:22:09.860Z
@GeorgeProfenza Thanks! I'm glad you got it figured out.
jncraton
CC BY-SA 4.0
2022-02-04T23:30:38.777Z
2022-02-06T21:41:36.620Z
2022-02-06T21:41:36.620Z
jncraton
<p>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:</p>
<pre><code>{&quot;m&quot;:0,&quot;p&quot;:[[62, [11]], [0, []], [0, []], [0, []], [0, []], [0, []], [-30, -9, 1008], [0, 0, 0], [0, 0, 1], &quot;&quot;, 12105]}
{&quot;m&quot;:0,&quot;p&quot;:[[62, [11]], [0, []], [0, []], [0, []], [0, []], [0, []], [-30, -8, 1007], [0, 0, 0], [0, 0, 1], &quot;&quot;, 12105]}
{&quot;m&quot;:0,&quot;p&quot;:[[62, [11]], [0, []], [0, []], [0, []], [0, []], [0, []], [-30, -8, 1006], [0, 0, 0], [0, 0, 1], &quot;&quot;, 12105]}
{&quot;m&quot;:0,&quot;p&quot;:[[62, [11]], [0, []], [0, []], [0, []], [0, []], [0, []], [-30, -8, 1006], [0, 0, 0], [0, 0, 1], &quot;&quot;, 12105]}
{&quot;m&quot;:0,&quot;p&quot;:[[62, [11]], [0, []], [0, []], [0, []], [0, []], [0, []], [-29, -7, 1007], [0, 0, 0], [0, 0, 1], &quot;&quot;, 12105]}
{&quot;m&quot;:0,&quot;p&quot;:[[62, [11]], [0, []], [0, []], [0, []], [0, []], [0, []], [-30, -8, 1007], [0, 0, 0], [0, 0, 1], &quot;&quot;, 12105]}
</code></pre>
<p>I found a few related posts:</p>
<ul>
<li><a href="https://bricks.stackexchange.com/questions/15731/spike-prime-remote-command-using-screen/15733#15733">Spike Prime remote command using screen</a></li>
<li><a href="https://www.reddit.com/r/mindstorms/comments/jyixxc/ive_figured_out_how_to_access_the_spikemindstorms/" rel="nofollow noreferrer">I've figured out how to access the Spike/Mindstorms 51515 hub serial ports (bluetooth and usb) from python</a></li>
</ul>
<p>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).</p>
<p>In this case, what's the easiest way to connect to the hub via USB VCP and use the Python REPL ?</p>
<p><strong>Update</strong>
I've noticed that I can send <code>Ctrl+C</code>(KeyboardInterrupt) via VCP and with a bit of luck on timing the spam stops and I can type commands prototype directly on the REPL.</p>
<p>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 <code>PATH</code> I could still run the command manually:</p>
<pre><code>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.
</code></pre>
<p>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.</p>
<p><a href="https://lego.github.io/MINDSTORMS-Robot-Inventor-hub-API/pkg_hub.html" rel="nofollow noreferrer">https://lego.github.io/MINDSTORMS-Robot-Inventor-hub-API/pkg_hub.html</a></p>

<programming><spike-prime><micropython>
How to use REPL on the 51515 hub?
George Profenza
# How to use REPL on the 51515 hub?

(Asked by: username_0 on 2022-02-04)

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:

Spike Prime remote command using screen
I've figured out how to access the Spike/Mindstorms 51515 hub serial ports (bluetooth and usb) from python

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

**Tags:** programming, spike-prime, micropython


---

## 1 answers

### Answer by username_1 on 2022-02-04. Score: 6 | Accepted answer

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.

> **Comments:**
> **username_0**: 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  
> **username_1**: @GeorgeProfenza You should be able to run `repl` from the shell or run rshell as `rshell repl`.  
> **username_0**: 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.  
> **username_0**: 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!  
> **username_1**: @GeorgeProfenza Thanks! I'm glad you got it figured out.  

---

