User avatar
HermannSW
Posts: 4813
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

My 1st time use of Thonny

Fri Mar 12, 2021 11:31 am

I have never used Thonny until today -- I worked with Pico using vi editor (since 1990) and minicom for REPL access.

"thonny" was already installed, and I just followed the 1st two instructions in "4.1 Using Thonny":
https://datasheets.raspberrypi.org/pico ... df#page=28
  1. switch to "Regular Mode." at top right
  2. Select "MicroPython (Raspberry Pi Pico)" at bottom right

Without having written my 1st script with Thonny, I can see two advantages over using minicom for just working with REPL:
  1. nice syntax coloring in "Shell" window
  2. always current display of all global variables at right side

Below animation was created after having flashed today's daily Pico Micropython build (contains "machine.freq()" already):
http://micropython.org/download/rp2-pico/

Demonstration of doubling system clock to 250MHz can nicely be demonstrated by diff of two consecutive microsecond timestamps:
Image
https://github.com/Hermann-SW/memrun
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/en/Raspberry_camera.html

User avatar
jbeale
Posts: 3893
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Running Pico at 250MHz

Sat Mar 13, 2021 12:40 am

Amazing, double the speed! Thanks for letting me know.

Code: Select all

def main():
 a = array.array('L', [0]*6)    # unsigned long int, 4 bytes min.
 a[0] = time.ticks_us()
 a[1] = time.ticks_us()
 a[2] = time.ticks_us()
 a[3] = time.ticks_us()
 a[4] = time.ticks_us()
 a[5] = time.ticks_us()

 for i in range(5):
   print(i+1, a[i+1]-a[i]) # print Delta-T between calls to ticks_us()

# -----------------------------------------
main()
Sure enough, half the elapsed time as before:

Code: Select all

>>> machine.freq()
250000000
>>> %Run -c $EDITOR_CONTENT
1 16
2 6
3 5
4 5
5 6

hippy
Posts: 10923
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: My 1st time use of Thonny

Sat Mar 13, 2021 1:28 pm

HermannSW wrote:
Fri Mar 12, 2021 11:31 am
Without having written my 1st script with Thonny, I can see two advantages over using minicom for just working with REPL:
The big advantage for me is it's an editor and shell. You can edit your file, run it, observe the results, fix the file and run it again. You can even leave it running while editing the file to add the next feature.

Thonny is not 'problem free' but it's more than good enough, suits how I like to work.

User avatar
HermannSW
Posts: 4813
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: My 1st time use of Thonny

Sat Mar 13, 2021 3:50 pm

hippy wrote:
Sat Mar 13, 2021 1:28 pm
HermannSW wrote:
Fri Mar 12, 2021 11:31 am
Without having written my 1st script with Thonny, I can see two advantages over using minicom for just working with REPL:
The big advantage for me is it's an editor and shell. You can edit your file, run it, observe the results, fix the file and run it again. You can even leave it running while editing the file to add the next feature.
Nice, just tried that, wrote a snippet with "while True:" loop printing something and then sleep a second.
Pressing run button I got asked where to store the file, and chose Pico.
Then the script started and runs.
While running I changed what to print, and without saving, pressed run button.
Immediately the new version did run, nice.
https://github.com/Hermann-SW/memrun
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/en/Raspberry_camera.html

hippy
Posts: 10923
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: My 1st time use of Thonny

Mon Mar 15, 2021 7:14 pm

I have now started to use Thonny to edit and test Python code which will become built-in for my MicroPython builds. That is, files which live in '.../ports/rp2/modules' or replicated ports.

That's been a Quad-Burger of delight for me while writing my Pico Packet Sniffer. The Python code is where it needs to be when built-in for MicroPython. I can edit it within a reasonable GUI IDE. I can click Run to test it live on my Pico And I can click the Save icon and run it with normal Python from the Pi's command line.

I guess, as a an extra topping, I could use Thonny to run and debug the code when running on the Pi but not sure if that will work ( it needs 'sudo', or attempts to auto-escalate privileges ) and it's always a risk having two copies of the same source open for editing.

I am quite liking Thonny as an IDE, especially its simplicity of use. That 'View->Outline' window is very handy for larger programs.

There are a few things I would add ... ability to use two-space indentation - using four-space is the only real PITA I've encountered, Toolbar icons for Save to File/Pico/Both so it's easy to keep a disk backup, and a 'Save Snapshot' to make it easier to revert when making changes and royally screwing those up - I have never liked IDE's which auto-save on Run.

I had never used Thonny before I started coding for the Pico. I guess I didn't know what I was missing.

Return to “MicroPython”