Raspberry Pi and Visual Studio Code: A great combination :
With ARM and Linux support, Visual Studio Code is an ideal development tool for the Raspberry Pi, using either its remote development tools to work directly with headless IoT devices, or now. In addition to creating graphical interfaces via web servers such as Node.JS or Python and TKinter, we also have the option to run GUIs that were created by Visul Studio on the Raspberry Pi. These are created via Windows and then made executable on the Raspberry Pi. Not much is needed! Visual Studio Code is totally free but until recently was not available in an official version for the Raspberry Pi. You can find a version in the GitHub projects of Steve Desmond for version 1.28.2, but VSC is already on version 1.50.1 today.
Raspberry Pis are everywhere. From the tiny new Pico microcontroller to the low-cost desktop PC that’s the Raspberry Pi 400, the ARM-based single board computer is a powerful tool that works as well in education as it does as an IoT device. Pis have been to space, track aircraft around the world, manage home media collections, run development Kubernetes clusters, and much more. If it can be done on a computer, it’ll be done on a Pi.
Microsoft’s Visual Studio Code development environment is another of those ubiquitous tools. Like the Pi, it’s everywhere, and is used for nearly everything a developer wants, from learning to code, to building and running large-scale cloud-native applications. It’s for more than Windows, with macOS and Linux versions, and for Intel and ARM processors, with tools for local and remote development.
With ARM and Linux support, Visual Studio Code is an ideal development tool for the Raspberry Pi, using either its remote development tools to work directly with headless IoT devices, or now running a full installation on a Pi hooked up to a keyboard, monitor and mouse. This makes for a flexible combination for both hobbyist and professional alike.
Visual Studio Code: Now on ARM
Microsoft has recently released a version of Visual Studio Code that runs on both ARMv7 and ARM64 Linux devices. With support for 32- and 64-bit ARM code, you can now run Code on both the 32-bit Raspberry Pi OS (recently renamed from Raspbian, as it’s no longer a direct port of Debian) and its 64-bit beta. As the Raspberry https://www.raspberrypi.org/softwarePi 4 hardware supports ARM64, it’s now more attractive for mainstream Linux distributions, and Ubuntu 20.10 now offers an official Raspberry Pi desktop build, targeted at Pi 4 hardware with more than 4GB of memory.
The Linux ARM versions of Visual Studio Code are available in rpm, deb, and tar formats, so should install on most Raspberry Pi Linux releases. There’s even an Ubuntu Snap release, to simplify installing on 20.10. You get the full Electron-based Code editor, with support for the marketplace. Not all extensions are supported, where they need to access external Intel binaries, but most should work.
Visual Studio Code can be a demanding application; with the Electron platform it’s built on needing significant system resources. In many cases your Pi won’t have the horsepower to run the full Code user interface. You might be able to use the new Raspberry Pi 400, which is, at heart, a 4GB Pi 4 built into a keyboard, but we’d recommend using an 8GB Pi 4, with an SSD drive rather than a SD Card, for speed and storage longevity.
I’ve been using a Pi 4 as a Linux desktop, running the ARM release of Ubuntu 20.10, and installed Code on it, downloading it as a 64-bit deb package from Microsoft’s repository. You need to click through the available versions on the Code site, as the ARM64 release isn’t visible from the main screen. However, it’s a quick download that can then be installed using the familiar apt install syntax, although referencing a local deb file rather than searching the various Ubuntu and Debian repositories.
A modular editor for remote development
Another advantage of Visual Studio Code is its modular nature, which has allowed Microsoft to split it into two parts: a user interface and everything else you need to edit, manage, debug, and test code. This allows a copy of Visual Studio Code running on a PC or a Mac to connect securely to a remote device or into a container, download its core components, and edit code directly on the remote device from your PC. You don’t need virtual machines, and you can develop on ARM and Linux without leaving the familiar Windows environment.
Remote access is best considered if you’re using a Pi as an IoT device, and aren’t using a screen, or where it’s resource-limited. Using the open SSH protocol, Visual Studio Code connects to a device and sets up the appropriate secrets needed for a secure connection. Once connected it will download much of the core Code environment, so you can debug and test code directly on your Pi, using Code extensions to manage your application environment and link to source code management services like GitHub. Connections run over the familiar secure SSH protocol, for editing, for file transfer, and for terminal access to a remote device.
A built-in terminal allows you to step outside your editing environment, to test code, to check your logs, or monitor system performance. It’s a useful way of checking code running on a Pi from a remote PC, as well as evaluating commands for use in shell scripts. The terminal can help debug setting up the remote service components on your Pi, using the Output view.
Setting up SSH on a Raspberry Pi
If you’re using Ubuntu on Raspberry Pi, you first need to set up an openssh server to use Visual Studio Code’s remote access tooling. That’s easy enough: just use the built-in package management tools to install the appropriate packages, and then use the Windows command line to ssh to your Pi to set up the appropriate keys. If you see the Raspberry Pi bash prompt, you’re ready to go.
One of my Pis runs as a headless aircraft tracker, with no monitor or keyboard. Here I have used the built-in Raspberry Pi OS (previously known as Raspbian) SSH support. This is easy enough to enable: simply add a blank file called ‘ssh’ to the boot partition of your Raspberry Pi SD card or SSD from your PC before you put the card into the device. It’ll then boot up ready to use SSH. You won’t be able to do this from a booted Pi — it needs to be done from another machine.
Alternatively you can use the Raspberry Pi configuration tool to enable SSH support. Choose Interface Options and enable SSH here. However, you do need to be logged into a Pi to do this, so it won’t work for a headless appliance. In this case, you can quickly plug your Pi into a screen and keyboard to set up SSH before installing the device where you plan on using it.
Code for the Pico in Code :
The Raspberry Pi Foundation’s latest device, the Raspberry Pi Pico microcontroller, is based on its own RP2040 silicon. It’s programmable in MicroPython and C/C++, with Visual Studio Code the preferred development environment for C/C++ applications. It works well with the command-line debugging tools from the RP2040 SDK, using a Raspberry Pi 4 as a development host. Code written and compiled in Code can be debugged on the Pico over a wired connection to your host Pi.
The combination of Raspberry Pi and Visual Studio Code is a powerful one. As Pis have become more capable, they’re now an alternative to desktop PCs in educational environments and a good-quality free code editor turns them into an effective development environment for teaching programming and for building your own IoT applications. Remote development tools mean you can stay in your chosen platform, whether it’s Windows, macOS, or Linux. And if you prefer, you can simply plug a Pi into a keyboard and screen and start coding.
Debugging C/C++ Code on a Raspberry Pi with Visual Studio
So recently I’ve been playing around with Raspberry Pi type Internet of Things (IoT) devices… In my case I’m experimenting with OrangePi Zero and the C.H.I.P. Both of these are way small, way powerful processor headless computers. Sonic unleashed pc download completo gratis. I’m trying to do fun and interesting things using these as control devices for special input/output. One of the things I’m interested in is ultra low latency… that is, an absolute minimal amount of time between user input and computer output.
Visual Studio Code Raspberry Pi 4
I found an interesting article comparing the use of different programming languages to control things on a Raspberry Pi. Basically the guy hooks up an oscilloscope to and I/O pin, and then turns the pin on and off via different programs / shell commands. Its clear from that test, if you want to control things quickly, go to C for the win. So C it is.
I started playing around with code. I started playing around with different hardware. Pixel font maker online.
First go was with the Orange Pi Zero, with Armbian Linux Server Image (Debian Jessie Legacy v 3.4.113 ) First test was to be using simple General Purpose Input/Output (GPIO) to blink some LED’s. It turns out the Orange Pi is a little bit off standard. To get the GPIO to work, we need to use a modified WiringPi library, courtesy of Github and user Zhaolei.
Here’s a photo of the Orange Pi Zero, an add-on shield with extra USB connections, an audio jack, a microphone and an infrared receiver. I also made a couple of LED jumpers for easy blinky I/O testing. In my case I wanted to use the on board microphone and audio jack… they work pretty well.
Let’s talk a little bit about software. With this device, I always planned on a headless installation. Generally my only contact would be thru SSH, either from desktop / laptop (Git Bash Command Line Interpreter) or mobile phone (with either the Termius or WebSSH app.) Coding consists of me writing original in Atom.io, then copying the code and pasting it into .c files via the nano editor. Compilation and shell run commands are run via the SSH tool.
I ALWAYS want a backup copy of the software I’m writing on my laptop/desktop. The only downside is there is no great way to delete a large block of code with nano. Frankly its easier to delete the file and copy/paste new again.
Visual Studio Code Raspberry Pi Remote
SSH Version:
- Setup the remote device. Probably best to see that things are updated, via
$ sudo apt-get update
followed by$ sudo apt-get upgrade
. - Verify Git is installed on the remote device. If not there, add it with
$ sudo apt-get install git-core
- Install the WiringOp (Orange Pi) library, via
$ git clone https://github.com/zhaolei/WiringOP.git -b h3
- Compile that library on the Orange Pi via
$ cd WiringOP
$ chmod +x ./build
$ sudo ./build
- Create a test file at the user directory (~/) via
$ nano GPIO.c
Copy, paste the code from Atom.io. Exit nano, save the file. - Compile the test file…
$ gcc GPIO.c -o GPIO -lwiringPi
The gcc -lwiringPi command links content from the wiringOP library. - Finally run the compiled file via
$ ./GPIO
. If you did this right, you should see some blinking LED’s. Yipee.
So far, so good. Now its about this time, I’m realizing that I will need to be writing some pretty involved programs. And one thing I don’t have is the ability to debug my code interactively in a convenient method. Its about this time in my research that I stumble over this posting, Visual C++ for Linux Development Wow. No, really… Wow. You can use Visual Studio to manage code, keep copy on your laptop/desktop computer, push code to remote device, AND run code in debugger mode. Way cool. The system uses GDB (the GNU DeBugger) to manage the process remotely.
Now at this point, I spent a heck of a long time trying to understand how Visual C++ for Linux development actually worked. I had more than a few problems, and I couldn’t tell if my troubles were based on my custom libraries or my Visual Studio setup. The answer here was to go back to basics, run the thing one step at a time and see that everything worked well. Now my first off-standard was my choice of the Orange Pi Zero. For a Visual Studio proveout, I reverted back to basics, and used a Raspberry Pi Model B. I set up a clean install.
- Clear SD card via SDFormatter tool (Format type = Full, Format size adjustment = On). I used a 16Gb Samsung Evo MicroSD card in holder.
- Download Raspbian Jessie Lite Minimal Image from raspberrypi.org
- Unzip it. Push OS to SD card via Etcher.io
- Update/Upgrade the OS. Add Git (same as above).
- Add the WiringPi library to the remote device per these installation instructions.
$ git clone git://git.drogon.net/wiringPi
$ cd ~/wiringPi
$ ./build
- You can verify the install via
$ gpio readall
which creates a handy pinout identification map.
At this point its time to start up Microsoft Visual Studio. I’m using Visual Studio Community 2015, version 14.0.25431.01 with Update 3.
- You are going to want to download and install the Visual C++ for Linux Development extension.
- Install a few tools on the remote device
$ sudo apt-get install openssh-server g++ gdb gdbserver
- Add a few LED’s to your Raspberry Pi. I added one LED to wiringPi Pin #0 and another to wPi pin #1.
- For me, this added one LED to actual pin 11, GND to pin 9 and one LED to pin 12, GND to pin 6. Verify that you have the LED’s oriented in the correct direction.
- Create a new Project. Select Templates –> Visual C++ –> Cross Platform –> Linux
- For this quick test, select ‘Blink (Raspberry)’. Accept the defaults, with one exception. Give the file name a .c suffix (and not a .cpp suffix)
- You will have to set up the program as a ARM processor program, with a pull down selection in the top menu bar.
- At some point you will have to add login credentials, via (Top Menu) Tools –> Options –> Cross Platform –> Connection Manager.
- You can observe output via (Top Menu) Debug –> Linux Console.
- When you click “Remote GDB Debugger” Visual Studio performs the compilation and execution processes.
Visual Studio creates the following files on the remote device (in this case, my Raspberry Pi). Project = Blink, code = main.c
Monopoly pc board game full version free download. projects directory
Blink directory
bin directory
ARM directory
Debug directory
Blink.out file
obj directory
ARM directory
Debug directory
main.o file
main.c file
And that Blink.out file, it is fully executable via ssh and $ ./Blink.out
. Note that the WiringPi library is located elsewhere on the remote linux device. If you inspect the sample code carefully, you will note two things.
- Right click on the Blink project in the Solution Explorer. Choose Properties –> Linker –> Input. In the block entitled “Library Dependencies” you will note ‘wiringPi’ This is the command line that tells the system to look for that library on the remote device. The files needed are actually located at /usr/local/lib (normally xxx.so files). Note: there is one thing here I wasn’t very happy about. What if you’ve neglected to compile the library files correctly? If you do that, you get an error message “fatal error: wiringPi.h: No such file or directory”. Wait, what? For a missing file on a remote device, that error message seems to be lacking, and probably should be improved. It’s not immediately obvious that the error is for code content on the remote device, instead, you are wondering what you did wrong on the desktop/laptop machine. My recommendation is “fatal error: wiringPi.h: No such file or directory at remote Linux device.” or words to that effect. The folks at Microsoft seem to agree, and as a result of my email to them, they’ve added this to their open issues list.
- The other thing of note on the Blink project is all the notes involving
// LED Pin - wiringPi pin 0 is BCM_GPIO 17.
So in the history of Arduino and Raspberry Pi’s there have been a whole lot of implementations of GPIO pin numbering. The whole WiringPi GPIO thing gives you the chance to custom define different pin schema’s. I will admit for most of us the whole thing is confusing. In this example, its very easy to get pin #0 to function. Starting from the code as written, its way difficult to get pin #1 to function. In this case BCM_GPIO pin #17 = WiringPi pin #0 = physical Pin #11, but what pin is used for WiringPi Pin #1? Hint, it you use the mating BCM_GPIO pin (#18) that is a total fail. Why? Because you have to declare each BCM_GPIO pin special via the Property Pages –> Build Events –> Remote Post-Build Event command. Yes it is important to understand that process, but not, Not, NOT for a beginner exercise. I wasted a good portion of time trying to understand the entire numbering scheme. For 99% of us, its just best to understand our hardware, ssh$ gpio readall
to obtain a pin map for your hardware, and then simply use the WiringPi (wPi) pin numbering.
And heck, to make things easier, I’ll include my beginner approved code sample, RaspberryPiBlink.c (suggest you right click, and save document).
And by the way, just so we don’t forget why we’re using Visual Studio with the Raspberry Pi for programming… with the Gnu Debugger installed we can STEP DEBUG our program on the REMOTE device from within Visual Studio on the laptop/desktop easily. You can see a variable’s content. You can see the order of processing for complex calls. This is way cool, and well worth the tiny bit of extra effort it takes to get everything set up smoothly.