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.