There are, of course, many options when it comes to editing files. Raspberry Pi’s suggested way of coding for the Raspberry Pi Pico is to use Visual Studio Code. I must admit, I struggled to get on with it. In order to make my life easier, I wanted to use Sublime Text 3, which is what I use for work. Familiarity with your IDE/editor helps a lot when you’re doing something new, so I looked at how I could use it. I’m on Windows, so expect those kind of file paths 🙂 I’m also using CircuitPython which means the Pico presents itself as a drive on your PC (like a Removable Disk).
First steps – direct editing
To start with, I created a Project and added the CIRCUITPY drive to the project. That way, I could see the files on the drive and just edit them.
I experimented for a while and tried to use the serial_monitor plugin to see the device and access the REPL. This plugin, though, doesn’t allow interaction at that level, so I’ve stuck with Putty for now. I have Sublime Text open on one screen and Putty on the other, but if you’ve only got one screen, just split it using Windows’ in-built facility.
Version control using Git / File synchronisation with the Pico
Of course, eventually you’re going to want to keep your code version controlled and backed up on GitHub… right? I mean, you wouldn’t want to just keep it on your Pico and then accidentally lose it? And version control is good, correct? Say “Yes, Mike”. 🙂
Having your repository keyed to be on the Pico itself is pretty bad form, in my opinion. Instead, you need a place for your code off of the Pico. This makes sense – that way if you want to do Git commits and pushes, you can do it from your hard drive, rather than direct from the Pico. But how to keep that “local” code in step with the Pico? That’s where file synchronisation comes in.
I looked at a few options, but what I really wanted was for the file system to be monitored for changes and then the code file(s) that had been changed to be automatically copied onto the Pico. I came across the FSync plugin. It is pretty bare bones, but it does what I want. You’ll need Package Control installed (see here for instructions). First of all, add a repository to Package Control and enter https://github.com/weverss/FSync into the text box. This links your ST3 installation to the specific GitHub for the plugin. Then, install the package by searching for FSync. Restart Sublime Text 3 and the package will be installed and ready.
In your menu, go to Preferences->Package Settings->FSync->Settings – User.
This will open up a blank file.
Now, go to Preferences->Package Settings->FSync->Settings – Default. Copy the whole thing and paste it into your User file and save it.
Now, edit the local_workspace and remote_workspace settings. Set them according to the location of your local folder and your Pico drive. Use / as the path delimited and do not add a trailing /.
Here’s mine:
{ // File extensions list to ignore during sync "ignore_extensions": [".FSync", ".svn-base", "wc.db"] , // WARNING: In both settings below, don't finish directories with '/' // Local directory to work... "local_workspace": "D:/Projects/Raspberry Pi/Pico/Pico Picorder/PicoPicorder (code)", // Remote directory to sync files from local directory ('local_workspace' setting above) "remote_workspace": "E:" // Don't finish it with '/' }
Save it.
Now, what you should find is that each time you save a file in your LOCAL folder, it copies it to the CIRCUITPY drive.
And, because you have now moved your code to a local folder, you can now add it in the usual way to a GitHub repository.
Indentation
Don’t forget to change your Sublime Text 3 indents to “Spaces: 4”. This is at the bottom right of the screen in the grey strip. This is important as all the Adafruit libraries (and, indeed your code!) should use 4 spaces, not a tab character, otherwise you get indentation errors when it runs on the Pico.
Why not use Emacs or Nano as editor…nano is a bit primitive though.
I am not a friend on vi/vim…but will take a long look at them but I have no regard in using line commends to edit a file.
I just like a proper editor with file management etc.
I’m happy with Mu for CircuitPython. The REPL works fine and does graphs. It’s just a bit of a fiddle to double click the name tab if you want to save the file with a suitable name to your PC.
My favorite code editor is Codelobster – https://codelobster.com