Quantcast
Viewing latest article 1
Browse Latest Browse All 18

Emulating a Raspberry Pi on Virtualbox

So I’m working on a lot of posts for Enterprise Manager, but I can’t post them just yet, so here’s some more Raspberry Pi love to keep you busy until then… Image may be NSFW.
Clik here to view.
🙂

Why VBox Raspberry Pi?

Many times I just want to write and test some code, but I want to do it while I’m taking a break from my day to day work-  waiting for a download, in a meeting, a script is running in another window, etc., so it’s convenient to have a Virtualbox image to run Python scripts with all the libraries and modules installed. I can’t simulate my Pibrella card or other add-ons, but I can install the libraries and verify that all my code tests out syntax wise before I run it on the actual Raspi.

Now the “noobs” install of Raspian, (Debian) won’t work for a direct Vbox image.  It’s made for ARM processors and Virtualbox is expecting an OS to support an X86 processor.  This just means we need to be more selective in the OS version that we use, so we’re going to use Ubuntu or other supported platforms for our image, then add the Raspian on top of it. You could use an emulator like Qemu, that emulates the hardware, too, but I just want a simple Vbox image and be done with it.

OVA File Already Built

If you just want to use an Ubuntu image, already built, you can locate that here and that’s what we’ll do for this example-  use the pre-built image and then add what we need to it!

The OVA fill need to be extracted from the bit torrent file using 7Zip or another file management program after it’s been downloaded.

Once this is done, open up Oracle Virtualbox and choose to “import appliance” option with the file, keeping all the defaults.

Image may be NSFW.
Clik here to view.
vbox2

The Username/Password is rpi/password and once you login, open a folder and right click, choose “Open in Terminal”.  You can then change the directory from the default to debian-

cd debian
./launchDebian

Expect some odd errors to come up-  this is normal for this image and can be disregarded.

Image may be NSFW.
Clik here to view.
vbox1

Once the errors complete and the prompt stops at the “Same machine: preferring raw encoding” statement, then go back to your folder and right click again, opening a second terminal.
Type in the following:

xtightvncviewer localhost

Username/password is root/password and you’ll find that you are now working from the Raspberry Pi command line, just as if you were on the machine!

Image may be NSFW.
Clik here to view.
vbox3

Pibrella Module Installation

Installing the Pibrella Libraries are pretty easy.  Just do the installations and you are set.  Start with running the update:

sudo apt-get update

Then run the upgrade:

sudo apt-get upgrade

Image may be NSFW.
Clik here to view.
vbox4

Now, let’s install the Pibrella modules:

sudo apt-get install python-pip
sudo pip install pibrella

Once completed, now I have all the pibrella module installed and can run code. We can run a quick test, too.

vi python_test.py
import pibrella
pibrella.buzzer.fail()
pibrella.light.pulse(0.2)

from sys import exit
exit()

Save the file and then execute it:

sudo python -i pibrella_test.py

No, the lights and buzzer, or button commands won’t work on the simulator, but I can test my code to verify that syntax is correct and get it ready before moving it over to the actual Raspberry Pi!

Python 3 Addition

As most folks know, I’m a Python addict, so I also want to update to Python 3 on this image.

sudo apt-get install python3

Image may be NSFW.
Clik here to view.
vbox5

Now I have everything I need to simulate my Raspberry Pi to run scripts from my PC!

Have a great day and Pi on!



Image may be NSFW.
Clik here to view.
Tags:  ,



You might be interested in this:  

Copyright ©  [Emulating a Raspberry Pi on Virtualbox], All Right Reserved. 2023.

Viewing latest article 1
Browse Latest Browse All 18

Trending Articles