Learn how to develop code on Raspberry Pi using VSCode without needing VNC or a desktop environment by setting up a remote development environment. Develop your projects more conveniently and efficiently with this powerful tool!
[0:00] We’ve got a few options when developing on the RaspberryPI.
[0:03] We can connect a mouse, keyboard and monitor and treat it like a desktop computer.
[0:07] This is a great option, but it’s not always very convenient.
[0:11] First off you need a spare mouse, a spare keyboard and a spare monitor - And you need
[0:15] the RaspberryPi close enough that you can plug all this together
[0:19] This RaspberryPI is part of my wordle solving robot and it’s connected to my 3D printer.
[0:23] I could plug everything into it, but it’s a bit of a pain and I’d probably end up ripping
[0:27] the sockets off the board.
[0:29] If you don’t have these spare peripherals you can set the PI up in a headless way and
[0:34] connect to it via SSH.
[0:36] Once you’re connected then you’ve got access to vim and nano - I’m quite used to using
[0:40] these for making quick edits, but it’s not the most friendly of editors to use.
[0:44] There are of course more fully functional editors that you can use from the command
[0:48] line, Emacs is particularly powerful.
[0:50] Another option once we’ve got our headless PI up and running and connected to our network
[0:55] is to use VNC - this is quite nice and we get access to the PIs desktop environment.
[1:00] We can then install an IDE like VSCode and crack on with our development.
[1:05] This last option is nice, but it’s still a bit annoying to use and we need to have a
[1:09] desktop environment installed and running on our Pi.
[1:12] In this video, I’m going to present a much nicer alternative that lets you run VSCode
[1:17] as an IDE without needing to use VNC to connect to the Pi’s desktop.
[1:21] But first a quick plug for the channel sponsor PCBWay.
[1:25] Do you like PCBs?
[1:26] Do you want to make a PCB in a weird and wacky colour like purple?
[1:30] Maybe you’d like a flexible PCB
[1:32] Or maybe you’d like someone to do some CNC work for you?
[1:35] Check out the link to PCBWay in the description.
[1:41] First off we’ll do a headless setup of our Pi - this is now trivially easy with the Pi
[1:46] imager app as we can now access the advanced options using this cogwheel icon.
[1:51] This lets set up the hostname, turn on SSH, set the username and password and add the
[1:56] WiFi credentials.
[1:57] When we boot the Pi from the SD Card everything will be set up nicely for us.
[2:03] Now for the magic part of the video.
[2:05] I’m going to open VSCode on my desktop computer and install the “Remote Development” extension pack.
[2:11] With this installed we now get this extra button in the bottom left of the window.
[2:16] If we click on this button we get an option to connect to a host.
[2:20] We just enter the same thing that we would use to connect via SSH - in my case the user
[2:25] is pi and I set up the machine to be on wordle so I just enter pi@wordle and then we enter
[2:32] our password.
[2:33] VSCode will install the VSCode server on the Pi and we’re good to go.
[2:38] I’m going to use my wordle solving robot code as a demonstration project, so I’ll need to
[2:43] clone it from GitHub.
[2:45] We can use the clone from git option in VSCode to do this for us and then we just open up
[2:50] the folder that has been cloned.
[2:52] I’ve got an additional extension that I want to install into my remote environment - this
[2:56] is a python project, so I want to install the python extension.
[3:00] This will also install the extensions for running Jupyter Notebooks.
[3:04] We’re now ready to finish setting up our project on the Pi.
[3:07] I’ll open up a new terminal in VSCode - this automatically opens up a terminal on our Pi
[3:12] in the correct folder.
[3:13] And I’ll just follow the instructions in my README file.
[3:17] There are some native dependencies that I’ll need to install, so we’ll kick that off first.
[3:21] With that done we can install our python dependencies.
[3:25] The first thing I’ll do is create a virtual environment - this keeps our python dependencies
[3:29] nice and local to our project.
[3:31] VSCode should automatically detect that we have a virtual environment and will switch
[3:36] to using it for Python.
[3:38] We then activate this environment in the terminal and install all our Python dependencies.
[3:43] This takes a while as we want Jupyter Notebooks, OpenCV and support for PiCamera.
[3:49] We’re now ready to run our code - I’ll open up the Jupyter Notebook that does the image
[3:54] processing for the wordle robot.
[3:55] We can access the Pi’s camera directly and read images straight from it as all our code
[4:00] is running on the Pi.
[4:02] We can step through each of our notebook cells.
[4:05] And, we can even debug the code and see what’s going on.
[4:10] This is a really nice way of developing code on the Pi - we’ve got access to all the Pi’s
[4:15] hardware so we know immediately if our code will work or not.
[4:18] There are as always some limitations, there’s no support for armv6 so you can’t use this
[4:24] on Pi Zero.
[4:25] But other than that it works really well.
[4:28] Thanks for watching, I hope this was a useful and interesting video - I’ll see you all soon.