Problem with rshell running a series of commands

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
lclev
Posts: 7
Joined: Fri Nov 15, 2019 7:30 pm

Problem with rshell running a series of commands

Post by lclev » Sat Apr 03, 2021 4:15 am

I am using micropython v. 1.12 and PYB v1.1. connected via usb to raspberry pi 4B with latest version of Raspberry Pi OS.

I can manually enter rshell and then enter repl and then type import mm1 and get the simple program to run ok.
However, if I run the following code, it does'nt work:
$rshell repl ~ import mm1
The error message is: unable to find to find board 'home/pi'
I am using the default name of the board.

Also in the Readme, the code is given as 'rshell.py repl ~ some_command '. Please clarify the rshell.py versus rshell usage.

My ultimate goal is to run a python script on the host computer that will use the subprocess module to run a program on the pyboard that will return some data to the host computer.

Any help would be greatly appreciated!

lcleve

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Problem with rshell running a series of commands

Post by pythoncoder » Sat Apr 03, 2021 3:36 pm

I use pyboard.py for this kind of thing. Perhaps this script might give you some ideas. It prints the name of the attached device. It is called from a Bash script, which picks up the detected device name and builds and loads the appropriate firmware.

Code: Select all

#! /usr/bin/python3
# -*- coding: utf-8 -*-

# Called from buildpyb
# Arg: device (e.g. '/dev/pyboard')

import sys
import os, os.path
mp = os.getenv('MPDIR')
sys.path.append(''.join((mp, '/tools')))
import pyboard

errmsg = 'Usage pyb_check device'
d = {b'PYBv1.1' : 'PYBV11', b'PYBv1.0' : 'PYBV10', b'PYBLITEv1.0' : 'PYBLITEV10',
    b'PYBD-SF2W' : 'PYBD_SF2', b'PYBD-SF3W' : 'PYBD_SF3', b'PYBD-SF6W' : 'PYBD_SF6',
    b'PYBD_SF2W' : 'PYBD_SF2', b'PYBD_SF3W' : 'PYBD_SF3', b'PYBD_SF6W' : 'PYBD_SF6',}

def main():
    if len(sys.argv) < 2:
        print(errmsg, file=sys.stderr)
        sys.exit(1)
    device = sys.argv[1]
    if not os.path.exists(device):
        print('Device {} does not exist'.format(device), file=sys.stderr)
        sys.exit(1)
    pybd = pyboard.Pyboard(device)
    pybd.enter_raw_repl()
    hardware = pybd.exec('import os; print(os.uname()[4].split(' ')[0])').strip()
    pybd.exit_raw_repl()
    if hardware in d:
        print(d[hardware])

if __name__ == "__main__":
    main()
Peter Hinch
Index to my micropython libraries.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Problem with rshell running a series of commands

Post by dhylands » Sat Apr 03, 2021 4:07 pm

lclev wrote:
Sat Apr 03, 2021 4:15 am
I can manually enter rshell and then enter repl and then type import mm1 and get the simple program to run ok.
However, if I run the following code, it does'nt work:
$rshell repl ~ import mm1
The error message is: unable to find to find board 'home/pi'
I am using the default name of the board.
What's happening is that your shell is translating ~ into /home/pi, so what rshell actually sees is:

Code: Select all

rshell repl /home/pi import mm1
I would instead invoke it as:

Code: Select all

rshell repl "~ import mm1"

seaside_motors
Posts: 17
Joined: Thu Mar 25, 2021 4:19 am

Re: Problem with rshell running a series of commands

Post by seaside_motors » Sat Apr 03, 2021 5:55 pm

lclev wrote:
Sat Apr 03, 2021 4:15 am
I am using micropython v. 1.12 and PYB v1.1. connected via usb to raspberry pi 4B with latest version of Raspberry Pi OS.

I can manually enter rshell and then enter repl and then type import mm1 and get the simple program to run ok.
However, if I run the following code, it does'nt work:
$rshell repl ~ import mm1
The error message is: unable to find to find board 'home/pi'
I am using the default name of the board.

Any help would be greatly appreciated!

lcleve
Howdy, I have also just started working with rshell and I was interested in your issue so I was able to get the same errors and how I was able to get my .py script working with rshell.

I tried your same command >rshell repl ~blinkpico.py and got the same error. I then tried, as 'dhylands' suggested >rshell repl "~ import blinkpico.py" and this also produced the same error. It seems whatever you put after rshell repl it is trying to interpret as a board name.

Here is what I did to get my little blink program working:
#first we need to connect to the board
>rshell -p /dev/ttyADM0 (#you don't seem to have an issue connecting to the board)
#lets see whats actually on the board, in this case nothing since I have not actually copied anything to the board.
>ls -l /pyboard (#I was first trying /flash but I figured to use the default board name even though I am running a pico)
#Let us get a program loaded onto the board using the cp command
>cp blinkpico.py /pyboard/blinkpico.py
#Now if you run the list command again you will see the file loaded.
>ls -l /pyboard
156 Apr 3 02:58 blinkpico.py
(#I notice here that the time is not correct, will have to investigate. Not of importance atm)
#Now that we have a program to run lets drop into the repl and make it happen
>repl
Entering REPL. Use Control-X to exit.
>
MicroPython v1.14 on 2021-02-02; Raspberry Pi Pico with RP2040
Type "help()" for more information.
>>>
#Now let us blink that LED!
>>> import blinkpico.py

I hope this was helpful, I myself am just getting started on my micro-python journey so if I can help someone I am happy to do so.

Cheers!

lclev
Posts: 7
Joined: Fri Nov 15, 2019 7:30 pm

Re: Problem with rshell running a series of commands

Post by lclev » Wed Apr 07, 2021 2:04 pm

Thanks to all!

Putting in quotation marks, as suggested by dhylands, worked.

Also using pyboard.py as suggested by pythoncoder worked. Sample code much appreciated.

lcleve

Post Reply