0% found this document useful (0 votes)
20 views9 pages

Practical 5C - Emulator

Uploaded by

black hello
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views9 pages

Practical 5C - Emulator

Uploaded by

black hello
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

BAIT2123 INTERNET OF THINGS Jul 2024

Practical 3 Emulator

During the COVID 19 pandemic period, students may not be able to have a physical embedded
system (i.e., Raspberry Pi set, GrovePi, sensors, indicators and actuators) to work at home.
Hence, we advise students to go through an Emulator using a virtual machine (VM) with fake
devices libraries to simulate the actual practical works.

Take note that the provided libraries were developed by online resources and lecturers efforts
and it would be updated from time to time, based on the needs of practical usage and creative
ideas by students.

Ref: https://www.bluetin.io/raspberry-pi-raspbian-virtual-machine/

Please go through the following steps to initialize the virtual embedded system.

Step 1: Download the Oracle VirtualBox 6.1.XX for Windows Host (you can choose based on
your operating system) and install it.

https://www.virtualbox.org/wiki/Downloads

Step 2: Download the Raspberry Pi ISO image (i.e., Raspberry Pi Desktop). It is about 3 GB,
and takes some time to download.

https://www.raspberrypi.org/software/raspberry-pi-desktop/

Step 3: Launch Oracle VM VirtualBox Manager and Click New to create a new VM.

Step 4: Give a Name for your VM, choose Linux Debian 32-bit (that is exactly what Raspbian is),
give a 4 GB Memory size to create a new virtual hard disk now, then click “Create”.
BAIT2123 INTERNET OF THINGS Jul 2024

Step 5: Choose a file location (a drive that is big enough) for locating your virtual hard disk.
Let’s make the hard disk size (file size) to be the same as our Raspberry Pi SD card, i.e., 32
GB, and choose dynamically allocated if you have a hard disk size constraint. Then click
“Create”

Step 6: Now the new VM is created. Select it and click “Start” to load it.

Step 7: Select the start-up disk by pointing the optical disk selector (Add) to our downloaded Pi
ISO Image.
BAIT2123 INTERNET OF THINGS Jul 2024

Step 8: Choose the Debian GNU / Linux i386 installation with


Run with persistence: You may have a quick start to load Pi, but unable to save any content
after shutdown.
Graphical install: You may be able to reload the same Pi image with an installed Pi OS, but it
takes a while for the installation process (follow the steps below).

Select the American English Keyboard, Partition of the virtual disk according to the default
selection (select Yes to allow the partitioning process), and continue the installation process.
BAIT2123 INTERNET OF THINGS Jul 2024

Step 9: Select the only partition for GRUB boot loader and continue the installation.
BAIT2123 INTERNET OF THINGS Jul 2024

Step 10: After loading the Pi image, the Welcome page will appear. Click Next and select
Country: Malaysia with “Use English Language” and “Use US Keyboard”. Then Click Next, and
you may ignore the password resetting by clicking Next.

Step 11: Skip the Update Software and click Done. Remember you may NOT type the three
sudo apt-get update / upgrade / dist-upgrade because the Pi ISO image may not support the
latest raspbian repositories. It is okay to keep it as the current version to proceed to our practical
work.

Optional (For sharing document between Virtual Machine and Windows 10


Step 12: If you prefer to set up a shared folder in between a local machine (Windows 10) and
Virtual Machine (Pi) for file transfer purposes, kindly refer to the following steps. Else, you may
use the Virtual Machine (Pi) to retrieve files from the Internet via Chromium browser.

To set up the shared folder, we may need to enable Dynamic Kernel Module Support (DKMS)
features in Virtual Machine (Pi). In our terminal, type:

sudo apt install build-essential module-assistant dkms


sudo m-a prepare

After that, insert a Guest Additions CD images from the virtual box > Devices and click Cancel
after the CD image is inserted.
BAIT2123 INTERNET OF THINGS Jul 2024

In the terminal, type the following (to run VBOX installation) and reboot:
sudo sh /media/cdrom/VBoxLinuxAdditions.run
reboot

After reboot, you may see a new mount icon, sf_Desktop (shared folder Desktop). If it doesn’t
exist, kindly check the virtualbox > Devices > Shared Folders > Shared Folder Setting, to see if
you have a Machine Folder shared.

In terminal, type the following (enable the accessibility of shared folder) and reboot:
sudo usermod -aG vboxsf $(whoami)
sudo systemctl restart vboxadd-service.service

After reboot, you should be able to access your machine Desktop folder from the Pi
* The shared folder content is not updated in real-time.
* Do the similar step to enable other shared folder access if needed.
BAIT2123 INTERNET OF THINGS Jul 2024

Step 13: Download the FakeDevices-master.zip, unzip it and locate all the files at your working
folder (follow the instruction from any other practical document).

Step 14: For example, we use /home/pi/Test as our working directory

Launch the Python IDE (Geany Programmer’s Editor)

Save it as test.py under the working directory

In Python IDE, selecting MenuBar > Build > Set Build Commands
BAIT2123 INTERNET OF THINGS Jul 2024

Update the Python Command > Compile > python3 , Execute Command > Execute > python3
Find the way to look for “OK” button and press it [MUST DO]

In the terminal, type the following to install some packages:


pip3 install sounddevice
sudo apt-get install libportaudio2

* If you face an error indication: fatal error: ffi.h: No such file or directory

You may have to first install libffi-dev, so run:


sudo apt-get install libffi-dev
BAIT2123 INTERNET OF THINGS Jul 2024

In any practical codes, as shown as below:

Add in the necessary lines:


form FakeDevices import *
gui = Gui()
gui.add(ANYCOMPONENTS)

Enjoy exploring the Raspberry Pi work with FakeDevices library.

* Special credits to Dr. Poh Tze Ven, for preparing the FakeDevices library.

You might also like