I am at a loss of how to get started??

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
seaside_motors
Posts: 17
Joined: Thu Mar 25, 2021 4:19 am

I am at a loss of how to get started??

Post by seaside_motors » Fri Apr 02, 2021 2:10 am

Need a little help here, not sure I seem to be understanding how to do this whole Micropython thing.

So I have a Rpi Pico, I have it connected to the pc, I have downloaded the UF2 file, held the boot select button and plugged it in. It shows up on the desktop, I drag and drop the file on it and it disappears. I can then go into Thonny and I can connect to the pico. I can write a basic script to flash the led. That is all fine and dandy.

But I want to interface with it directly, I want to be able to bring up the repl in my terminal window, I want to be able to use my text editor, write a file and send it directly to the pico.

If I use screen /dev/ttyADM0 it will simply bring up a simple blinking cursor. No keyboard input works, control C won't break break, nothing, just a forever blinking cursor on a totally blank screen. If I terminate the terminal then try it again it will error and say device not available and say screen terminated. At this point I have to unplug it and plug it back in.

I can reopen thonny and its there and I can get a repl and run a script. I want to be able to interface directly with the device and not have to go through a IDE.

Running Linux. I have tried looking in the docs but I don't see any simple how to guide, perhaps I am missing something, perhaps I am thinking wrong headed about all of this?? I obviously have zero experience with programming or micro-controllers.


Thanks,
Robert

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: I am at a loss of how to get started??

Post by davef » Fri Apr 02, 2021 3:28 am

In Linux terminal:

Code: Select all

rshell -p /dev/ttyUSB0 --editor nano --buffer-size=30 -a
and tell us what happens.

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

Re: I am at a loss of how to get started??

Post by seaside_motors » Fri Apr 02, 2021 2:54 pm

You assume I have rshell installed, I don't so it is a invalid command. I am on debian so I tried a sudo apt install rshell that failed. I found it on github and used gh repo clone dhylands/rshell which showed it as installing but when I again try rshell it just returns a invalid command.

I will admit I am new to github and do not have a full understanding of how it works so its possible it did not actually install anything and simply made a link to the repository and nothing more??

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: I am at a loss of how to get started??

Post by davef » Fri Apr 02, 2021 6:17 pm

Code: Select all

sudo apt-get install python3-pip
then

Code: Select all

sudo pip3 install rshell

User avatar
scruss
Posts: 360
Joined: Sat Aug 12, 2017 2:27 pm
Location: Toronto, Canada
Contact:

Re: I am at a loss of how to get started??

Post by scruss » Fri Apr 02, 2021 9:52 pm

seaside_motors wrote:
Fri Apr 02, 2021 2:10 am
Running Linux. I have tried looking in the docs but I don't see any simple how to guide, perhaps I am missing something, perhaps I am thinking wrong headed about all of this?? I obviously have zero experience with programming or micro-controllers.
Have you seen Get Started with MicroPython on Raspberry Pi Pico? It's meant for beginners.
But I want to interface with it directly, I want to be able to bring up the repl in my terminal window, I want to be able to use my text editor, write a file and send it directly to the pico.
Unless there's an accessibility reason, if you've got zero experience with programming or micro-controllers, I strongly recommend you use the Thonny IDE. It makes development so much easier. Thonny's a decent editor, too: I've been programming since the '80s and Thonny cuts out a whole load of complex stuff I no longer have the energy to remember. No point in suffering on the command line these days unless you really want to.

If you do go the rshell route, though, use /dev/ttyACM0 instead of /dev/ttyUSB0

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

Re: I am at a loss of how to get started??

Post by seaside_motors » Fri Apr 02, 2021 10:45 pm

davef wrote:
Fri Apr 02, 2021 6:17 pm

Code: Select all

sudo apt-get install python3-pip
then

Code: Select all

sudo pip3 install rshell
Ok so quick update. I realized I had not actually downloaded micropython to my computer so I grabbed the latest tar ball and got it all decompressed and the micropython directory is in my /home/robert/ directory. So that is done. I also have the latest version of Python and pip installed so the >sudo pip3 install rshell was a success.

I am also aware of the /dev/ttyACM0 link, but big thanks for verifying.

In regards to the actual micropython directory, does it need to be in /usr/lib or /usr/share ??

