I am trying to execute commands using the -X switch on the Spike Prime Hub but all I get is either nothing, or unknown command errors. Here is what I tried so far:

screen /dev/ttyACM0 -X 'print("test")' screen /dev/ttyACM0 -X $'print("test")/n' screen /dev/ttyACM0 | 'print("test")' screen /dev/ttyACM0 | $'print("test")/n'

The piped commands gave me unknown command errors. When I change the main.py and add some prints, they are shown even if printed before I login. So stream wise that is working no matter when I login.

Another issue occures with the rshell rsync. I had to add a switch to stop the sound files from syncing since they crash rshell. Also rshell stops the code execution on the hub. I tried the above commands before and after rshell rsync call. When I login the hub after rshell I can enter python commands without hitting ctrl+c. Before rsync I have to stop execution with ctrl+c before I am able to type.

But the screen command does not execute python in all cases. Any ideas ?

The main task I want to achieve is that the hub continues execution after rsync. I wanted that with a screen command. But the whole Spike Prime software seems buggy and sluggish from the open source point of view.


With the prime hub you need to exit the hub default process before you can send commands using ctrl-c.

Ctrl-c is the character 0x03.

This is my python script that I use to send micropython scripts over to my hub: https://github.com/gpdaniels/spike-prime/blob/master/simulator/run.py

It has lots of nastyness in it like this:


To try and get the hub to stop the running script and behave.

Also there's functions to read the serial input from the hub until it sees the >>> characters which indicate the REPL is ready to receive python commands.

  • 1
    Wouldn't it be easier to send the script file in a whole with rsync and force the hub to execute it by calling execfile() ? That might be faster because you call sleep(0.1) between every command. Anyway your script is a big help, thanks man. – areop-enap Jan 1 at 22:06
  • The sleeps in my script are just to get the REPL into a good state. I send the whole script using the paste mode of the REPL. After which it is executed in one go. – gpdaniels Jan 8 at 10:51
  • Well, sounds good, but isn't the readline of python reading a file line by line ? Later you pass the file line by line to write_command(...) which then waits for every line 0.2 seconds. Not sure if that might be slow thou, I have to get into the code for a bit longer to clearly understand... – areop-enap Jan 9 at 16:31
  • Yeah there is a lot of delays, rather than spending time on my dodgy code, I'd recommend rshell [ github.com/dhylands/rshell ] which is great! – gpdaniels Jan 11 at 12:03
  • I found that repository already but I didn't know it can execute code on the hub. It's in the pyboard.py file. I still have to figure out how it works but accordingly to the header it shouldn't be that hard. Thanks for your help. Btw I tried to use your run.py to paste a larger code file in one big chunk but it fails after some lines. Seemingly the REPL paste mode cant handle big chunks. I used rsync to copy files to the board already before but wanted copy and execute at once. – areop-enap Jan 11 at 21:39

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.