This is the third part of a series of blogs devoted to programming the Raspberry Pi pico:
Adventures with the Raspberry Pi pico - part 1 - Describes setting up the toolchain and building all the examples using the command line
Adventures with the Raspberry Pi pico - part 2 - Tries to understand some of the processes covered in part 1
In this blog I will try and describe the processes necessary to configure and use Visual Studio to build the examples. I have never used VS before and I will be following:
And the official pico getting started guide: https://datasheets.raspberrypi.org/pico/getting-started-with-pico.pdf
The above document has been revised and sections renumbered since I wrote this blog
Getting to Grips with Visual Studio Code
I had already installed and partially configured Visual Studio Code in Part 1, largely following shabaz's blog.
One area of confusion I found was how to actually run VS. Referring to section 8.2.4 EDIT: 9.2.4 in the official pico document, you start it from the Windows Menu:
Windows > Visual Studio 2019 > Developer Command Prompt What it doesn't say, and what I think I found, was that you need to do this in Administrator mode.
When mine starts up, it does so in:
whereas the next instruction in section 8.2.4 EDIT: 9.2.4 is to type:
This requires me to move up the folder tree to C:> before I can enter the command. Is there a way of configuring VS to default to C:> ?
There is a very strong warning:
"If you start Visual Studio code by clicking on its desktop icon, or directly from the Start Menu then the build environment will not be correctly configured. Although this can be done manually later in the CMake Tools Settings, the easiest way to configure the Visual Studio Code environment is just to open it from a Developer Command Prompt Window where these environmental variables are already set."
I had already partiallyconfigured Visual Studio Code in Part 1, flipping between shabaz's blog and and the official pico document, to check each step before acting.
Now I returned to shabaz's blog at this point:
And followed shabz's blog faithfully right up to here:
I didn't click Build, because I had already built all of the examples in part 1, using the command line.
Instead, in the left hand column of files, I clicked on the blink folder, which opened, revealing two files:
I clicked on blink.c and the file opened in the central editor window, as shown below:
I then got very brave and edited the file to change the LED flashing rate:
Note: I have scrolled the edit window down so that that :
Note also that up in the top left hand is a message >OPEN EDITORS 1 UNSAVED, indicating that the edit has not been saved.
Note also the blue bars at line 15 and line 17, which are the lines I have edited.
I wasn't sure how to save the edited file, so I hovered over the white dot next to blink.c in the centre at the top of the screen. I turned into a x and I clicked it to close the file. I then got a message box asking me if I wanted to save the changes. I chose to save.
When I reopened the file the blue bars were still present against lines 15 and 17. Not sure why?
I then noticed this:
Which I think is telling me that I have 1 change to commit to my git repository. Hovering over it, I could read a message box:
Source Control (Ctrl+Shift+G) - 1 pending change
I closed the editor - nothing to save - but there was still a pending change. I clicked on the symbol and got this:
Hovering over the symbols alongside SOURCE CONTROL, I found that the tick represented Commit.
So I clicked it and got a message box relating to "Staged Changes" and asking to make a choice - I chose Always.
I was then asked to provide a message - I put in my initials - and then to press "Enter" to confirm or "Escape" to cancel. I pressed "Enter".
After a few seconds, I got this:
Looks like the commit has worked!
I then clicked on the explorer icon and reverted to the file list. I clicked on blink.c to open the editor and found that the blue lines against lines 15 and 17 have gone. Thus I have learned that the blue bars next to lines in the editor are an indicator of an uncommitted change. Wow!
Building the Modified blink file
Referring again to shabaz's blog:
[all], next to Build, indicates that the whole set of examples will be built
Clicking on [all] opens a dialogue box at the top of the screen. Typing in blink and pressing Enter selects blink as the only one to be built:
Clicking Build now builds the blink example. It didn't take very long. There are quite a few messages. Presumably problems will show up here.
Using Windows File Manager, I navigated to .....pico-examples\build\blink\
Where I found blink.uf2, with today's date and an appropriate time stamp.......Impressive!
I then prepared the pico for flashing - Power up with BOOTSEL button pressed.
RPI-RP2 drive appeared in File manager.
I copied the new blink.uf2 file and pasted it on the the RPI-RP2 drive.
SUCCESS the pico started flashing at the rate I had programmed!
I have learned a lot here, never having used Visual Studio before. It's fairly complicated, certainly when compared with the Arduino IDE (my only previous exposure to a C/C++ type development environment). I am self taught in C/C++ and only know and understand enough of C/C++ to do what I need to do!
- What does the CMakeLists.txt file, alongside the blink.c file, do?
- How do I set up a folder of my own programs, independent of the pico examples.
- Will my own folder automatically be included in git, or do I need to do something.
I hope this will be helpful to anyone who has never used Visual Studio before.