Preparing a virtual development environment for Raspberry Pi GPIO programming — Part I

Cédric Rochefolle
Nov 5 · 5 min read
Raspberry Pi 4B
Raspberry Pi 4B
Raspberry Pi 4B

This end of year, I decided to finally make good use of these Raspberry Pi (RPi) laying around my desk. If you are like most of software/hardware engineer, you get to start a new awesome home project every now and then and it rarely gets finished. So my project is to build an opencv enabled droid controlled by voice, using a RPi.

This series of step by step tutorials will go through:

  • Setting up the build environment (this tutorial and the next one)
  • Creating some libraries to control servos (directly via GPio or through servo-controller via UART)
  • Creating the application that will control wheels and head movement
  • Assembling the body
  • Adding a camera and opencv to recognize faces
  • Adding control with speech recognition

For this tutorial, you will need

  • A laptop/PC with VirtualBox installed
  • A good internet connection

Creating a virtual environment

Whichever the language you chose, I would recommend either a chroot environment (but possibly a lot of command lines to type) or a virtual machine running Raspberry Pi Desktop rather than using your regular desktop.

I’ll go with RPi Desktop on VirtualBox.

  1. Go to https://www.raspberrypi.org/downloads/raspberry-pi-desktop/ and download the latest .iso. Note this is a x86 architecture (at least at the time of writing)
  2. Start VirtualBox and prepare your machine:
    Select Linux as type, Debian (32-bit) as Version (Note: I haven’t tried 64-bit, will post an update when I do)
Create virtual machine
Create virtual machine
Create virtual machine

3. Create Virtual hard disk
Make sure you select at least 15 GB. I selected 20 GB and manually created my partitions. Whatever you do, make sure your / root partition has at least 10 GB.

Create Virtual Hard Disk
Create Virtual Hard Disk
Create Virtual Hard Disk

4. Attach the .iso to the IDE Controller

Attach .iso image
Attach .iso image
Attaching .iso image

5. Installation menu starts

Raspberry Pi Desktop installation menu
Raspberry Pi Desktop installation menu
Raspberry Pi Desktop installation menu

6. I chose the Graphical install

7. The next few screen, select:

  • Keyboard language
  • Guided or manual (see previous note about disk space)
  • Select the disk (there should be only one if you followed this tutorial)
  • Chose your preferred disk partition option
  • Select Continue for Finish partitioning and write changes to disk
  • Select Yes then Continue
  • It will start installing the system
Installer in action
  • If you get an error in this step, click Continue, then select from the menu to run a shell. Once in the shell, type:
cat /var/log/syslog

This should give you some indications why the installation failed. Most common issue is main Virtual Hard Disk too small.

  • You should get to the GRUB screen, select Yes then click Continue
GRUB installation
GRUB installation
GRUB installation
  • Select the main device (most likely /dev/sda)
Device selection fro boot loader
Device selection fro boot loader
Device selection fro boot loader
  • A worrying long phase of pre-seed, be patient a little bit more
Running pre-seed
Running pre-seed
Running pre-seed
  • Your patience should be rewarded with the Installation Complete.
Installation complete
Installation complete
Installation complete
  • Click Continue to clean-up installation packages and rebooting
  • Welcome to Raspbian!
Welcome to Raspbian Desktop
  • Follow the welcome steps to setup language, password and unless your are 100% sure you have enough space on root partition /, do the updates. Otherwise, skip it for now.

Now let’s do a few checks and final tuning

  • Disk space
    Check the space available on the / root part. Open a terminal and type:
df -h /

You should have a few GB available:

Disk space available on /
Disk space available on /
Disk space available on /
  • Updates
    Run the debian commands to update your installation
sudo apt update
sudo apt upgrade -y

Reboot afterwards then clean-up by running in the terminal (this might have no effect if install is already clean):

sudo apt autoremove --purge
  • Screen resolution
    Install VirtualBox guests additions, it will allow better screen resolution, and if you need it:
    - uni/bi-directional clipboard between host and guest
    - sharing disk between host and guest
    To get these, run in the terminal
sudo apt install build-essential module-assistant dkms
sudo m-a prepare
wget https://download.virtualbox.org/virtualbox/6.0.14/VBoxGuestAdditions_6.0.14.iso
sudo mount VBoxGuestAdditions_6.0.14.iso /media/cdrom -o loop
sudo sh /media/cdrom/VBoxLinuxAdditions.run
sudo adduser pi vboxsf

The second command prepares the environment for module updates.

You could skip the download and mounting of the VirtualBox image if you can attach from the VirtualBox directly: from menu Device > Insert Guest Addition CD Image. If you download an image, change the guest addition link to the relevant version.

Installing VirtualBox Guest Additions

This might give an error in a popup, you can safely ignore. Reboot. After that, you can open the guest in full screen, share clipboard, share folder.

Setting up development environment

This will be covered in the next part (link coming soon!)

Cédric Rochefolle

Written by

When not playing with Raspberry Pi, Typescript or web-security, I spend my time enjoying the nice beaches and culinary delights of Thailand.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade