(Nelson Newman) Raspberry Pi 4 Projects User Guide PDF
(Nelson Newman) Raspberry Pi 4 Projects User Guide PDF
Guide
Nelson Newman
Copyright 2019 © Nelson Newman
1
The creation of a portal to get your guest Wi-Fi-
powered.
And many more.
This book will guide you through on how to make the best
use of your Raspberry Pi 4 device with major ideas that will
help you in getting the most of your Raspberry Pi 4 device.
The Raspbian is specifically designed to run on the
Raspberry Pi and this is based on Debian Linux. The
Raspberry Pi 4 has the Raspbian pre-installed on it and
ready to use as soon as it’s purchased.
3
In a situation where you are using the wireless
network with your Raspberry Pi, mere clicking the
Cancel button might not result in the closing of the
Welcome Wizard; you might be required to answer
at least some first set of questions before the wizard
closes.
After closing the Welcome Wizard, select the Next
button.
After selecting the Next button, you will be
prompted with a drop-down box coming up in turns
which will require you to select your country,
language as well as time zone from the lists.
You are required to click on the checkbox if you are
using the US-layout keyboard, to ensure that
Raspbian is making use of the correct keyboard
layout.
Clicks on the “Use English language” checkbox to
select it, to make your desktop, as well as programs,
appear in English irrespective of the native language
of your country.
Select “Next” when you are done.
4
For security reasons, the next page that appears will
prompt you to alter the password for the “pi” user
from the default “raspberry.” You are advised to do
this to keep your device from intruders by using
your own password in the boxes as shown below.
Click on the checkbox next to the “Hide
characters” option to show the passwords to help
you confirm what you type in and they must be the
same for both boxes.
Select “Next” when you are done.
5
You will be prompted to select your preferred Wi-Fi
network from the list on the next screen that comes
up.
With the use of your mouse or keyboard, scroll
down the networks’ list and search for the name of
your network to select it and click Next afterward.
In a situation where you are using a secured Wi-Fi
network, you will be required to produce the
password which is also referred to as the pre-shared
key. It is to be noted that you will normally find this
on the card with the router or go check below the
router itself.
To get connected to the network, select Next and
you can select Skip in a situation whereby you are
not connecting to a wireless network.
6
Set up continues:
7
At the final screen of the Welcome message, wizard
will come up with just a few tasks to be done. It is to
be noted that changes made during the setup
process will get activated only after you must have
restarted your Raspberry Pi.
Select the Reboot button to get your Raspberry Pi
restarted, if prompted to do so. After the restart, the
Welcome Wizard will not show up this time and
your Raspberry Pi will be ready for use.
8
Chapter 2: Get Started With the
Chromium Web Browser
1. Load the Chromium browser to start up with practicing
the use of your Raspberry Pi.
2. Go to the top left and click on the raspberry icon to
display the menu.
3. Select the internet category using your mouse pointer.
4. Select the Chromium web browser to get it loaded.
10
ii. Type in a website address and tap the ENTER key on
your keyboard. This will load the website.
iii. Several tabs might come up at the top of the
window if you are loading chromium for the first time.
iv. To go to a different tab, select the tab in question.
v. Click on the cross icon which is located at the right-
hand edge of the tab you like to close, to get it closed.
vi. Click on the tab button located at the right of the
last tab on the list to open a new tab alternatively, you can
have the CTRL key on the keyboard held down and press
the “T” key before releasing your finger on the CTRL.
vii. As soon as you are done exploring your Chromium
web browser, click on the close button which is located at
the top right of the window.
11
Chapter 3: The Libreoffice
Productivity Suite in Raspberry Pi 4
Other examples of productivity suite are the Microsoft
Office and Google docs.
12
Apart from the ability to write documents using a
word processor,
LibreOffice can also be used in getting them
formatted by making use of options like font style,
color, add effects, size as well as inserting tables,
pictures, charts including other content. With the
use of the word processor, you can also check for
mistakes, getting spelling highlighted with red as
well as checking with grammar issues highlighted
with green.
Get started by writing a paragraph as regards what
you have learned so far on the Raspberry Pi
including its software. Go to the top of the window
to experiment with different icons and see what
they can do, check to see if you can perform some
simple actions like enlarging your writing, changing
your color.
Hover your mouse pointer over each icon will help
in displaying the tooltips to be sure of what they do.
When you are done, click on the File menu and
select the Save option to get your work saved. You
will be prompted to give it a name and then click on
the Save button.
13
Apart from the LibreOffice Writer, other parts of the
LibreOffice productivity suite that can be found in the
office menu category just like the Writer include:
14
LibreOffice Math: This is a formula editor tool used for
creating mathematical formulae that are properly
formatted which are usable as well in other documents.
GETTING HELP
15
It is, however, important to note that an internet
connection will be required to make use of the
recommended software tool, therefore, you need to make
sure your Raspberry Pi is connected to the internet.
ii. Go to preferences.
16
viii. If you have software with a tick next to it, then it
means it is already installed on your Raspberry Pi and if not
already installed, you can simply click on the checkbox
next to the software to get it marked for installing. It is to
be noted that you can install as many software as possible
all at once, if your microSD is not large enough, you might
not have enough space for installing them all so you might
need to check for that. You can also uninstall similarly.
ix. Once you are done with the selection of the software,
either to install or uninstall, select OK to begin the process.
17
Add/Remove software tool is an additional tool that can be
used for getting the software installed or uninstalled and
this tool is located at the same preference category of the
Raspbian menu. With this, you will get to select more
software all at once.
18
Chapter 4: Creating a Portable
Security Box
People that get paid to hack into security systems with the
penetration testers, as well as other security personnel
have been able to exploit the portability and accessibility of
the Raspberry Pi 4 in carrying out their different functions.
The fact that it is designed with a built-in Ethernet port,
lesser power requirements and also can run any Linux
software, makes it easy for integration with targeted
networks.
19
The Kali Linux on the Raspberry Pi comes in handy for
ethical hackers looking for more portability. Raspberry Pi 4
has been designed such that its usage requires less power
including having a small size built. Its size can be
compared as a credit card-sized computer such that when
combined with Kali Linux, you will derive a super-portable
network testing machine that can be carried anywhere.
Raspberry Pi 2, 3, or 4
Power supply
HDMI cable
A minimum of 8GB SD-Card
Keyboard
20
Mouse
root@kali:~ rm /etc/ssh/ssh_host_*
root@kali:~ dpkg-reconfigure openssh-server
root@kali:~ service ssh restart
24
Chapter 5: Installing Full Windows
10 on Raspberry Pi 4
The Operating system of Microsoft can be installed on the
Raspberry Pi 3 Model B or B+ boards by making use of
windows on ARM installer (WoA) which is available on the
GitHub. The operating system previously used on the
Raspberry Pi devices is the Windows IoT core operating
systems but there is now an opportunity to have the full
Windows 10 OS installed.
25
Running Windows 10 IoT Core on Raspberry Pi
If you want to have the full version of Windows including
the Windows 10 IoT core running on your Raspberry, you
can have a stripped version of the operating system up and
running on the microcomputer.
26
Other tools that will be needed include a text editor, Visual
studio, the SDKs add-ons including certificates.
27
Installing Windows 10 Iot Core on
Raspberry Pi
Raspberry Pi 3
A spare microSD card
Windows computer has a microSD card reader for
the installation media to be created
29
Download Visual studio, text editor including
certificates, when you are ready to start with the
development of the applications.
30
In getting your Pi ready, you will need to set up your
microSD for the model of your Raspberry Pi.
31
To download, click on the tab that reads “Download the
Windows 10 IoT Core Dashboard”
32
The next step is to set your device to Broadcomm
Raspberry Pi 2 & 3 or 4
Select your OS to build which should be Windows
10 IoT core. It is advisable to go for the latest version
which is 17763 at the time of writing this book.
Specify a device name as well as the password. The
default name is minwinpc which is quite easy to
remember and you are advised to use a good
password and avoid using the same password you
used for the login for other services.
Go to the right-hand side of the window where you
will find a list of Wi-Fi network connections.
Select your preferred network on the list and it is to
be noted that your Raspberry Pi will automatically
get online at boot up.
33
In case there is a change of location and you need
to boot up your Windows 10 IoT core in a different
location, there will always be a chance to choose an
SSID and provide it with the passphrase.
Insert the SD card into your PC once this is done. It
is to be noted that the Raspberry Pi makes use of
MicroSD card while most laptops make use of only a
full-sized SD card slot. Therefore, it is advisable to
purchase a cheaper microSD adapter and make sure
you have everything that might be available on your
microSD card backed up in case you need to keep
the files because once the setup process is complete,
all files will be completely wiped out.
Due to the same reason, once your card has been
inserted, make sure you properly check to make
sure it has been correctly selected by the IoT
dashboard as the installation destination.
Both the name and capacity should be shown as
expected and to be sure of this, double click on the
dropdown menu and get all the options reviewed to
select the correct one.
Accept the terms of the software license by ticking
the box and then select the Download and install
34
option afterward to get the process completed. The
latest build for your device will get downloaded by
the IoT dashboard. It is to be noted that this file is
large and as a result, it might take up to an hour to
download using home broadband.
The image will be stored locally afterward and you
won’t have to get it downloaded again in case you
want to flush the microSD in the future.
35
Booting into the IoT core
Booting into the IoT core might take a little longer
showing the Windows logo or a blank screen at first
time booting.
You will be asked to choose a Wi-Fi network that
can be skipped if you already chose a network
during the image creation.
The next page after this will be the device overview.
The brief rundown about the spec of your hardware
will contain the IP address including other
information as shown below:
36
Once you are booted into the Operating system, it is
advisable to check for any available updates.
Go to the sidebar and click on the icon denoted by a
red person to get logged in to your Microsoft
account.
Open the Settings by clicking on the cog icon.
Select App Updates in the sidebar.
Apart from the ability to use the Raspberry Pi as a
regular desktop PC, it can also be used for headless
operation due to its compact and low-power design
even with the exclusion of the monitor, mouse or
keyboard.
Microsoft has also built the device such that it now
has a remote access feature in its IoT dashboard. To
make use of this functionality:
Return to your personal computer.
Go to the IoT dashboard sidebar and select “My
Devices.”
Right-click on your Raspberry Pi and click on Open
in the Device Portal which will result in the opening
of your default browser which contains different
details about your IoT Core System.
37
Use “Administrator” as the username while your
password should be the one you specified during the
setup process. In a situation where no password was
entered, make use of the default password which is
“p@ssw0rd”
38
With the device portal, you can also get the
application deployed to the device.
39
If you have a problem initiating a connection, check to be
sure that the format of credentials is correct. The format
should be in the form: username prefixed by the IP address
of the Pi as well as a backslash for example here, we have
192.168.1.77\Administrator.
40
Type in "Set-Item WSMAN:\localhost\Client\
TrustedHosts -Value 192.168.1.77" to replace "192.168.1.77"
using the address that was copied down from the screen of
your device overview.
41
that can be a machine controller, time-lapse camera,
voice assistant, etc.
It is to be noted that if you are a fan of the IoT
development, the IoT Core distribution being
described in this book can only be used in creating
test images which are a major target for developers
that have an interest in prototyping new designs.
There are also retail images that are compiled to be
used by consumers and they can be used on
corporate networks as well. They can also be
effectively secured to protect it from intruders.
42
Chapter 6: The Raspberry Pi can
function as a desktop PC
The Pi can be connected with an HDMI cable to
compatible display for use as a regular PC. Add power
supply, a keyboard and a mouse then you are good to go.
Add a microSD card for storage support.
43
Every computing work I do for one week will be on the
Raspberry Pi. I will do my writing and editing for the next
seven days on this little device set up as a traditional
computer.
Internet connectivity
Email
Web browsing
Word processing and spreadsheets
Printing
Collaboration
Check email
Check Slack
44
Editing work
Writing
Pitch emails
Internet research
Editing photos and screenshots
45
My typical work week is five days, from Monday-Friday,
still I decided to set up the Pi beforehand. By Sunday
evening my workspace was ready, even I don’t want to
spend my Sunday night setting up computers.
All I had to do was scroll to the end of the line and added:
46
After saving, I exited (Ctrl + X, then follow the instructions
on-screen), I restarted my Pi. After restarting, now there is
no delay and my mouse works perfectly.
47
And yes, it did.
48
Day 4: Switching to the Laptop for Today
49
This is the last day of my project and I had some articles to
submit. It dawned on me that this is the time for me to edit
some images. I started installing GIMP, I was nervous
before I realized it was available in the Raspberry
repository. Soon enough I began cropping and resizing as I
would on a traditional computer.
50
1. When I logged into my Google account, auto-
installed extensions clashed with the Chromium
browser’s pre-installed extensions. I fixed this by
disabling the extra extensions.
2. Keep the number of open browser tabs to a
minimum.
3. The Raspberry Pi is not portable.
4. The Pi couldn’t cope with the Slack homepage. I use
Slack often, but the Pi can’t handle it. I tried the
Linux app version too but it didn’t work.
5. It is slow when downloading from the cloud.
6. Use the right keyboard and mouse to avoid issues.
7. On the Pi, I could edit quality images using the
GIMP.
In conclusion, most of these problems, won’t trouble the
average user. Since my work involves writing, editing and
photo editing, I must say I had a decent experience with
the Raspberry Pi.
51
computing work on a Raspberry Pi. If you choose the right
mouse and keyboard, you won’t notice a difference
between a Pi and a traditional PC.
52
Chapter 7: Build Your Own
Raspberry Pi Night Vision Camera
To build a homemade night vision camera, you need a
Raspberry Pi Zero W, Pimoroni HyperPixel screen, and
Raspberry Pi IR Camera Module.
53
Night Vision
Night Vision
55
Building A Night Vision Device
56
A Note on Screen Rotation
The main issue was that the ‘touch’ accuracy was off by 1
and 2 cms. I tired other operating systems; I had the same
issue with the new Buster OS. Finally, I downloaded an
older version of the Raspbian OS from:
http://downloads.raspberrypi.org/raspbian/images/
Software Install
57
Using GUI Zero
58
Shutting down the Night Vision
The GUI
A 10 second preview
A 30 second preview
A 60 second preview
A 5 minute preview
A 10 minute preview
59
A 15 minute preview
Take a photo
Capture a 10s video clip
Turn on the preview (no time limit)
Close the night vision GUI and shut down.
The original colors of the buttons were grey which was too
bright for my stealth agenda, so I changed them to black
and green.
60
3. Retrofit a Vintage Camera Flash with a Raspberry Pi
Camera Module
61
Although the flash function of the unit was still broken,
this is a great case of upcycling old tech. it looks cool and
you can set it up alongside a Film camera to create some
comparison between the footage they produce. The image
above is an example of this.
62
1. Purchase a camera flash,
2. Take it apart to remove the capacitor and circuit
board,
3. Now you have to find a way to fit the Raspberry Pi
inside it,
4. Cut a large hole in the side, put the Pi and the USB
OTG hub also, so you can access the Pi directly or
with your computer.
5. The Pi won’t fit without its protective case, so leave
it on. Cut a breadboard in half, add two LEDs and its
resistors to it, then insert the breadboard at the
back of the USB OTG hub.
6. Attach and strap a small power bank to the flash as
the power source
7. Anytime you use click on the touchpad, the camera
will record a 12 seconds video. The two LED lights
act as status indicators, for recording and standby.
63
The PiCamera library creates H.264 videos which are
converted to MP4 by MP4box. If a USB drive is connected,
the MP4 files are generated onto it. The system dive can
also serve this purpose if a USB drive is unavailable. This
device is similar to the action camera that can be installed
on hot or cold shoes of film cameras.
One of the issues was that you have to wait for several
minutes after taking the footage before extracting your files
or the last MP4 will be outputted as empty (0 byte). You
can compromise by shooting an extra video to ensure the
last one you wanted, won’t be generated as empty.
65
66
67
68
69
70
Chapter 9: The Scratch 3 Desktop
can now be installed and used for
Raspbian on your Raspberry Pi!
Scratch 3
Since the Scratch 3’s release this January, the Scratch team
has been working with us to build an offline version for the
Raspbian OS. Compared to older versions the Scratch 3 has
improved interface and superior functionality. This feature
requires a better processor to run smoothly. With the Pi 4
running the latest version of the Raspbian, Buster, you are
guaranteed a comfortable experience using the Scratch 3
on your PC.
71
Which Raspberry Pi can I use?
72
After updating your OS, the apt on the terminal or
Recommended Software app on the terminal may be used
to install Scratch 3.
73
What use is the Scratch 3 and Raspberry Pi?
Scratch 3 for the Raspberry Pi provides extensions that you
can use to control the GPIO pins and Sense Hat using
Scratch code.
GPIO extension
74
With the GPIO extension comes freedom to connect and
control a lot more electronic devices.
75
Sense HAT Extension
76
It displays patterns, text and characters on the LED
matrix.
77
Chapter 10: Virtual Gaming with
Raspberry Pi 4
With the constant increase in mobile gaming and the rise
in virtual gaming, MMO games with streaming and
headsets for voice chatting is the new rave.
Raspberry Pi 4 board
The Raspberry Pi
78
The Raspberry Pi has seen lots of iterations since its release
in 2012, each device more powerful and efficient than the
last one. Currently, there are two valid options.
79
The Raspberry Pi with the enhanced 4GB ram will cost a lot
more. You can purchase a starter kit which contains
everything you need, except the mouse and keyboard.
After getting all the listed hardware, you have to find the
right emulators. It is best to install an emulation suite but
if you want to you can install the emulators individually.
The emulation suite contains many top emulators and can
be written on a SD card. You will find other unlisted
emulators preinstalled on the suite.
1. RetroPie
2. RecalBox
80
The cheat codes, a rewind tool, to undo mistakes and
screenshot features enhances the gaming experience on the
RecalBox.
3. PiPlay
4. Lakka
81
With about 40 emulators and thousands of games
available, this is a competent alternative to RetroPie and
RecalBox.
6. Batocera
82
Batocera supports a host of gaming platforms; you just
have to plug your game controller to play.
83
Where to Get RetroPie ROM Downloads
If you want the retro feel, go for the old school joysticks
and console controllers with USB connectors. They are
available. I prefer to use a standard Raspberry Pi 3 case and
85
it’s not usually in the open. You may decide to use a retro
console-themed case and display it proudly. There are lots
of them available in various designs the mini SNES console
design for example.
You can also try 3D printing, Lots of retro style cases can be
found online as digital files, you just have to buy and
produce them. If you don’t have a 3D printer, there are
people who provide this service. You have to upload the
design and they want their payment upfront, they will ship
it to you. If you intend to build your own case, you can use
the slick design of a game for inspiration.
86
Chapter 11: Setting up Raspberry Pi
as a Vpn Server
The function of the VPN is to help you in making your
online identity to protect your activity from being tracked
while browsing the internet or doing other things like
engaging in conversations. VPNs are famous for their use
in our regular computers and it is used in a similar way
when it comes to our micro-computer such as the
Raspberry Pi. Examples of VPN services that can be used
with the Raspberry Pi are Expressvpn, IPVanish, HideMy
Ass as well as the SaferVPN.
87
Set your Raspberry Pi up as a VPN server by taking the
following steps:
88
Easy access to files on your NAS without endless
configurations or while the connection is being
encrypted.
You will also get an option to make use of your
laptop on a public Wi-Fi hotspot without the risk of
any intruder accessing your transmitted data.
It also gives you complete control over your data
having a rest of mind that all your data is safe.
No special hardware is needed to get your VPN
working as well.
89
in the command-line mode. The Lite version does
not come with a graphical user interface.
Get on your browser to get the 2017 file of raspbian-
jessie-lite.zip file and get the .img file in it extracted.
90
Download and install the Win32 Disk Imager.
91
require a keyboard and monitor to be connected to
your Raspberry Pi through the internet will not be
required yet.
Make use of the normal login to gain access by
making use of the username: pi; password:
raspberry.
You can hide the Raspberry Pi in the corner that is
next to your router since it is just going to be used
as a server. It is advisable to set up your Pi to be
controlled remotely in the crustless mode. You will
need to enable Secure Shell (SSH) by typing in the
command sudo raspi-config to control in the
crustless mode.
92
You will be prompted with a question saying
“Would you like the SSH server to be enabled?”
answer yes to this question.
Once you select YES, Pi will confirm that your SSH
is on and select Finish afterward.
Type in the command sudo shutdown now, to get
your Raspberry Pi shut down.
Get your keyboard and monitor unplugged and get
the Raspberry Pi plugged into your router using the
Ethernet cable.
93
Go to Windows and make use of the IP scanner like
the Angry IP scanner for example. The Angry IP
scanner gets your Raspberry Pi listed as raspberry
pi.local located in the Hostname column.
94
Raspberry Pi is the one you have at the top-left of
the PuTTY window and finally select YES to confirm
that you trust the device.
Now you will have access to log in using the username and
password of your Raspberry Pi including a command-line
used similarly to having the physical presence of your
Raspberry Pi. You should have the Linux updates
downloaded and installed by making use of the command
sudo apt-get update and sudo apt-get upgrade
afterward.
95
Then you can now install the OpenVPN through the PiVPN
installer by taking the following steps:
Static IP
96
To carry this out, if asked about using your current
network settings as your static address, you can click on
NO and change the last number of the address afterward.
i. The default “pi” will be the only one installed, so you will
have no other choice than to have it selected.
97
The security patches are very useful for a machine which is
always connected to the internet having its network port
opened all the time.
iv. You can now choose between using the TCP or UDP
protocols. It is more preferable to make use of the UDP
because they are faster, through the TCP also comes in
handy in certain situations.
vi. Let the port remains as the default (1194) and selects the
OK option. It is important to have the port number noted
somewhere and ensure the port is correctly displayed on
the screen.
Paranoia Level
98
security, 4,096 come in handy and you will also be
given the option to download key components from
public key generation service for generation time to
be reduced.
If the security is an important factor for you which
is otherwise referred to as the paranoid in terms of
the PiVPN installer, you can get your keys generated
from scratch. You can get this done on the
Raspberry Pi 3 in less than an hour.
Getting Connected To Pi
100
page and in case of some routers like the Netgear
D700; you can sign up directly from the interface.
In a situation where your router does not support
dynamic DNS, you can sign up for a No-IP account
to compensate for this by making use of the
Windows application. This will automatically send
your external IP address to No-IP and for this to
work; you must make sure your computer is on.
After you have completed the signup, you will be
given the option of selecting a hostname with
different domains and it will automatically fill in
your IP address. In a situation where your hostname
has already been taken, you will need to keep trying
different hostname or domain combinations until
you stumble on an available one.
Then you should have your hostname listed at the
Hostname section of the No-IP dashboard with the
No Dynamic Update Detected underneath. Select
this option and you will be enlightened by the
wizard as regards setting up your DNS getting
updated on your router.
Go to the PiVPN installer and select the Public IP or
an external IP address or choose the DNS entry if
101
you are making use of the dynamic DNS. In the case
you chose the DNS entry, you will be required to put
in your dynamic DNS Hostname and check properly
to be sure it is right before confirmation.
For users connecting to your VPN, you will need to
be requested for the DNS Provider because it will be
needed in browsing the web through a VPN server
of the Raspberry Pi. The DNS server can view
whatever websites that must have been visited by
those connecting to your VPN as a result, you are
advised to build your DNS server if you need some
privacy.
At the final stage, you will be required to “run pivpn
add to create the ovpn profiles,” however you will
need to have your Raspberry Pi rebooted first.
Select the OK option to start rebooting.
Forward the necessary port available on your router.
Go to the settings of the router and get a port
forwarded to your Raspberry Pi to notify your router
where it will be sending the incoming VPN
connections irrespective if you decide to use an
external IP address which is connecting to your
Raspberry Pi VPN or using the dynamic DNS.
102
You should visit the portforward.com for a
comprehensive router list. Stick to the use of the
default OpenVPN UDP port 1194.
Access Granted
104
To get connected to your VPN, you will need the
combination of .ovpn file along with the correct
username and password. It is to be noted that the
client software will be needed for this.
The next step is to download and install the
OpenVPN Installer.
To copy .ovpn files to C:\Program
Files\OpenVPN\config. In a situation where you
intend sending these files to other people, it will be
a good idea to encrypt the files using the 7-Zip first
to have them secured. It is, however, important to
note that most email services will not allow you to
get an encrypted file sent over them as an
attachment so they will need to be hosted in a file
sharing service like Dropbox. After which you can
send a link to the Dropbox folder which contains
the encrypted file.
It is also advisable to get the username including the
password sent separately from the 7-Zip encrypted
.ovpn file. You can preferably make use of an
encrypted platform like WhatsApp.
To get the OpenVPN Gui loaded. Go to the System
Tray and right-click it.
105
You will then be prompted with a list of OpenVPN
profiles that have been installed.
Click on connect afterward for a secure connection
to your Raspberry Pi.
Connection using a smartphone running in the
wireless hotspot mode is the easiest way to check if
your VPN is working from outside a home network.
106
Chapter 12: Hosting a WordPress Site
on Raspberry Pi 4
The hosting of your website on the Raspberry Pi 4 is a great
way of familiarizing yourself with the device. You will get
conversant with how to work with MySQL, Apache
software and PHP including the practical application of
working with Linux by running a Wordpress server.
107
that can be accessed on any device via the same network as
your Raspberry Pi 4.
Installing Apache
108
How to Test the Web Server
The Apache will by default put a test HTML file in the web
folder which can be viewed from your Raspberry Pi 4 or
another computer available on your network. To test the
web server, you are required to take the following steps:
109
v. You should be prompted with the page below, after step
iv., which shows that your Apache is up and running.
110
Details about each column:
111
The groups that own the file or directory.
The size of the file or directory.
The date and time of the last modification.
Installing PHP
112
PHP is a very useful language that has also been used for
huge projects like Wikipedia and Facebook.
113
What you will need
Raspberry Pi computer with a Camera Module port
All the current Raspberry Pi models have a port for you to
connect the Camera Module.
114
Raspberry Pi Camera Module
115
Connecting the Camera Module
116
Boot the Raspberry Pi.
Open the main menu, then under preferences select
the Raspberry Pi Configuration tool.
117
Enter the Interfaces tab and make sure the camera
is enabled:
Restart the Raspberry Pi.
118
How to Control the Camera
119
Type the command in the image below to take stills
and save them on your desktop:
raspistill -o Desktop/image.jpg
120
You can add more options to set the size and look of the
image the raspistill command takes.
You can add -h to change the height of the image
and -w for the width:
raspistill -o Desktop/image-small.jpg -w 64
121
The video.h264 file will be saved to your desktop,
double-click the file icon to play it with VLC Media
Player.
122
Create and save the new file as camera.py.
camera = PiCamera()
camera.start_preview()
sleep(5)
camera.stop_preview()
camera.rotation = 180
sleep(5)
camera.capture('/home/pi/Desktop/image.jpg')
124
camera.stop_preview()
Note: Set the sleep mode for at least two seconds, this
should be sufficient time for the camera sensors to register
lighting conditions.
for i in range(5):
sleep(5)
camera.capture('/home/pi/Desktop/image%s.jpg' %
i)
camera.stop_preview()
125
The variable i indicates the amount of times the loop has
run, from 0 to 4. Your photos will be saved as image0.jpg,
image1.jpg till it gets to image0.jpg.
Launch the code to take more pictures with your Camera
Module.
The camera will capture an image every five seconds,
stopping after the fifth photo.
camera.start_recording('/home/pi/Desktop/video.h26
4')
sleep(5)
126
camera.stop_recording()
camera.stop_preview()
127
Type the following command to set the maximum
resolution for your picture:
Note: You have to set the frame rate to 15 to enable
maximum resolution.
camera.resolution = (2592, 1944)
camera.framerate = 15
camera.start_preview()
sleep(5)
camera.capture('/home/pi/Desktop/max.jpg')
camera.stop_preview()
128
sleep(5)
camera.capture('/home/pi/Desktop/text.jpg')
camera.stop_preview()
camera.annotate_background = Color('blue')
camera.annotate_foreground = Color('yellow')
camera.stop_preview()
camera.brightness = 70
sleep(5)
camera.capture('/home/pi/Desktop/bright.jpg')
camera.stop_preview()
for i in range(100):
camera.brightness = i
130
sleep(0.1)
camera.stop_preview()
You can change the contrast of your preview, just like you
changed the brightness.
camera.start_preview()
for i in range(100):
camera.contrast = i
sleep(0.1)
camera.stop_preview()
sketch
denoise
emboss
oilpaint
hatch
gpen
pastel
watercolor
film
blur
132
saturation
colorswap
washedout
posterise
colorpoint
colorbalance
cartoon
deinterlace1
deinterlace2
camera.image_effect = 'colorswap'
sleep(5)
133
camera.capture('/home/pi/Desktop/colorswap.jpg')
camera.stop_preview()
camera.image_effect = effect
sleep(5)
camera.stop_preview()
134
Set the image exposure mode
off
auto
night
nightpreview
backlight
spotlight
sports
snow
beach
135
verylong
fixedfps
antishake
fireworks
camera.exposure_mode = 'beach'
sleep(5)
camera.capture('/home/pi/Desktop/beach.jpg')
camera.stop_preview()
136
Change the image’s white balance
off
auto
sunlight
cloudy
shade
tungsten
fluorescent
incandescent
flash
horizon
The white balance is preset to auto mode.
camera.awb_mode = 'sunlight'
sleep(5)
137
camera.capture('/home/pi/Desktop/sunlight.jpg')
camera.stop_preview()
Conclusion
Thanks
138