I am appreciative to all of you good folks helping me get started in the right direction. I will update on my rshell adventures soon :)

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

Re: I am at a loss of how to get started??

Post by seaside_motors » Fri Apr 02, 2021 10:52 pm

Not sure if this is working correctly or not?
(I am trying guys, so bare with me, thanks)

robert@mountain-cabin:~/micropython-1.14$ rshell -p /dev/ttyACM0
Using buffer-size of 128
Connecting to /dev/ttyACM0 (buffer-size 128)...
Trying to connect to REPL connected
Retrieving sysname ... rp2
Testing if ubinascii.unhexlify exists ... Y
Retrieving root directories ...
Setting time ... Apr 02, 2021 15:48:15
Evaluating board_name ... pyboard
Retrieving time epoch ... Jan 01, 1970
Welcome to rshell. Use Control-D (or the exit command) to exit rshell.
/home/robert/micropython-1.14>

So it appears to be connecting but it is simply giving me the command prompt in very same directory I started from? Also notice it says the board name is pyboard and the time is Jan 01, 1970. Thats only about 6 months older then I am, LOL!

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

Re: I am at a loss of how to get started??

Post by seaside_motors » Fri Apr 02, 2021 11:03 pm

This did not work, doh!

robert@mountain-cabin:~$ rshell -p /dev/ttyACM0 -f blinkpico.py
Using buffer-size of 128
Connecting to /dev/ttyACM0 (buffer-size 128)...
Trying to connect to REPL connected
Retrieving sysname ... rp2
Testing if ubinascii.unhexlify exists ... Y
Retrieving root directories ...
Setting time ... Apr 02, 2021 16:02:26
Evaluating board_name ... pyboard
Retrieving time epoch ... Jan 01, 1970
Unrecognized command: import machine
Unrecognized command: import time
Unrecognized command: pin = machine.Pin(25, machine.Pin.OUT)
Unrecognized command: while True:
Unrecognized command: pin.value(1)
Unrecognized command: time.sleep(.225)
Unrecognized command: pin.value(0)
Unrecognized command: time.sleep(.225)
robert@mountain-cabin:~$
Last edited by seaside_motors on Fri Apr 02, 2021 11:33 pm, edited 1 time in total.

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

Re: I am at a loss of how to get started??

Post by seaside_motors » Fri Apr 02, 2021 11:19 pm

Hey Robert, so if your trying to access the repl, why don't you just type >repl ?

Duh, knuckle head! :oops:

robert@mountain-cabin:~$ rshell -p /dev/ttyACM0
Using buffer-size of 128
Connecting to /dev/ttyACM0 (buffer-size 128)...
Trying to connect to REPL connected
Retrieving sysname ... rp2
Testing if ubinascii.unhexlify exists ... Y
Retrieving root directories ...
Setting time ... Apr 02, 2021 16:17:58
Evaluating board_name ... pyboard
Retrieving time epoch ... Jan 01, 1970
Welcome to rshell. Use Control-D (or the exit command) to exit rshell.
/home/robert> 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.
>>>
>>>

Ok, my next big question is how do I import my blinkpico.py file and run it from the repl?

I know, doing this the hard way, but its how us old knuckle heads learn :mrgreen:
Last edited by seaside_motors on Fri Apr 02, 2021 11:33 pm, edited 1 time in total.

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

Re: I am at a loss of how to get started??

Post by seaside_motors » Fri Apr 02, 2021 11:31 pm

Ok, so I was able to open another shell tab and >cat blinkpico.py and copy the contents. Then in the repl I was able to enter 'paste' mode (^E) and paste the program in and use ^D and viola, blinky pico!


>>>
paste mode; Ctrl-C to cancel, Ctrl-D to finish
=== import machine
=== import time
=== pin = machine.Pin(25, machine.Pin.OUT)
=== while True:
=== pin.value(1)
=== time.sleep(.225)
=== pin.value(0)
=== time.sleep(.225)
===

I am going to just let this little guy blink for awhile in victory while I celebrate with a Friday afternoon beer! Cheers! :D

One more question, How do I actually just upload the file straight into memory and execute?
Using python3 I would simply use the command >python3 <filename.py> and it would open a repl and execute the program. I made some progress here today guys and I am pretty happy about that so thank you for taking the time to help.

Post Reply