Raspberry Pi – Linux Hint https://linuxhint.com Exploring and Master Linux Ecosystem Fri, 05 Mar 2021 03:08:58 +0000 en-US hourly 1 https://wordpress.org/?v=5.6.2 Can You Turn a Raspberry Pi into a Laptop Computer? https://linuxhint.com/turn-raspberry-pi-into-laptop-computer/ Tue, 02 Mar 2021 12:58:03 +0000 https://linuxhint.com/?p=92412 Years ago, the Raspberry Pi Foundation impressed the computer industry when it released a computer board as small as a credit card. Yes, that small-sized board can hold all the basic components of a computer – CPU, GPU, RAM, USB ports, HDMI port, Ethernet port, and even a space for a 40-pin GPIO header. Not to mention that some models are also wireless capable. The wafer-thin microSD card you’re already familiar with withholds the operating system, normally Linux, and also serves as the hard drive. Many people are accustomed to Raspberry Pi as a desktop computer but do you know that you can turn it into a laptop too?

Raspberry Pi as a Laptop

Raspberry Pi may have all the connectors you need to build a computer, but it’s still just a board. To complete your setup, you need all the other accessories like a keyboard, mouse, and monitor, which may already be lying around your home. Setting up your Raspberry Pi as a desktop is quite simple; after connecting all the accessories to your Raspberry Pi board and loading the operating system to the microSD card, you can start using your Raspberry Pi computer. But if you want to cut all the wires and build a portable laptop from the tiny Raspberry Pi board, it would require a totally different setup.

Laptops have great advantages when it comes to convenience and portability. That’s why hardcore and creative DIY enthusiasts took the challenge of turning the Raspberry Pi into a laptop. Computer manufacturers like Kano have already marketed laptops with a Raspberry Pi board at its core. Other laptops built from Raspberry Pi like CrowPi, Pi-top 3, and Lap-Pi are also on par with mainstream Chromeboxes and netbooks when it comes to performance and price.

How To Turn Raspberry Pi Into a Laptop

Turning Raspberry Pi into a laptop would take learning to a whole new level. It’s not as simple as connecting peripherals here and there. It would take accessories and proficient knowledge on electronics, coding, and computers to build a working Raspberry Pi laptop. Furthermore, you need additional connectors and electronic tools like the multimeter to test if the voltages and current going around the board and its components are correct. You can probably tell by now that it’s quite complicated but not impossible if you have the passion and creativity.

If you feel inconvenient going through the intricate assembly, you can just buy Raspberry Pi-powered laptop kits like a Kano computer and the playful Lego Raspberry Pibook. These kits have all the components you need to build a laptop, and you have to connect all these together and enclose them in a case, which is also already included. But glory is found in difficulty, so if you want to get your hands dirty on assembling your own Raspberry Pi laptop, here are the basic things you need aside from the Raspberry Pi board:

Display

If you have some cash to spare, you can buy a brand new IPS display and connector for your DIY Raspberry Pi laptop. But if you have old laptops or tablets just sitting in the corner that still have working displays, you can go green by recycling the display. You most likely need a Raspberry Pi HAT (Hardware Attached on Top) with an IPS display connector. You just need to connect the HAT to the 40-pin GPIO header on the Pi board, and you can straightaway connect your display to the board.

Keyboard

You can get your fingers tapping on a Bluetooth keyboard for your Pi laptop, but you should get a Raspberry Pi with Bluetooth capabilities like the Raspberry Pi 3 B+ or the most recent Raspberry Pi 4 B. Otherwise, you can source the keyboard out from your old laptop as long as you know the connectors and the driver you need.

Trackpad

There’s not a lot of touchpads you can buy individually. DIY makers usually salvage trackpads from old laptops. These, however, are still using a PS2 connector, so if you want to do the same thing, you would need to do some soldering to make the touchpad work with the Pi’s interface. If you have advanced electronic skills, you can do what other makers have already done; use an Arduino microcontroller, or other similar boards, to convert the trackpad’s PS/2 to USB. If you want to make things easier, you can buy a wireless keyboard with a built-in touchpad instead.

Battery Pack

Power banks are a good choice for a power supply for DIY laptops because they’re already enclosed in a casing. You just need to solder some wires, add a switch, and you already have a battery pack. If you don’t have a power bank, you can glue your AAA batteries together, connect a switch, and put them in case. There are many other means to create a battery pack as long as you know your way around electronics.

Casing

You can use any sturdy and lightweight material for your casing. Makers usually opt for a heat-resistant plastic casing, but you can also choose metal or wood. That would all depend on your style and creativity.

Cooling System

The system will generate heat. Thus, a cooling system is absolutely necessary. To keep the air flowing within and prevent damages to the components, you need to add cooling fans and heatsinks. You can either buy new fans and heatsinks, or you can rummage your old laptops or even desktops for working heatsinks and fans.

Coding Skills

Setting up your Raspberry Pi laptop does not connect all the components together and organize them inside a case. Aside from your skills in electronics, you need coding skills too. You need to install the drivers for the components and some coding to make them work with the board.

These are the essential components in building a Raspberry Pi laptop. You can add other fancy features if you want your laptop to be unique. You have all the freedom to design your own laptop so you can include anything that would suit your needs and style. If you have all the components and the skills required, then the possibilities are endless in building your very own Raspberry Pi laptop.

]]>
What Are the Differences Between Raspberry Pi and Arduino? https://linuxhint.com/raspberry-pi-vs-arduino/ Fri, 26 Feb 2021 18:33:00 +0000 https://linuxhint.com/?p=91924 Raspberry Pi and Arduino are usually the top choices for a broad range of build projects because of their size, price, and versatility. Both boards were created initially to provide students a single-board module that will help them learn about computers, coding, and electronics at a very low cost. Unexpectedly, these boards, later on, gained popularity in the community of hobbyists and makers, novices, and experts alike.

A Little Throwback

Arduino hails from Italy, and it’s said that it was named after a bar where the developers usually meet to discuss the board. The first Arduino was developed in 2005 and aimed to provide students at Interaction Design Institute Ivrea in Italy with an inexpensive microcontroller board. Its cost and simplicity also piqued the interests of hobbyists and professionals; it wasn’t long until it reached a wider community of makers. Many other varieties of Arduino boards have been created since then. In 2013, around 700,000 Arduino boards were already sold [1].

Raspberry Pi was born seven years after Arduino when Eben Upton invented a low-cost, modular, the single-board computer that will help improve the programming skills of his students. Like Arduino, it soon reached a wider audience due to its cost and versatility. The first Raspberry Pi board cost only $35, far less expensive than the existing computer boards that usually cost five times higher. The small board got even smaller and cheaper after the Raspberry Pi Foundation created the Raspberry Pi Zero, the smallest Raspberry Pi board to date, which costs only $5. Raspberry Pi progressed rapidly that millions of boards were already created from the initial target of just 10,000 boards years after its first release.

Raspberry Pi and Arduino: Key Differences

Raspberry Pi and Arduino have grown by leaps and bounds over the years. Because they’re both a favorite among students, DIY enthusiasts, and project builders, these boards are often compared head-to-head despite having different platforms; Raspberry Pi is a single-board computer while Arduino is a microcontroller. Although they both find their niches in DIY projects, robotics, and electronics, they have many differences in performance, cost, software, and functionality. Read on to know the main differences between these two miniature boards to help you decide which one will be suitable for your future projects.

Hardware

Raspberry Pi is built as a mini-computer and thus seats all the basic components of a computer. At the heart of all Raspberry, Pi boards is a 32-bit or 64-bit Broadcom ARM CPU, from the 700MHz single-core CPU of the original Pi to the much faster 1.5GHz quad-core CPU of Raspberry Pi 4. Broadcom Videocore GPUs are also integrated on the board for graphics processing. The RAM ranges from 256MB to 8GB, depending on the model. USB ports for data transfer and HDMI ports for display are also embedded on the board. Some models also consist of Ethernet ports and have wireless capabilities as well. There’s a microSD card slot for storage reserved for the microSD card containing the operating system. All Raspberry Pi boards include a 40-pin GPIO header, save for Raspberry Pi Zero and Raspberry Pi Zero W, where you need to solder the header yourself.

On the other hand, Arduino is a circuit board built as a microcontroller. Its computing power is far less than that of Raspberry Pi. 8-bit Atmel microcontrollers are at the core of every Arduino board, which are often less than 100MHz. The RAM ranges from 2KB to 64MB. Storage is based on flash memory, from 32KB to 128MB, depending on the model. Some models have a USB port that serves as a communication link and as a power supply. Those without the USB port use the Atmel microcontroller’s pins for communication and can be powered up using a battery pack. Not all boards have built-in networking features. Some would require additional hardware, known as Arduino Shield, which is usually attached to the board to connect to a network. Like the Arduino Uno WiFi, other boards have included WiFi support due to the increasing demands for IoTs.

Software

Because a Raspberry Pi is essentially a computer, it requires an operating system to boot up. The Linux OS for Raspberry Pi called the Raspberry Pi OS (previously Raspbian) is the default OS of Raspberry Pi’s. However, other Linux and non-Linux OSes can also run on the tiny board. There’s a long list you can learn with the Pi’s when it comes to programming languages. You can start coding with Scratch, Python, JavaScript, HTML5, C, C++, and Java, to name a few.

Unlike Raspberry Pi’s, Arduinos don’t need an OS to run. Arduino systems are much more simple than Raspberry Pi’s. It would be best to program the microcontroller, although the programming languages you can use are limited to C and C++. Arduinos are plug-and-play devices, which means, once you power it up, it will run the program you’ve encoded and will terminate the program once you shut it off.

Uses

When you embed a Raspberry Pi in your prototypes or projects, you’re embedding an entire computer to perform many different tasks. Due to its lower computing power, Arduino is limited to just one or two tasks and repeatedly runs the same program. The Raspberry Pi is more complicated than the Arduino, but its complexity is a huge advantage for a multi-functional project. For example, to interact with sensors, you would need to install libraries and other software in a Raspberry Pi, whereas you need a simple code for the Arduino to do the same task. You can build simple projects, like sensing the temperature in a room, using an Arduino, but you can build more complex projects like a DIY drone using a Raspberry Pi. Because there are more components on a Raspberry Pi, it generally costs more than an Arduino.

As you can see, the Raspberry Pi and Arduino are two very different boards, and both have their own set of strengths and weaknesses. If you’re working on a project that requires you to fulfill only one or two tasks, you can go for an Arduino, but for projects that require more complicated tasks and programming, then the Raspberry Pi would be a better option.

]]>
What is the Difference Between Raspberry Pi 3 and 4? https://linuxhint.com/difference-between-raspberry-pi-3-and-4/ Thu, 25 Feb 2021 03:34:56 +0000 https://linuxhint.com/?p=91050 Raspberry Pi may sound like an appetizing raspberry-flavored dessert, but it’s far from being edible. It’s a credit card-sized, Broadcom-based, single-board computer, that’s easy on the pocket.

Hailing from the United Kingdom, the first generation of Raspberry Pi was released in 2012 with the intention of teaching students about computers. Due to its size, cost, and modularity, it has been utilized for other purposes, such as in IoT (Internet of Things), robotics, electronics projects, and is now being promoted for industrial use as well.

The unbelievably tiny computer has spanned four generations so far. There are normally two versions for each generation, models A and B, but revisions and enhancements come along the way, upgrading the models to A+ or B+. Although inedible, these Raspberries have delightful features. Two of the most in-demand models are from the third and fourth generations of the Raspberry Pi. Expectedly, Raspberry 4 is a better model, but it costs more than its predecessors. Is it a worthy upgrade from Raspberry Pi 3? Read on as we dig deeper into the gratifying features of its two recent versions.

Raspberry Pi 3 vs. Raspberry Pi 4

Both Raspberry Pi 3 and Raspberry Pi 4 offers complete functionalities of a basic computer on a single board. They are equipped with ARM processors, RAM, Ethernet port, display port, USB ports, Wi-Fi and Bluetooth capabilities, and a 40-pin GPIO header. While there are three variations of Raspberry Pi 3 (B, A+, B+), Raspberry Pi 4 only has one, Raspberry Pi 4 B, but it comes with four configurable memory amounts.

These two boards also differ in performance, connectivity, and display capabilities among many other things. For comparison purposes, we will be using Raspberry Pi 3 B+, the final revision of the Raspberry Pi 3 generation, and the closest predecessor of Raspberry Pi 4.

Performance

When it comes to performance, Raspberry 4 is a sure winner. Sporting a higher-end Broadcom quad-core processor running at 1.5GHz, newer memory technology with selections ranging from 1GB to 8GB, and a Broadcom Videocore VI GPU, it is a beast, at least in the Raspberry Pi family.

Although it lacks the RAM options of the fourth generation, Raspberry Pi 3 B+ is not far behind when it comes to performance. Embedded with a lower-end Broadcom quad-core processor with just a slightly lower clock speed of 1.4GHz, it can still deliver a pretty nifty performance when paired with 1GB of RAM and a Broadcom Videocore IV GPU.

Here are the key components driving the performance of the tiny boards:

Processor RAM GPU
Raspberry Pi 4 B Broadcom BCM2711, Quad-core Cortex-A72 (ARM v8) 64-bit SoC, 1.5GHz 1GB, 2GB, 4GB, or 8GB LPDDR4 SDRAM Broadcom Videocore VI
Raspberry Pi 3 B+ Broadcom BCM2837B0, Quad-core Cortex-A53 (ARMv8) 64-bit SoC, 1.4GHz 1GB LPDDR2 SDRAM Broadcom Videocore IV

Display and Audio

Raspberry Pi 4 B carries two micro-HDMI connectors onboard, allowing dual display output. Media playback is also a notch higher than its predecessors, supporting up to 4K videos. But one downside to it is you likely need to find a micro-HDMI to HDMI adapter.

On the other hand, Raspberry Pi 3 B+ has an embedded HDMI port and can play videos at 1920×1080p. Although the resolution is lower than Raspberry Pi 4’s, video playback is still considerably satisfactory, plus you don’t need a special adapter to connect your HDMI display.

For audio connectivity, both models come with a 3.5 mm analog audio-video jack.

Connectivity

The two miniature computers have both wired and wireless capabilities. Bluetooth also comes as a standard.

LAN Connectivity

Both models support Gigabit Ethernet, but Raspberry Pi 3 B+’s gigabit performance is hindered by the USB interface that connects the Ethernet port to the motherboard. This interface greatly reduced the maximum throughput to only 315Mbps. Because of this limitation, the interface was eliminated on Raspberry Pi 4 B. The gigabit Ethernet jack is instead directly connected to the motherboard, unobstructed by any interface for optimum gigabit performance.

Wi-Fi and Bluetooth

The wireless LAN for both Raspberries is up-to-date, supporting 2.4GHz and 5GHz bands. When it comes to Bluetooth, Raspberry Pi 4 B has the latest Bluetooth 5.0 in place while its predecessor is using the earlier version, Bluetooth 4.2.

Ports and Storage

Aside from the ports already discussed, there are still other ports on the miniaturized computer boards. There are four USB ports in each of these Raspberry boards. While all four USB ports on the Raspberry Pi 3 B+ adopt the USB 2.0 standard, two of the ports on Raspberry Pi 4 B have been upgraded to USB 3.0; the other two remain as USB 2.0.

Raspberry Pi boards are more than just a computer. The inclusion of a 40-pin GPIO (General Purpose Input/Output) port also makes it suitable for electronics experiments and projects, as it allows you to control your electronic circuit from the Pi itself. In addition, the GPIO port on Raspberry Pi 4 B can serve as the power port, but Raspberry Pi 3 B+ lacks this capability.

Raspberry Pi 4 B is mainly powered up via the USB Type-C port while Raspberry Pi 3 B+ is through a micro-USB port.

Another common thing for both models is the microSD slot reserved for the microSD card that is loaded with a Linux-based operating system. The diminutive SD card also serves as the computer’s hard drive.

Which Pi Should You Buy?

Based on all the features discussed, it can easily be seen that the Raspberry Pi 4 B is an upgraded version of Raspberry Pi 3 B+ in almost all aspects, but it has one disadvantage – heat issue. The faster processing speed will generate more heat and heat issue is inevitable down the road. If the board is used extensively, especially those with higher RAM, a separate cooling system may be required (which means additional cost). Apart from this, Raspberry Pi 4 B is a superb choice for an affordable yet powerful, versatile, and complete computer board.

Still, Raspberry Pi B 3+ is not to be brushed aside. Its components may be at the lower end, but its performance is still up to the mark. Except for dual display support, it’s still capable of all the things that its successor can do at a lower price. If you don’t need all the fancy upgrades of Raspberry Pi 4 B for your computer or projects, then Raspberry Pi 3 B+ would be a good alternative.

]]>
What is the Raspberry Pi Zero used for? https://linuxhint.com/about-raspberry-pi-zero/ Wed, 24 Feb 2021 16:35:47 +0000 https://linuxhint.com/?p=91387 Raspberry Pi was built to educate students about computers and teach them about programming. The Linux-based kit is complete with all the basic components of a desktop computer board despite its credit card size. Just put the tiny board in a case, load the OS in a microSD card, and connect all the necessary peripherals, and you can already boot up a computer! Surprisingly, it became popular among DIY enthusiasts and project builders too. Raspberry Pi boards are already small, but would you believe that the Raspberry Pi Foundation managed to make an even smaller board?

Raspberry Pi Zero

Raspberry Pi Zero is the smallest computer board ever created by the Raspberry Pi Foundation. Released in 2015, Pi Zero only measures 6.5cm by 3cm, just half the size of the standard Raspberry Pi board. It’s equipped with the same single-core Broadcom processor used in the very first Raspberry Pi, but it runs faster with a higher clock speed of 1GHz.

The best selling point of this amazingly small board is its price. With only $5, you get a 32-bit computer that’s complete with a 1GHz ARM11 Broadcom CPU, Broadcom Videocore IV GPU, 512MB of RAM, a microSD card slot, two microUSB ports (one exclusively reserved for power), one mini-HDMI port, a CSI camera connector, and one unoccupied 40-pin GPIO header. But there’s one thing missing – network connectivity. There’s no Ethernet port nor Wi-Fi card on the board, which means you can’t connect it to a network. Because it’s designed to be a minimalist board, Bluetooth is also not included. If you need the Internet, you can connect a USB Wi-Fi dongle or a USB Ethernet port as a workaround.

As you can see, Pi Zero can only give you the bare minimum for a desktop PC. Aside from the network cards, you still need a lot of things like a USB hub to connect various USB devices and a mini-HDMI to HDMI adapter for the display to complete the setup. But for $5, you already get more than what it’s worth.

Raspberry Pi Zero W and Raspberry Pi Zero WH

Perhaps Raspberry Foundation realized the struggles that Pi Zero users go through to connect to a network. Because of Pi Zero’s popularity but lack of network support, the Raspberry Foundation released a Pi Zero variation with built-in wireless features. Introduced two years after Raspberry Pi Zero, Raspberry Pi Zero W has the same components as the original but with the addition of 802.11n wireless card and Bluetooth 4.1. Because of the additional features, it costs slightly higher than its predecessor. With a price tag of just $10, it’s still very affordable considering all the features you can get from such a tiny board. Like the Pi Zero, the W variation is power-efficient.

Now let’s get on to the next Pi Zero variation. Remember the unoccupied 40-pin header in Raspberry Pi Zero? That is no longer a free space for the other Pi Zero variation.

The Raspberry Pi Zero WH sports an integrated 40-pin GPIO header (the H stands for).  It’s everything that Raspberry Pi Zero W is but with the inclusion of a 40-pin GPIO header. This is a great additional component for people who need the GPIO pins but don’t want to go through the hassle of soldering the header.

Raspberry Pi Zero’s OS

Just like any other Raspberry Pi, the microSD card slot on a Raspberry Pi Zero is reserved for the microSD card which holds the operating system. The majority of the OSes compatible with Raspberry Pi are Linux-based, like Arch Linux and Kali Linux, but the default and widely installed OS of Raspberry Pi Zero is the Raspberry Pi OS (previously called Raspbian), downloadable for free from the Raspberry Pi website. Although it’s built for Linux, non-Linux OSes like RISC OS and NetBSD can also run on the Pi Zero.

Before installing the OS, it’s recommended to install the operating system installer Berryboot or NOOBS (New Out of Box Software) to make the installation much easier. You can also download these for free from the Raspberry Pi website. If you don’t want to go through the hassle, you can just purchase a microSD card from Raspberry Pi that’s preloaded with NOOBS. This makes things a lot easier since NOOBS provides you with a list of operating systems, and you just select the OS that you want to install.

What Are They Used For?

Raspberry Pi Zero is a great tool for people who want to start getting their hands on building computers. It has a simple and uncomplicated platform that makes learning easy for children and adults alike. Likewise, it’s a suitable tool for people who want to start cheap in learning how to code languages like Python, C, and C++.

Besides learning about computers and programming, you can also build your hobby projects using the Raspberry Pi Zero. Its small size is a big advantage in build projects because it’s easier to embed than its larger counterparts. Raspberry Pi Zero has also found favor in the IoT community, especially after integrating wireless capabilities in Raspberry Pi Zero W. There are many cool things that you can build with it, either for your home or for work. Creative DIY enthusiasts have created countless projects like portable game consoles, home network music systems, WiFi security cameras, and even weather stations using Raspberry Pi Zero.

The Raspberry Pi Zero’s flexibility, versatility, and computing power also make it an excellent tool for industry-grade projects such as robotics and electronics.

This humble board has surpassed many people’s expectations. The super-cheap board may look just like any other circuit board from the first look, but it carries more power in it. It’s versatile enough that you can learn how to assemble computers, learn how to code, and embed an entire computer in your build projects with it. With the inclusion of wireless capabilities and GPIO headers, there are many other things that you with the Raspberry Pi Zero family. Who would’ve thought that such a small board can do many great things?

]]>
Compared: Raspberry Pi OS vs. Armbian vs. Debian GNU/Linux https://linuxhint.com/raspberry-pi-os-vs-armbian-vs-debian-gnu-linux/ Sun, 27 Dec 2020 00:53:46 +0000 https://linuxhint.com/?p=82453 Many programmers may have the same question: Is Armbian just another flavor of Debian GNU/Linux, or is it something completely different? What are the differences between Raspberry Pi OS, Armbian, and Debian? In this article, we will discuss the Armbian, Debian, and Raspberry Pi operating systems in detail, including a comparison between these different systems.

Fruity Awakening

In 2012, Raspberry Pi popularized the single-board computers (SBC) class for the general public. Back then, anyone with knowledge about devices like the RouterBOARD from Mikrotik [9] or the ALIX Board from PC Engines [11] was seen as exotic. Today, it is impossible to imagine everyday existence without these powerful mini-computers. You can find these devices everywhere — in wifi routers, weather stations, home automation devices, and fine dust measuring instruments. These devices are run with specially adapted Linux or BSD distributions, of which Armbian and RaspberryPi OS are only two representatives of many.

‘Armbian’ is an artificial word that combines the words ‘ARM,’ for the corresponding RISC processor architecture [3], and the last two syllables, ‘bian,’ from ‘Debian.’ This makes it very clear what sets Armbian apart from Debian GNU/Linux; unlike Debian, Armbian is focused and optimized for the ARM architecture.

Moreover, while the Debian GNU/Linux distribution supports a variety of hardware architectures, including ARM7 (32 bit) [4] and ARM8, the Armbian distribution focuses only on a wide range of ARM-based development boards. From the project website, you can download distribution images for the Orange Pi [5], the Cubieboard [6],

and the Asus Tinkerboard [7], among other images. Cubian [12], a fork of Debian GNU/Linux for the Cubieboard, seems no longer to be maintained, as the last release dates back to 2014.

Raspberry Pi OS [8] is the official operating system of the Raspberry Pi Foundation [17] for their SBCs. Initially, it was named Raspbian, for the Raspbian project [15] on which it is based. The Raspberry Pi Foundation later added another package repository with partially closed source software to their images. The Raspbian project never published its own images, but instead always referred to the images of the Raspberry Pi Foundation. The foundation eventually added their own desktop flavor and many more customizations, reaching far beyond Raspbian’s rebuilding and minimal patching of Debian packages. To clearly distinguish between the Raspbian project and the Raspberry Pi Foundation derivative, the latter was renamed to Raspberry Pi OS in 2019.

Compared to Armbian, the Raspbian project and Raspberry Pi OS follow an opposite approach: these distributions rely on dozens of contributors to focus on a single SBC platform. Based on the 32-bit ‘armhf’ version of Debian GNU/Linux, it is meant to run on all versions of the Raspberry Pi board but is not designed to work on any other ARM SBCs. The Raspberry Pi 3 and 4 hardware can run 64-bit operating systems. Meanwhile, the Raspberry Pi OS always runs 32-bit, with the exception of the Linux kernel, which can be a 64-bit kernel. Some packages made specifically for the Raspberry Pi OS are also available for the Intel architecture (32- and 64-bit variants) and can even run on a normal desktop PC running Debian GNU/Linux.

For a limited time only, there are also (unofficial) Debian GNU/Linux images offered for the Raspberry Pi family of SBCs [16]. The main difference to the Raspberry Pi OS is that the images for those Raspberry Pi systems, capable of running a 64-bit OS (Raspberry Pi 3 and 4), also contain a 64-bit OS (‘arm64’ in Debian); while the other images run the 32-bit ‘armhf’ (Raspberry Pi 2) or ‘armel’ (Raspberry Pi 1 and Zero) architectures. The latter two differ from the ‘armhf’ packages provided by Raspbian and Raspberry Pi OS. Historically, several distributions, including Debian GNU/Linux and Fedora, decided on a minimum set of CPU instructions [19] needed for the ‘armhf’ architecture. The first Raspberry Pi OS was published shortly afterward and supported all but one of the required CPU instructions.

So, there were two options: either 1) use the much slower but not optimized ‘armel’ architecture, as Debian GNU/Linux still does for Raspberry Pi 1 and 0, or 2) redefine the ‘armhf’ architecture. Debian GNU/Linux did not want to do the second option, as this option would deviate from what had already been decided and implemented. This was the moment when the Raspbian project was born: the Debian Developer Peter Green (also known by the tag plugwash in IRC) recompiled all ‘armhf’ Debian packages for Raspberry Pi 1 CPUs (back then, only Raspberry Pi 1 existed) with the single CPU instruction missing. This is also the reason why you cannot mix Debian’s ‘armhf’ and Raspbian’s ‘armhf’ releases.

Image Size

The installation images offered by the three projects are quite different. Armbian requires you to select a category (such as General, IOT, NAS, Networking, or Desktop) and the SBC, first. Next, you will choose the corresponding image offered with either the 4.9 or 5.9 Linux kernel for oldstable (previous release), stable (current release), and testing (upcoming release). The image size is between 270 and 600 M. Each image file can be retrieved as a direct download or via BitTorrent from the project website. Updating an existing Armbian installation is done using the same instructions as those used for maintaining Debian GNU/Linux.

In contrast, the options for Raspberry Pi OS are a bit more limited. Raspberry Pi requires you to choose between OS Lite, OS with desktop, and OS with desktop and recommended software. All images are equipped with the 32-bit version of a 5.4 Linux kernel. The image size varies from 440 M to 3 G. Downloading the image can be done directly, as a torrent data stream, or via the Raspberry Pi Imager, a GUI-based setup tool available for Windows, macOS, and Ubuntu. As with Armbian, updating an existing version of Raspberry Pi is done using the same instructions as those used for maintaining Debian GNU/Linux.

The RaspberryPi Imager

Finally, for most devices, including most ARM devices, Debian GNU/Linux offers a variety of ready-made installer images, including a basic setup, a tiny image for network-based installation, different desktop variants that fit on one CD or DVD, live CDs, and even a set of full CD/DVD images. Though these images are not ready-to-run images, they contain the Debian Installer, a minimal OS that is solely for performing the OS installation. The live images run directly from a read-only installation also contain the Debian Installer.

The image size is between 250 M and 3 G. Downloading an image is possible as a direct download or via BitTorrent. The regular Debian packaging commands are used to update an existing installation.

This is not so for the Raspberry Pi operating system. In fact, there are no official Debian GNU/Linux images for Rasberry Pi. There are, however, unofficial ready-to-run images (no installer images) with Debian GNU/Linux for Raspberry Pi, made by the same developers behind the official (but “non-free”) Raspberry Pi firmware packages in Debian GNU/Linux [16].

First, you will decide between daily built images based on the most current packages in Debian GNU/Linux 10 Buster (the current stable release at the time of writing this article) or “tested” images that are guaranteed to run. In comparison to the Raspberry Pi OS, which offers images that work on all Raspberry Pi boards, with this distribution, you have to choose which Raspberry Pi board will contain the image. The images for the Raspberry Pi 1 and Raspberry Pi 0 (not 0W) operating systems are roughly the same, as they use more or less the same CPU and have no Wi-Fi components. Depending on that, you also get different OS architectures; namely, ‘armel’ for Raspberry Pi 1, 0, and 0W; the original ‘armhf’ for Raspberry Pi 2; and ‘arm64’ for Raspberry Pi 3 and 4.

Supported Devices

Regarding supported platforms and devices, the three projects go in slightly different directions. For Armbian, the device information for every supported SBC can be found at the Armbian website. This is accompanied by a list of tested third-party hardware to ensure that all hardware components work well together. Overall, Armbian supports several different ARM SBCs, but it does not support the Raspberry Pi family of SBCs.

For Raspberry Pi OS, device information for every Raspberry Pi version is available online, at the Raspberry Pi website. And, of course, Raspberry Pi OS provides support for all Raspberry Pi devices.

For Debian GNU/Linux, the information is organized in a wiki, sorted by OS architecture, with specialized sections for more specific information. Debian currently supports nine OS architectures officially (of which three are for ARM devices). Debian also builds its packages and installer images for 13 further OS architectures that are not officially supported, running under the label ‘Debian Ports’ [21].

Development

Furthermore, the methods by which each of the three Linux distributions are developed differ significantly. Armbian and Debian GNU/Linux are community-based projects. For Armbian, the corresponding GitHub project page is key. Debian GNU/Linux uses its own distributed infrastructure that allows for development of the Linux distribution from all over the world.

Meanwhile, Raspberry Pi OS is maintained by the non-profit Raspberry Pi Foundation as an in-house project. Contributions to the Raspberry Pi Foundation can be made via the Raspberry Pi Forum [20]. The Raspbian project is largely a recompilation of the Debian packages created for Raspberry Pi and does not seem to have a big community of its own. The outdated Raspbian website [16] often refers users to either of the Debian GNU/Linux or Raspberry Pi Foundation websites.

Licensing

Armbian is licensed under GPL2, whereas both Raspberry Pi OS and Debian GNU/Linux use a mix of licenses, including GPL and others. The Raspberry Pi OS image “with recommended software” contains several “free-to-use” commercial software packages, most of which are limited demo versions. The plan is of these free package offerings is to hook users so that they buy that software for their other computers.

Also, some firmware blobs needed for Raspberry Pi and other ARM SBCs are only available as “binary only,” i.e., without source code. In the software world, these software packages are considered “non-free.” The previously mentioned unofficial Debian images for Raspberry Pi contain Debian’s “non-free” repository, enabled by default because it includes the ‘raspi-firmware’ software package.

Software Packages and Setup

Armbian describes itself as a “Lightweight Debian or Ubuntu based Linux distribution specialized for ARM development boards.” It comes as a ready-to-run image optimized for memory flash devices, such as NAND, SATA, eMMC, and USB. Both SSH and DHCP services are activated right from the start. A wireless adapter supports DHCP (if present), but this feature needs to be enabled by the user. This allows for an easy setup to connect this system to your router or create an individual access point. XFCE is used as the Desktop Environment [18].

XFCE on Armbian

To increase execution speed for code and data and minimize I/O operations, several functionalities have been transferred to work as much as possible from memory. For example, the log2ram service keeps log files in the memory and saves them to the disk daily and on shutdown [13]. Disk caches are kept in the memory for ten minutes using the option “commit=600” in the directory configuration in the file /etc/fstab [14].

As previously noted, the Raspberry Pi OS targets the different Raspberry Pi models, which started out with quite limited hardware components. To deal with these limitations as a Desktop Environment, the default setup starts a modified LXDE Desktop named PIXEL (Pi Improved X-windows Environment Lightweight), which is also available from the Raspberry Pi Foundation for Intel-based Linux PCs.

The PIXEL Desktop Environment

By default, a user named “pi” with the password “raspberry” exists, and the SSH service is disabled for this user. You can enable it for a single boot up by editing the file config.txt on the first partition. It is strongly advised to change the password immediately after the first login. Only then can you can enable the SSH service permanently to avoid well-known default passwords accessible via SSH.

Debian’s unofficial Raspberry Pi images also come wired with the network enabled by default via DHCP, but the Wi-Fi does not come pre-configured, as of this writing. Another difference with Raspberry Pi OS images is that there is no normal user, just a root user with no password and the SSH root login disabled. Setting the root password or an SSH public key for root login in advance is supported by editing “sysconf.txt” on the first partition. These settings are wiped after they have been applied to the booted system to avoid leakage of the plain text password.

Currently, the option to configure access to a Wi-Fi network is in the planning stages. Future versions of Raspberry Pi OS images will come equipped with this feature.

Conclusion

The programming community has been using Debian GNU/Linux and Armbian in production-like environments without fail for many years; for example, a CubieTruck as a mobile collaboration platform (“mobile cloud”). Devices with Raspberry Pi OS have been used in experimental stages, and we were very happy about them, too. It is a great pleasure to have access to such small, reliable, affordable, and powerful machines. We wish to have more time to explore them in even more detail.

Links and References

[1] The Debian GNU/Linux project, https://www.debian.org/
[2] The Armbian project, https://www.armbian.com/
[3] ARM, Wikipedia, https://en.wikipedia.org/wiki/ARM_architecture
[4] ARM7, Wikipedia, https://en.wikipedia.org/wiki/ARM7
[5] Orange Pi, http://www.orangepi.org/
[6] Cubieboard, http://cubieboard.org/
[7] Tinkerboard, https://www.asus.com/us/Single-Board-Computer/Tinker-Board/
[8] Raspberry Pi OS, https://www.raspberrypi.org/software/operating-systems/
[9] Mikrotik, https://mikrotik.com/
[10] Frank Hofmann: Zwergenaufstand. Das Cubietruck im Alltagstest, RaspberryPi Geek 04/2016, https://www.raspberry-pi-geek.de/ausgaben/rpg/2016/04/das-cubietruck-im-alltagstest/
[11] PC Engines, https://www.pcengines.ch/
[12] Cubian, http://cubian.org/
[13] Log2Ram, https://github.com/azlux/log2ram
[14] Advantages/disadvantages of increasing “commit” in fstab, https://unix.stackexchange.com/questions/155784/advantages-disadvantages-of-increasing-commit-in-fstab
[15] Raspbian Project, https://www.raspbian.org/
[16] Unofficial Debian images for the Raspberry Pi SBC family, https://raspi.debian.net/
[17] RaspberryPi Foundation, https://www.raspberrypi.org/about/
[18] XFCE, https://xfce.org/
[19] “armhf” on Wikipedia, https://en.wikipedia.org/wiki/ARM_architecture#VFP
[20] RaspberryPi Forum, https://www.raspberrypi.org/forums/
[21] Debian Ports, https://www.ports.debian.org/

About the authors

Frank Hofmann works on the road – preferably from Berlin (Germany), Geneva (Switzerland), and Cape Town (South Africa) – as a developer, trainer, and author for magazines like Linux-User and Linux Magazine.

Axel Beckert works as a Linux system administrator and specialist for network security with the central IT services of ETH Zurich. He is also a volunteer with the Debian GNU/Linux distribution, Linux User Group Switzerland (LUGS), Hackerfunk radio show and podcast, and various open-source projects.

Hofmann and Beckert have also authored a Debian package management book

(http://www.dpmb.org).

]]>
How to Install Zabbix 5 on Raspberry Pi 4? https://linuxhint.com/install-zabbix5-on-raspberry-pi4/ Mon, 14 Dec 2020 18:53:09 +0000 https://linuxhint.com/?p=81748 Zabbix is an open-source monitoring tool, and with it, you can monitor your servers, virtual machines, networks, cloud services, and many more. It is a very useful tool for small, medium, and large IT organizations.

In this article, I will show you how to install Zabbix 5 on Raspberry Pi 4. So, let’s get started!

Things You Will Need

To follow this article, you will need the following things to set up your Raspberry Pi 4 in headless mode:

  1. A Raspberry Pi 4 single-board computer
  2. A USB Type-C power adapter
  3. A 16 GB or higher capacity microSD card with Raspberry Pi OS flashed
  4. Network connectivity on the Raspberry Pi 4
  5. A laptop or a desktop computer for VNC remote desktop access to the Raspberry Pi 4

If you don’t want to set up your Raspberry Pi 4 in headless mode, you will also need:

  1. A monitor
  2. An HDMI or micro-HDMI cable
  3. A keyboard
  4. A mouse

If you need any assistance on flashing the Raspberry Pi OS image on the microSD card, check my article How to Install and Use Raspberry Pi Imager.

If you’re a Raspberry Pi beginner and need any assistance on installing Raspberry Pi OS on your Raspberry Pi 4, check my article How to Install Raspberry Pi OS on Raspberry Pi 4.

Also, if you need any assistance on the headless setup of Raspberry Pi 4, check my article How to Install and Configure Raspberry Pi OS on Raspberry Pi 4 Without External Monitor.

Updating Raspberry Pi OS

Before installing Zabbix 5, it would be a good idea to update all the existing packages of Raspberry Pi OS.

First, update the APT package repository cache of your Raspberry Pi OS with the following command:

$ sudo apt update

To update all the existing packages of your Raspberry Pi OS, run the following command:

$ sudo apt full-upgrade

To confirm the installation, press Y, and then press <Enter>.

The APT package manager will download all the required packages from the internet. It may take a few minutes to complete.

Once all the required packages are downloaded, the APT package manager will install them one by one. Although, it may take a few minutes to complete.

At this point, all the existing packages should be updated.

For the changes to take effect, reboot your Raspberry Pi 4 with the following command:

$ sudo reboot

Adding Zabbix 5 Official Package Repository

Once your Raspberry Pi 4 boots, download the Zabbix package repository DEB file with the following command:

$ wget -O /tmp/zabbix5.deb https://repo.zabbix.com/zabbix/5.2/raspbian/pool/main/
z/zabbix-release/zabbix-release_5.2-1+debian10_all.deb

Once the download is complete, the Zabbix 5 package repository DEB file should be available in the path /tmp/zabbix5.deb.

Install the zabbix5.deb file with the following command:

$ sudo apt install /tmp/zabbix5.deb

The Zabbix 5 package repository should be added.

Now, update the APT package repository cache with the following command:

$ sudo apt update

Installing MariaDB Database Server

You need to install the MariaDB database server for storing the Zabbix 5 data.

You can install the MariaDB database server with the following command:

$ sudo apt install mariadb-server mariadb-client

To confirm the installation, press Y, and then press <Enter>.

The APT package manager will download all the required packages from the internet. It may take a while to complete.

Once the packages are downloaded, the APT package manager will install them one by one. This may take a while to complete.

At this point, MariaDB should be installed.

Once MariaDB is installed, the MariaDB database service mysqld should be running.

$ sudo systemctl status mysqld

If in any case, the MariaDB database service mysqld is not running, you can start it with the following command:

$ sudo systemctl start mysqld

Installing Zabbix 5

Now, you can install Zabbix 5 with the following command:

$ sudo apt install zabbix-server-mysql zabbix-frontend-php zabbix-apache-conf
zabbix-agent

To confirm the installation, press Y, and then press <Enter>.

The APT package manager will download all the required packages from the internet, and it may take a while to complete.

Once all the packages are downloaded, the APT package manager should install them one by one.

At this point, Zabbix 5 should be installed.

Creating a Database for Zabbix 5

Before you can use Zabbix 5, you must create a MariaDB user and database for Zabbix 5.

To create a MariaDB user zabbix, set the password to secret for the zabbix user, then run the following command:

$ sudo mysql -u root -e 'create user zabbix@localhost identified by "secret";'

To create a MariaDB database zabbix, run the following command:

$ sudo mysql -u root -e 'create database zabbix character set utf8 collate utf8_bin;'

Allow the MariaDB user zabbix full access to the MariaDB database zabbix by running the following command:

$ sudo mysql -u root -e 'grant all privileges on zabbix.* to zabbix@localhost;'

For the MariaDB database changes to take effect, run the following command:

$ sudo mysql -u root -e 'flush privileges;'

Importing Zabbix 5 Schemas on the Zabbix Database

Once a MariaDB database zabbix and MariaDB user zabbix is created, you have to import the Zabbix 5 database schemas to the MariaDB zabbix database.

You can import the Zabbix 5 database schemas to MariaDB zabbix database with the following command:

$ zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix
-Dzabbix -psecret

Configuring Zabbix 5

Once you have created the zabbix MariaDB database and imported the Zabbix 5 database schemas, you have to configure the Zabbix server to use the MariaDB database you’ve created.

To do that, open the /etc/zabbix/zabbix_server.conf file with the nano text editor as follows:

$ sudo nano /etc/zabbix/zabbix_server.conf

Scroll down a little bit and find the DBPassword= line as marked in the screenshot below.

Then, uncomment the line (remove the # sign from the beginning of the line) and set DBPassword to the MariaDB zabbix user password. In this case, it is secret.

Once you’re done, press <Ctrl> + X followed by Y and <Enter> to save the /etc/zabbix/zabbix_server.conf file.

For the changes to take effect, restart the zabbix-server systemd service with the following command:

$ sudo systemctl restart zabbix-server.service

If everything is okay, the zabbix-server service should be running.

To check whether the zabbix-server systemd service is running, run the following command:

$ sudo systemctl status zabbix-server.service

As you can see, the zabbix-server systemd service is running.

For the changes to take effect, restart the zabbix-agent systemd service with the following command:

$ sudo systemctl restart zabbix-agent.service

The zabbix-agent systemd service should be running, as you can see in the screenshot below.

$ sudo systemctl status zabbix-agent.service

Also, restart the apache2 systemd service with the following command:

$ sudo systemctl restart apache2

The apache2 systemd service should also be running, as you can see in the screenshot below.

$ sudo systemctl status apache2.service

Adding Zabbix Server to the System Startup

To make sure that the Zabbix server starts automatically when your Raspberry Pi 4 boots, add the zabbix-server systemd service to the system startup with the following command:

$ sudo systemctl enable zabbix-server.service

Accessing Zabbix 5 Web Application

Once Zabbix 5 is installed and configured, you can access the Zabbix 5 web app from any device on your home network using a web browser.

To access the Zabbix 5 web app from other devices on your home network, you need the IP address of your Raspberry Pi 4.

You can find the IP address of your Raspberry Pi 4 with the following command:

$ hostname -I

As you can see, the IP address of my Raspberry Pi 4 is 192.168.0.104. It will be different for you. So, make sure to replace it with yours from now on.

To access the Zabbix 5 web app, visit http://192.168.0.104/zabbix from a web browser.

As you’re running Zabbix 5 web app for the first time, you need to configure it.

Select your language, and click on Next step.

Make sure everything is okay and click on Next step.

Select MySQL as the database type. Then, type in zabbix as the database name, zabbix as the user name, and secret as the password.

Once you’re done, click on Next step.

Click on Next step.

Select your time zone and default theme for the Zabbix 5 web app. Once you’re done, click on Next step.

Make sure all the information is correct. If it is, click on Next step.

Zabbix 5 web app should be configured. Click on Finish.

You should see the Zabbix 5 login window.

Type in Admin as the username and zabbix as the password. Then, click on Sign In.

You should be logged in to the Zabbix 5 web app.

Changing the Admin Login Password of Zabbix 5

The first thing you want to do after you have logged in to the Zabbix 5 web app is to change the default password for the Admin user for security purposes.

To do that, click on Administration > Users > Admin from the Zabbix 5 web app as marked in the screenshot below.

Click on Change password.

Type in your desired password and click on Update.

The default password of the Admin user should be changed. Now, you should be able to log in to the Zabbix 5 web app using your newly set password.

Summary

In this article, I have shown you how to install Zabbix 5 on Raspberry Pi 4 single-board computer and access the Zabbix 5 web app from other devices on your home network. This article should help you to get started with Zabbix 5 on your Raspberry Pi 4.

]]>
5 Best Linux Distributions for Raspberry Pi Compared https://linuxhint.com/5-best-linux-distributions-for-raspberry-pi-compared/ Thu, 10 Dec 2020 12:03:35 +0000 https://linuxhint.com/?p=80869 There are many Linux distributions (operating systems) for the Raspberry Pi single-board computers. In this article, I am going to talk about the 5 best Linux distributions for the Raspberry Pi. So, let’s get started!

Raspberry Pi OS

Raspberry Pi OS was previously known as Raspbian OS. It is the official operating system for the Raspberry Pi single-board computers.

Raspberry Pi OS is based on Debian GNU/Linux. The latest version of the Raspberry Pi OS (at the time of this writing) is based on Debian 10 Buster (the latest stable version of Debian). Raspberry Pi OS is very lightweight for the Raspberry Pi single-board computers. You can run it on every single version (older and newer) of the Raspberry Pi single-board computers.

There are 3 versions of the Raspberry Pi OS available for download on the official website of Raspberry Pi, these are the following:

  • Raspberry Pi OS with desktop and recommended software
    This Raspberry Pi OS image has most of the necessary software and libraries required for Raspberry Pi projects and the Raspberry Pi OS desktop environment pre-installed.
  • Raspberry Pi OS with desktop
    This Raspberry Pi OS image only has the bare minimum number of programs and the Raspberry Pi OS desktop environment pre-installed.
  • Raspberry Pi OS Lite
    This is the minimal version of the Raspberry Pi OS. It does not have any Raspberry Pi OS desktop environment pre-installed. So, you will have to do your work from the command line. Also, a very limited number of command line programs are pre-installed. This one requires a very little amount of RAM to run. So, you will be able to use almost all of the RAM of your Raspberry Pi for other programs.

Raspberry Pi OS Requirements:

Supported Devices: Raspberry Pi 400, Raspberry Pi 4 Model B, Raspberry Pi 3 (Model A+, Model B+, and Model B), Raspberry Pi 2 Model B, Raspberry Pi 1 (Model B+ and Model A+), Raspberry Pi Zero W, and Raspberry Pi Zero

OS Architecture: 32-bit (stable) and 64-bit (beta)

MicroSD Card: 8 GB (for Raspberry Pi OS Lite) and 16 GB (for Raspberry Pi OS with desktop)

You can download Raspberry Pi OS from the official website of Raspberry Pi.

If you need any assistance on installing Raspberry Pi OS on your Raspberry Pi, check my other articles:

Here is a screenshot of the Raspberry Pi OS (with the desktop environment) running on the Raspberry Pi.

Ubuntu

Ubuntu is a good and stable operating system for the Raspberry Pi single-board computers. If you want to use your Raspberry Pi for IoT projects or as a desktop computer, you will surely love Ubuntu. IT also has official supports for many Raspberry Pi devices.

You can install Ubuntu Server 20.04.1 (LTS), Ubuntu Server 20.10 (non-LTS), as well as Ubuntu Desktop 20.10 (non-LTS) on your Raspberry Pi single-board computers.

Ubuntu Server 20.04 LTS and Ubuntu Server 20.10 Requirements:

Supported Devices: Raspberry Pi 400, Raspberry Pi 4 Model B, Raspberry Pi 3 (Model A+, Model B+, and Model B), and Raspberry Pi 2 Model B

OS Architecture: 32-bit and 64-bit

MicroSD Card: 8 GB or more

Ubuntu Desktop 20.10 Requirements:

Supported Devices: Raspberry Pi 400 and Raspberry Pi 4 Model B

OS Architecture: only 64-bit.

MicroSD Card: 32 GB or more

You can download Ubuntu for Raspberry Pi from the official website of Ubuntu.

If you need any assistance on installing Ubuntu on your Raspberry Pi, check my other articles:

Fedora

Fedora is also a great operating system for the Raspberry Pi. There are different versions of the Fedora operating system for Raspberry Pi’s different purposes.

The versions of the Fedora operating system for the Raspberry Pi are:

  • Fedora Workstation
  • This is a desktop operating system for the Raspberry Pi that uses the GNOME 3 desktop environment. You can use it on your Raspberry Pi 4 and Raspberry Pi 400.

  • Fedora Server
  • This is a headless server version of the Fedora operating system, and it does not come with any graphical desktop environment. So, it is lightweight and does not consume a lot of memory. You can run it on your Raspberry Pi 3 or Raspberry Pi 4 single-board computers.

  • Fedora IoT
  • This is also a headless version of the Fedora operating system that does not come with any graphical desktop environment installed. It is more lightweight than the server version. You can use the Fedora IoT version on older versions of the Raspberry Pi (i.e., Raspberry Pi 2, Raspberry Pi 1, Raspberry Pi Zero) as well.

Fedora Workstation Requirements:

Supported Devices: Raspberry Pi 400 and Raspberry Pi 4 Model B

OS Architecture: 64-bit only

MicroSD Card: 32 GB or more

Fedora Server Requirements:

Supported Devices: Raspberry Pi 400, Raspberry Pi 4 Model B, and Raspberry Pi 3 (Model A+, Model B+, and Model B)

OS Architecture: 64-bit only

MicroSD Card: 16 GB or more.

Fedora IoT Requirements:

Supported Devices: Raspberry Pi 400, Raspberry Pi 4 Model B, Raspberry Pi 3 (Model A+, Model B+, and Model B), Raspberry Pi 2 Model B, Raspberry Pi 1 (Model B+ and Model A+), Raspberry Pi Zero W, and Raspberry Pi Zero

OS Architecture: 32-bit and 64-bit

MicroSD Card: 8 GB or more

You can download Fedora for Raspberry Pi from the official website of Fedora.

If you need any assistance on installing Fedora on your Raspberry Pi, check my article on How to Install Fedora 33 on Raspberry Pi 4.

Here is a screenshot of the Fedora 33 Workstation running on the Raspberry Pi 4.

Manjaro

Manjaro is a great desktop operating system for the Raspberry Pi 4 and Raspberry Pi 400 single-board computers.

There are many versions of the Manjaro Linux distribution for the Raspberry Pi 4 and Raspberry Pi 400 single-board computers.

  • XFCE
  • This is a version of the Manjaro desktop operating system that is shipped with the XFCE desktop environment.

  • KDE Plasma
  • This is a version of the Manjaro desktop operating system that is shipped with the KDE Plasma 5 desktop environment.

  • i3
  • This is a version of the Manjaro desktop operating system that is shipped with the i3 tiling window manager.

  • Sway
  • This is a version of the Manjaro desktop operating system that is shipped with the Sway tiling window manager.

Manjaro (XFCE, KDE Plasma, i3, and Sway) Requirements:

Supported Devices: Raspberry Pi 400 and Raspberry Pi 4 Model B

OS Architecture: 64-bit only

MicroSD Card: 32 GB or more

You can download Manjaro for Raspberry Pi 4 and Raspberry Pi 400 from the official website of Manjaro.

If you need any assistance on installing Manjaro on your Raspberry Pi, check my article: Install Manjaro on Raspberry Pi 4.

Here is a screenshot of the Manjaro – KDE Plasma desktop environment running on the Raspberry Pi 4.

Kali Linux

Kali Linux is a Debian based operating system specially made for penetration testing. It has all the required tools for penetration testing installed by default. However, even if something is not installed by default, it will be on its official package repository, so you can easily install whatever you need from there. Kali Linux is also any penetration tester’s best friend.

There are different versions of the Kali Linux image for every different version of the Raspberry Pi single-board computer.

  • Kali Linux Rpi (img.xz)
  • This is a Kali Linux image for Raspberry Pi 1 (Model B+ and Model A+) single-board computers.

  • Kali Linux RaspberryPi 2, 3 and 4 (img.xz)
  • This is a 32-bit Kali Linux image for Raspberry Pi 400, Raspberry Pi 4 Model B, Raspberry Pi 3 (Model A+, Model B+, and Model B), and Raspberry Pi 2 Model B single-board computers.

  • Kali Linux RaspberryPi 2 (v1.2), 3 and 4 (64-bit) (img.xz)
  • This is a 64-bit Kali Linux image for Raspberry Pi 400, Raspberry Pi 4 Model B, Raspberry Pi 3 (Model A+, Model B+, and Model B), and Raspberry Pi 2 v1.2 single-board computers.

  • Kali Linux RaspberryPi Zero/Zero W (img.xz)
  • This is a Kali Linux image for Raspberry Pi Zero W and Raspberry Pi Zero single-board computers.

Kali Linux Requirements:

Supported Devices: Raspberry Pi 400, Raspberry Pi 4 Model B, Raspberry Pi 3 (Model A+, Model B+, and Model B), Raspberry Pi 2 Model B, Raspberry Pi 1 (Model B+ and Model A+), Raspberry Pi Zero W, and Raspberry Pi Zero

OS Architecture: 32-bit and 64-bit

MicroSD Card: 32GB or more

You can download Kali Linux for Raspberry Pi from the official website of Offensive Security.

If you need any assistance on installing Kali Linux on your Raspberry Pi, check my article: Install Kali Linux on Raspberry Pi 4.

Here is a screenshot of Kali Linux running on the Raspberry Pi 4.

Conclusion

In this article, I have talked about the 5 best Linux distribution for Raspberry Pi. I have included headless operating systems, as well as desktop operating systems. If you’re new to the Raspberry Pi world, this article should help you pick a Linux distribution for your Raspberry Pi single-board computer.

]]>
How to Set Up a Raspberry Pi Network Monitor? https://linuxhint.com/set_up_raspberry_pi_network_monitor/ Wed, 09 Dec 2020 05:33:14 +0000 https://linuxhint.com/?p=80379

Zabbix is an open-source monitoring tool in which you can monitor your servers, virtual machines, networks, cloud services, and many more. It is a very useful tool for small, medium, and large IT organizations.

You can install the Zabbix on the Raspberry Pi and monitor the network of other computers/servers in your home network using it.

In this article, I am going to show you how to set up Zabbix on your Raspberry Pi to monitor the network of other computers/servers in your home network.

Things You Will Need

To follow this article, you need a Raspberry Pi single-board computer with Zabbix 5 installed on it.

If you need any assistance on installing Zabbix 5 on your Raspberry Pi single-board computer, read my article on How to Install Zabbix 5 on Raspberry Pi 4.

I have installed Zabbix 5 on my Raspberry Pi (running the Raspberry Pi OS). The IP address of my Raspberry Pi is 192.168.0.106. So, I will be accessing the Zabbix 5 web app using the URL http://192.168.0.106/zabbix. The IP address of your Raspberry Pi will be different. So make sure to replace it with yours from now on.

What is Zabbix Agent?

Zabbix has 2 components: 1) Zabbix Server and 2) Zabbix Agent.

If you want to monitor your computer/server with Zabbix, you must have the Zabbix Agent installed and running on your computer/server. It will communicate and send necessary data to the Zabbix Server (running on your Raspberry Pi).

Installing Zabbix Agent on Ubuntu/Debian/Raspberry Pi OS

Zabbix Agent is available in the official package repository of Ubuntu/Debian/Raspberry Pi OS. So, it is easy to install.

First, update the APT package repository cache with the following command:

$ sudo apt update


You can install the Zabbix Agent with the following command:

$ sudo apt install zabbix-agent -y


Zabbix Agent should be installed.

Open the Zabbix Agent configuration file /etc/zabbix/zabbix_agentd.conf with the following command:

$ sudo nano /etc/zabbix/zabbix_agentd.conf


Change the Server variable to the IP address of your Zabbix Server (the IP address of your Raspberry Pi).


Also, make sure that the Hostname variable is set to the hostname of your computer/server. If you don’t know the hostname of your computer/server, you can run the hostname command and find it out.

Once you’re done, press <Ctrl> + X followed by Y and <Enter> to save the /etc/zabbix/zabbix_agentd.conf file.


For the changes to take effect, restart the zabbix-agent service with the following command:

$ sudo systemctl restart zabbix-agent


The zabbix-agent should be running, as you can see in the screenshot below.

$ sudo systemctl status zabbix-agent

Installing Zabbix Agent on CentOS/RHEL 8

To install Zabbix Agent on CentOS/RHEL 8, you must add the Zabbix package repository to your CentOS/RHEL 8 computer/server.

To add the Zabbix package repository to your CentOS/RHEL 8, run the following command:

$ sudo rpm -Uvh https://repo.zabbix.com/zabbix/5.2/rhel/8/x86_64/zabbix-release-5.2-1.el8.noarch.rpm


The Zabbix Package repository should be added.


Update the DNF package repository cache with the following command:

$ sudo dnf makecache


To install Zabbix Agent, run the following command:

$ sudo dnf install zabbix-agent


To confirm the installation, press Y, and then press <Enter>.


To accept the GPG key, press Y, and then press <Enter>.


Zabbix Agent should be installed.

Open the Zabbix Agent configuration file /etc/zabbix/zabbix_agentd.conf with the following command:

$ sudo nano /etc/zabbix/zabbix_agentd.conf


Change the Server variable to the IP address of your Zabbix Server (the IP address of your Raspberry Pi).


Also, make sure that the Hostname variable is set to the hostname of your computer/server. If you don’t know the hostname of your computer/server, you can run the hostname command and find it out.

Once you’re done, press <Ctrl> + X followed by Y and <Enter> to save the /etc/zabbix/zabbix_agentd.conf file.


Start the zabbix-agent systemd service with the following command:

$ sudo systemctl start zabbix-agent.service


The zabbix-agent service should be running, as you can see in the screenshot below.

$ sudo systemctl status zabbix-agent.service


Add the zabbix-agent service to the system startup so that it starts automatically on system boot:

$ sudo systemctl enable zabbix-agent.service


Run the following command to configure the firewall to allow access to the Zabbix Agent port 10050:

$ sudo firewall-cmd --add-service=zabbix-agent --permanent


For the firewall changes to take effect, run the following command:

$ sudo firewall-cmd --reload

Installing Zabbix Agent on Windows 10

On Windows 10, you have to download the Zabbix Agent software from the official website of Zabbix.

First, visit the official download page of Zabbix Agent from a web browser.

Once the page loads, select the Windows MSI package as marked in the screenshot below.


Then, scroll down a little bit, and click on the first DOWNLOAD link as marked in the screenshot below.


Zabbix Agent installer should be downloaded. Run the installer.


Click on Next.


Check the I accept the terms in the License Agreement checkbox and click on Next.


Make sure that the hostname is correct. Type in the Zabbix server IP address and check the Add agent location to the PATH checkbox.

Once you’re done, click on Next.


Click on Next.


Click on Install.


Click on Yes.

Zabbix Agent should be installed. Click on Finish.

Adding a Linux Host to Zabbix

Once the Zabbix Agent is installed on your computer/server, you can add it to the Zabbix Server (running on your Raspberry Pi).

First, log in to the Zabbix web app and go to Configuration > Hosts. Then, click on Create host, as marked in the screenshot below.


Type in the hostname of the computer/server you’re trying to add in the Host name field. Then, click on Select, as marked in the screenshot below.


Check the Linux servers checkbox, and click on Select.


Click on Add, as marked in the screenshot below.


Click on Agent.


Type in the IP address of the computer/server you’re trying to add to Zabbix.


Once you’re done, click on Add.


The Linux host should be added to Zabbix, as you can see in the screenshot below.

Adding a Windows 10 Host to Zabbix

In this section, I am going to show you how to add a Windows 10 host to Zabbix. So, let’s get started.

Just to keep things organized, let’s create a new host group for Windows hosts.

To create a host group, go to Configuration > Host groups from the Zabbix web app. Then, click on the Create host group.


Type in Windows Hosts, and click on Add.


A new host group, Windows Hosts, should be added.


To add your Windows 10 host to Zabbix, go to Configuration > Hosts. Then, click on Create host.


Type in the hostname or computer name of your Windows 10 host in the Host name field. Then, click on Select, as marked in the screenshot below.

Check the newly created group Windows Hosts, and click on Select.


Click on Add, as marked in the screenshot below.


Click on Agent.


Type in the IP address of your Windows 10 host, and click on Add.


Your Windows 10 host should be added to Zabbix.

Monitoring Network Usage of Linux Hosts

In this section, I am going to show you how to monitor the network usage of Linux Hosts using Zabbix 5. So, let’s get started.

First, navigate to Configuration > Hosts and click on the Linux Host that you want to monitor network usage.

Click on Templates.


Click on Select, as marked in the screenshot below.


Click on Select, as marked in the screenshot below.


Click on Templates, as marked in the screenshot below.


Check Linux network interfaces by Zabbix agent checkbox, and click on Select.


Click on Update.


The Linux host should be updated.


After a while, the ZBX availability option should be highlighted, as you can see in the screenshot below.


When the ZBX option is highlighted, navigate to Monitoring > Hosts and click on the Dashboards link of your Linux host, as you can see in the screenshot below.


As you can see, the network usage graph is being displayed.


You can change the timeline of the graph as well. As you can see, I have changed the graph time to the Last 15 minutes. The graph is being displayed nicely.


This is how you monitor the network usage of a Linux host using Zabbix on your Raspberry Pi.

Monitoring Network Usage of Windows Hosts

In this section, I am going to show you how to monitor the network usage of Windows 10 Hosts using Zabbix 5. So, let’s get started.

First, navigate to Configuration > Hosts and click on the Windows 10 Host that you want to monitor network usage.


Click on Templates.

Click on Select, as marked in the screenshot below.


Click on Select, as marked in the screenshot below.


Click on Templates, as marked in the screenshot below.


Check Windows network by Zabbix agent, and click on Select.


Click on Update.


The Windows 10 host should be updated.


After a while, the ZBX availability option should be highlighted, as you can see in the screenshot below.


When the ZBX option is highlighted, navigate to Monitoring > Hosts and click on the Dashboards link of your Windows 10 host, as you can see in the screenshot below.


As you can see, the network usage graph is being displayed.


You can change the timeline of the graph as well. As you can see, I have changed the graph time to the Last 15 minutes. The graph is being displayed nicely.


This is how you monitor the network usage of a Windows 10 host using Zabbix on your Raspberry Pi.

Conclusion

In this article, I have shown you how to create a Raspberry Pi network monitor using Zabbix 5. I have shown you how to use Zabbix to monitor the network usage of Linux and Windows hosts on your Raspberry Pi.

]]>
Securing Raspberry Pi with Firewall https://linuxhint.com/securing_raspberry_pi_firewall/ Mon, 07 Dec 2020 05:01:45 +0000 https://linuxhint.com/?p=79671

If you want to run some kind of server software on your Raspberry Pi (i.e., web server, database server, Minecraft server) and make them publicly available on the internet (hosting), then securing your Raspberry Pi server with a firewall program is very important.

There are many free and open-source firewall programs available on the Raspberry Pi OS (the official operating system of Raspberry Pi single-board computers). Among these programs, UFW and Firewalld are the most common firewall programs.

In this article, I will use the UFW firewall program to show you how to secure your Raspberry Pi. So, let’s get started.

Things You Will Need:

To follow this article, you will need the following things to set up your Raspberry Pi in headless mode:

  1. A Raspberry Pi 3 or Raspberry Pi 4 single-board computer.
  2. A micro-USB (Raspberry Pi 3) or USB Type-C (Raspberry Pi 4) power adapter.
  3. A 16 GB or 32 GB microSD card with Raspberry Pi OS flashed.
  4. Network connectivity on the Raspberry Pi.
  5. A laptop or a desktop computer for VNC remote desktop access or SSH access to the Raspberry Pi.

If you don’t want to set up your Raspberry Pi 4 in headless mode, you will also need:

  1. A monitor
  2. A HDMI or micro-HDMI cable
  3. A keyboard
  4. A mouse.

If you need any assistance on flashing the Raspberry Pi OS image on the microSD card, check my article How to Install and Use Raspberry Pi Imager.

If you’re a Raspberry Pi beginner and need any assistance on installing Raspberry Pi OS on your Raspberry Pi, check my article How to Install Raspberry Pi OS on Raspberry Pi 4.

If you need any assistance on the headless setup of Raspberry Pi, check my article How to Install and Configure Raspberry Pi OS on Raspberry Pi 4 Without External Monitor.

Updating Raspberry Pi OS:

As we are trying to secure our Raspberry Pi, it’s a good idea to update all the existing packages of the Raspberry Pi OS. This will make your Raspberry Pi OS more secure because it would install all the latest security updates and bug fixes.

First, update the APT package repository cache with the following command:

$ sudo apt update


To update all the existing packages of your Raspberry Pi OS, run the following command:

$ sudo apt full-upgrade


To confirm the installation of the updates, press Y and then press <Enter>.


The APT package manager will download all the required packages from the internet. It may take a while to complete.


Once the packages are downloaded, the APT package manager will install them one by one. It may take a while to complete.


At this point, all the updates should be installed.

For the changes to take effect, reboot your Raspberry Pi with the following command:

$ sudo reboot

Installing UFW – Uncomplicated Firewall:

Once your Raspberry Pi boots, you can install the UFW firewall program with the following command:

$ sudo apt install ufw -y


UFW should be installed.


For the changes to take effect, reboot your Raspberry Pi with the following command:

$ sudo reboot


Once your Raspberry Pi boots, the ufw systemd service should be active, as you can see in the screenshot below.

$ sudo systemctl status ufw


You can check whether UFW is enabled with the following command:

$ sudo ufw status


As you can see, UFW is not enabled by default.


To enable UFW, run the following command:

$ sudo ufw enable


As you can see, UFW is now enabled.

$ sudo ufw status

Allowing Access to the Ports using App Profiles:

UFW has some default app profiles. Each of the app profiles has some predefined ports that you can allow/deny access to.

To list all the available app profiles, run the following command:

$ sudo ufw app list


All the installed app profiles should be listed.

If you’re connected to your Raspberry Pi via SSH or VNC (like me), you must allow access to the OpenSSH and VNC app profiles. Otherwise, the next time you boot your Raspberry Pi, you won’t be able to access it remotely as the firewall will block all ports, including the SSH and VNC ports. So, this is very important.


You can see what ports are defined in an app profile (i.e., OpenSSH) with the following command:

$ sudo ufw app info OpenSSH


As you can see, TCP port 22 is defined in the app profile OpenSSH.


In the same way, the TCP port 5900 is defined in the VNC app profile.

$ sudo ufw app info VNC


To allow access to the ports defined in the VNC app profile, run the following command:

$ sudo ufw allow VNC


As you can see, the VNC app profile is allowed through the firewall.

$ sudo ufw status numbered


In the same way, allow access to the ports defined in the OpenSSH app profile with the following command:

$ sudo ufw allow OpenSSH


As you can see, the OpenSSH app profile is allowed through the firewall.

$ sudo ufw status numbered

Allowing Access to the Ports using Port Number:

At times, the port you want to allow/deny access to will not be defined in any available app profiles. So, you will need to allow/deny access to these ports using the port number.

For example, you can allow access to the TCP port 8080 with the following command:

$ sudo ufw allow 8080/tcp


As you can see, the TCP port 8080 is allowed access through the firewall.

$ sudo ufw status numbered


In the same way, you can allow access to the UDP port 8888 with the following command:

$ sudo ufw allow 8888/udp


As you can see, the UDP port 8888 is allowed access through the firewall.

$ sudo ufw status numbered

Denying Access to Ports:

The default behavior of the UFW firewall program is to deny everything that is not allowed. So, you don’t need to do anything to deny access to any ports.

For the sake of competition, I will show you how to deny ports in UFW anyway.

For example, to deny access to the TCP port 9900, run the following command:

$ sudo ufw deny 9900/tcp


As you can see, the TCP port 9900 is denied access through the firewall.

$ sudo ufw status numbered


In the same way, you can deny the ports defined in an app profile (i.e.,  WWW) as follows:

$ sudo ufw deny WWW

Denying Specific IP Addresses Access to the Server:

At times you may need to deny access to a specific IP address or IP subnet to protect your Raspberry Pi server from DDoS (Distributed Denial of Service) attacks. You can do that with UFW.

To experiment with denying IP addresses, I will use the Apache webserver.

You can install the Apache webserver on your Raspberry Pi with the following command:

$ sudo apt install apache2


To confirm the installation, press Y and then press <Enter>.


The APT package manager will download all the packages from the internet and install them one by one. It may take a while to complete.


At this point, the Apache webserver should be installed.


Once the Apache webserver is installed, create a simple index page with the following command:

$ echo "<h1>Welcome to LinuxHint</h1>" | sudo tee /var/www/html/index.html


The apache2 systemd service should be running, as you can see in the screenshot below.

$ sudo systemctl status apache2


Allow access to the Apache webserver port (TCP port 80) using the app profile WWW as follows:

$ sudo ufw allow www


As you can see, the ports defined in the app profile WWW is allowed access through the firewall.


Find the IP address of your Raspberry Pi with the following command:

$ hostname -I


As you can see, the IP address of my Raspberry Pi is 192.168.0.106. It will be different for you. So, make sure to replace it with yours from now on.


You should access the Apache webserver from other devices, as you can see in the screenshot below.


The computer I am using to access the Apache webserver has the IP address 192.168.0.109.


To deny the IP address 192.168.0.109 access to your Raspberry Pi server, you must add the firewall rule at the top (position 1). The order of the UFW rules matters a lot. The most restrictive rules should go first.

$ sudo ufw status numbered


To deny the IP address 192.168.0.109 access to the Raspberry Pi server, run the following command:

$ sudo ufw insert 1 deny from 192.168.0.109 to any


The UFW rule to deny the IP address 192.168.0.109 access to the Raspberry Pi server should be the topmost rule, as shown in the screenshot below.

$ sudo ufw status numbered


You won’t be able to access the Apache webserver running on your Raspberry Pi from the computer with the IP address 192.168.0.109 anymore, as you can see in the screenshot below.


But, you can access the Apache webserver running on your Raspberry Pi from other computers.


If you want to deny access to an IP subnet, you must add the required UFW rule before the rule you have added earlier, as it is a more restrictive rule.

$ sudo ufw status numbered


For example, to deny access to every computer in an IP subnet 192.168.20.0/24, run the following command:

$ sudo ufw insert 1 deny from 192.168.20.0/24 to any


The UFW rule should be added in the correct position, as shown in the screenshot below. Now, no computer from the IP subnet 192.168.20.0/24 should be able to access your Raspberry Pi server.

$ sudo ufw status numbered

Removing UFW Rules:

At times, you may need to remove some UFW rules. It is very easy to do so.

You can list all the available UFW rules with the following command:

$ sudo ufw status numbered


All the available UFW rules should be listed. Let’s say you want to remove the UFW rule number 10 (rule at the 10th position).


To remove the UFW rule number 10, run the following command:

$ sudo ufw delete 10


To confirm the remove operation, press Y and then press <Enter>.


The UFW rule number 10 should be removed.


As you can see, the UFW rule is removed, and the rules are reordered (The UFW rule that was in position 11 is now in position 10).

$ sudo ufw status numbered

Conclusion:

In this article, I have shown you how to install the UFW firewall program on your Raspberry Pi (running the Raspberry Pi OS). I have also shown you how to allow/deny ports using the UFW firewall program. I have shown you how to deny a specific IP address or an IP subnet from accessing the Raspberry Pi using the UFW firewall program as well.

]]>
How to Enable KVM Kernel Module on Raspberry Pi OS? https://linuxhint.com/enable_kvm_kernel_module_on_raspberry_pi_os/ Mon, 30 Nov 2020 15:49:35 +0000 https://linuxhint.com/?p=78810

The KVM, or Kernel Virtual Machine, is the virtualization solution for Linux. It is a Linux kernel module that allows the Linux kernel to act as a hypervisor program like VMware ESXi or VSphere.

Earlier it was impossible to get KVM running on the Raspberry Pi using the Raspberry Pi OS (also known as Raspbian). This is because KVM only works on a 64-bit operating system. Raspberry Pi OS was a 32-bit operating system. Another reason was that Raspberry Pi 3 and earlier models had only 1 GB of memory, and this is insufficient to run KVM. Docker was a better solution for devices with 1 GB of memory.

At the time of this writing, it is possible to run KVM on the Raspberry Pi using the Raspberry Pi OS. Because Raspberry Pi OS officially ships with a 64-bit kernel, and the Raspberry Pi 4 has an 8 GB model (it has 8 GB of memory). Sadly, the 64-bit Raspberry Pi OS kernel is not enabled by default. You have to enable it manually.

In this article, I am going to show you how to enable the 64-bit Raspberry Pi OS kernel and install KVM on the Raspberry Pi OS.

So, let’s get started!

Things You Will Need:

To follow this article, you will need the following things to set up your Raspberry Pi 4 in headless mode:

  1. Raspberry Pi 4 (8 GB version recommended, 4 GB version will also work) single-board computer
  2. USB Type-C power adapter
  3. 32 GB or higher capacity MicroSD card with Raspberry Pi OS (with the desktop environment) flashed
  4. Network connectivity on the Raspberry Pi 4
  5. Laptop or desktop computer for VNC remote desktop access to the Raspberry Pi 4

If you don’t want to set up your Raspberry Pi 4 in headless mode, you will also need:

  1. Monitor
  2. HDMI or micro-HDMI cable
  3. Keyboard
  4. Mouse

If you need any assistance on flashing the Raspberry Pi OS image on the MicroSD card, check my article How to Install and Use Raspberry Pi Imager.

If you’re a Raspberry Pi beginner and you need any assistance on installing Raspberry Pi OS on your Raspberry Pi 4, check my article How to Install Raspberry Pi OS on Raspberry Pi 4.

Also, if you need any assistance on the headless setup of Raspberry Pi 4, check my article How to Install and Configure Raspberry Pi OS on Raspberry Pi 4 Without External Monitor.

Upgrading Raspberry Pi OS

Before enabling the 64-bit kernel and installing KVM on the Raspberry Pi OS, it’s a good idea to upgrade all the existing packages of your Raspberry Pi OS. This will update the kernel if there is any new version of the kernel available or fix known bugs (if there are any).

Let’s check the kernel version before upgrading all the existing packages of Raspberry Pi OS.

$ uname -r

As you can see, I am running the kernel version 5.4.51 compiled for the ARMv7l architecture.

Now, let’s upgrade all the existing packages of Raspberry Pi OS.

First, update all the APT package repository cache with the following command:

$ sudo apt update

To upgrade all the existing packages (including the kernel), run the following command:

$ sudo apt full-upgrade

To confirm the installation, press Y and then press <Enter>.

The APT package manager will download all the required packages from the internet but it will take a while to complete.

Once the download is complete, it will automatically install them. It will take a while to complete.

At this point, all the updates should be installed.

For the changes to take effect, reboot your Raspberry Pi 4 with the following command:

$ sudo reboot

Once your Raspberry Pi 4 starts, you may see that the kernel version has been updated.

Enabling 64-bit Kernel on Raspberry Pi OS

On the latest release of Raspberry Pi OS, the 64-bit kernel is distributed along with the 32-bit kernel by default. The 64-bit kernel is still in beta. So, it is not set as the default kernel on the Raspberry Pi OS.

To use the 64-bit kernel on the Raspberry Pi OS, open the /boot/config.txt file with the nano text editor as follows:

$ nano /boot/config.txt

Add arm_64bit=1 at the end of the /boot/config.txt file as marked in the screenshot below.

Once you’re done, press <Ctrl> + X followed by Y and <Enter> to save the /boot/config.txt file.

For the changes to take effect, restart your Raspberry Pi 4 with the following command:

$ sudo reboot

Once your Raspberry Pi 4 starts, check the kernel version with the following command:

$ uname -r

You should see v8+ at the end of the kernel version, as you can see in the marked section of the screenshot below. It means we are using the 64-bit kernel.

The file /dev/kvm should also be available, as you can see in the screenshot below.

$ sudo ls -lh /dev/kvm

Installing KVM/QEMU:

Once the 64-bit kernel is enabled, you can install KVM, QEMU, and Virtual Machine Manager with the following command:

$ sudo apt install virt-manager libvirt0 qemu-system

To confirm the installation, press Y and then press <Enter>.

The APT package manager will download all the required packages from the internet. It may take a while to complete.

Once the packages are downloaded, the APT package manager will install them. It may take a while to complete.

At this point, all the required packages should be installed.

Now, add the pi user to the libvirt-qemu group with the following command:

$ sudo usermod -aG libvirt-qemu $(whoami)

For the changes to take effect, reboot your Raspberry Pi 4 with the following command:

$ sudo reboot

Once your Raspberry Pi 4 boots, start the default KVM network with the following command:

$ sudo virsh net-start default

To make sure that the default KVM network starts automatically on boot, run the following command:

$ sudo virsh net-autostart default

Downloading Alpine Linux ISO Installation Image

In this article, I will be installing Alpine Linux on a KVM virtual machine to test KVM on the Raspberry Pi OS.

NOTE: At the time of this writing, KVM acceleration or hardware acceleration is not available on Raspberry Pi OS. Operating systems will run in emulation mode in a KVM virtual machine. So, we won’t get much performance out of it. This is why I picked Alpine Linux for the demonstration. It is also a very lightweight operating system. Even though the virtual machine will run in emulation mode, we can still test it out. Hopefully, in a later update of the Raspberry Pi OS, KVM acceleration or hardware acceleration will be available. But, right now, this is as far as we can go.

To download the Alpine Linux ISO installation image, visit the official website of Alpine Linux.

Once the page loads, click on Downloads.

Once the page loads, scroll down a little bit and click on the VIRTUAL aarch64 download link as marked in the screenshot below.

Your browser should start downloading the Alpine AARCH ISO installation image. It may take a few seconds to complete.

Moving the Alpine Linux ISO Image to the KVM Image Directory:

Once the Alpine ISO image is downloaded, you should be able to find it in the ~/Downloads directory.

$ ls -lh ~/Downloads

Move the Alpine ISO image to the /var/lib/libvirt/images directory as follows:

$ sudo mv -v ~/Downloads/alpine-virt-3.12.1-aarch64.iso /var/lib/libvirt/images/

Creating an Alpine Linux KVM Virtual Machine

To create an Alpine Linux KVM virtual machine, start Virtual Machine Manager from Raspberry Pi Menu > System Tools > Virtual Machine Manager, as marked in the screenshot below.

Type in your login password and press <Enter>.

Now, click on the marked icon (), as shown in the screenshot below.

Select Local install media (ISO image or CDROM) from the list and click on Forward.

Click on Browse

Select the Alpine ISO image from the list and click on Choose Volume.

Uncheck the Automatically detect from the installation media/source checkbox.

Search for alpine and select Alpine Linux 3.8 (or higher if it’s available by the time you read this article) from the list.

Click on Forward.

Set the amount of memory and the number of CPU cores you want for this virtual machine.

Once you’re done, click on Forward.

Set the disk size of this virtual machine and click on Forward.

Type in a name for the virtual machine and click on Finish.

The virtual machine is being created. It may take a few seconds to complete.

Once the virtual machine is created, it should boot from the Alpine ISO installation image, as you can see in the screenshot below.


After a few seconds, you should see the Alpine Linux login window.

The default username is root. By default, no password is set for the root user. So, just type in root and press <Enter>.

You should be logged in. You can try out Alpine Linux from here.

If you like Alpine Linux and want to install it permanently on the hard disk of the virtual machine, run the following command:

$ setup-alpine

Alpine Linux setup is being initialized. It may take a few seconds.

Shortly, you should see the following window.

To set a keyboard layout, type in the 2-letter keyboard layout code from the list and press <Enter>.

To set a keyboard layout variant, type in the keyboard layout variant code from the list and press <Enter>.

Type in the hostname and press <Enter>.

Press <Enter>.

Press <Enter>.

Press <Enter>.

Type in your desired root login password and press <Enter>.

Re-type the root login password and press <Enter>.

The setup wizard is being initialized. It may take a few seconds.

Once you see the following window, press <Enter>.

Press <Enter>.

Press <Enter>.

You may see the following error while installing Alpine Linux on the disk.

At times, Alpine Linux fails to connect to the internet and fetch the Alpine package repository mirror database. This is when you see this error. Luckily, it’s easy to solve.

Press f and then press <Enter> as many times as you see this error.

Once you see the mirror list, select one of the mirrors (by typing in the mirror number) and press <Enter>.

You can also press f and then press <Enter> to let Alpine automatically pick the fastest mirror.

Once a mirror is selected, you should see the following window.

Press <Enter>.

OpenSSH server should be installed.

Now, Alpine should tell you to select a disk where you want to install Alpine Linux.

We want to install it on the virtual hard disk sda. So, type in sda and press <Enter>.

Type in sys and press <Enter>.

Press y, and then press <Enter> to confirm the installation.

Alpine is being installed on the virtual hard drive. It may take a few minutes to complete.

At this point, Alpine should be installed.

Reboot the virtual machine with the following command:

$ sudo reboot

The next time the virtual machine boots, it will boot Alpine Linux from the virtual hard disk.

Alpine Linux is being booted from the virtual hard disk.

Once Alpine Linux is booted, you should see the login window.

Type in root as the username and the login password you’ve set earlier to login to Alpine Linux.

You should be logged in to Alpine Linux.

Once you’re logged in, you should be able to run any command you want.

The Virtual Machine Manager app should show all the KVM virtual machines you’ve created in the dashboard. You can control your virtual machines from here.

Conclusion

In this article, I have shown you how to enable the Raspberry Pi OS 64-bit kernel and install KVM on the Raspberry Pi OS. I have also shown you how to install Alpine Linux as a KVM virtual machine on the Raspberry Pi OS. On Raspberry Pi OS, hardware acceleration for the KVM virtual machines is still not available. It may be available in a future update of the Raspberry Pi OS. But for now, you can only run lightweight operating systems in KVM virtual machines. If you want to run hardware accelerated KVM virtual machines on your Raspberry Pi 4 right now, use Fedora 33 as the KVM host on your Raspberry Pi 4.

]]>
Set Up Raspberry Pi Home Automation https://linuxhint.com/set-up-raspberry-pi-home-automation/ Tue, 24 Nov 2020 04:29:41 +0000 https://linuxhint.com/?p=77873 One of the most important things for home automation is controlling high-voltage AC using a low-voltage DC. To control the high voltage AC from Raspberry Pi, you will need a 5V relay switch. You can control the relay switch using the GPIO pins of Raspberry Pi. The relay switch can then control the AC home appliances through Raspberry Pi.

This article will show you how to use Raspberry Pi and the 5V relay switch to turn a lightbulb on and off from your mobile device. The article includes a web app that you can access from any device on your network and control any AC home appliances in your home wirelessly. So, let us get started with our simple Raspberry Pi home automation experiment.

Things You Will Need

If you want to use your Raspberry Pi headless (via SSH or VNC), you will need the following things:

1) Raspberry Pi 3 or Raspberry Pi 4.
2) 5V Relay switch.
3) Electrical wires.
4) 3 female-to-female connecting wires.
5) AC lightbulb.
6) AC lightbulb holder.
7) AC plug.
8) Wirecutter and stripper tool.
9) CR-V 3 screwdriver.
10) Micro-USB (Raspberry Pi 3) or USB Type-C (Raspberry Pi 4) power adapter.
11) 16 GB or 32 GB microSD card with Raspberry Pi OS flashed.
12) Network connectivity on Raspberry Pi.
13) Laptop or a desktop computer for VNC remote desktop access or SSH access to Raspberry Pi.

If you do not want to access Raspberry Pi remotely via SSH or VNC, you will also need the following:

14) A monitor.
15) HDMI or micro-HDMI cable.
16) A keyboard.
17) A mouse.

If you need assistance with flashing the Raspberry Pi OS image to the microSD card, check out the article How to Install and Use Raspberry Pi Imager.

If you are a Raspberry Pi beginner and you need assistance with installing Raspberry Pi OS on Raspberry Pi, check out the article How to Install Raspberry Pi OS on Raspberry Pi 4.

Also, if you need assistance with the headless setup of Raspberry Pi, check out the article How to Install and Configure Raspberry Pi OS on Raspberry Pi 4 Without External Monitor.

Images of all the required tools are given below.

Powering on Raspberry Pi

Next, connect the power cable to Raspberry Pi and power on Raspberry Pi.

Once Raspberry Pi is powered on, you can connect to Raspberry Pi via VNC or SSH. Or, you can connect a keyboard, a mouse, and a monitor to Raspberry Pi to directly access it.

5V Relay Pinouts

A relay is basically a switch. But, unlike a traditional switch, a relay can be controlled by a small amount of DC voltage.

The 5V relay is very easy to use. It has two sides: one side is used to control the relay via low-voltage DC (from Raspberry Pi), and the other side is used to control the high voltage AC (i.e., the lightbulb), depending on the state of the relay.


On one side, the relay has two LEDs (one red and one green) and three pins (IN, GND, and VCC). These three pins are used to control the relay from Raspberry Pi.

The first two pins on the other side are used to control the AC home appliance.

Connecting the 5V Relay to Raspberry Pi

To connect the 5V relay to Raspberry Pi, you will need three female-to-female connecting wires.

Plug one side of the connecting wires to the IN (yellow wire), GND (black wire), and VCC (red wire) pins in the 5V relay, as shown below.


The other side of the wires goes into the GPIO header pins of Raspberry Pi, as shown in the image below.

The red wire should go into the PIN 2 (VCC) of Raspberry Pi.
The black wire should go into the PIN 6 (GND) of Raspberry Pi.
The yellow wire should go into the PIN 7 (GPIO 4) of Raspberry Pi.


Once the 5V relay is connected to Raspberry Pi, it should look as shown in the image below.

Allowing GPIO Access to Login User

To allow access to the GPIO pins, the default login user of Raspberry Pi OS pi should be added to the gpio group.

You can add the pi user to the gpio group with the following command:

$ sudo usermod -aG gpio $(whoami)


For the changes to take effect, reboot Raspberry Pi with the following command:

$ sudo reboot

Creating a Project Directory

It is also a good idea to keep all the project files organized.

To keep the project files organized, create the project directory ~/www and the required subdirectories with the following command:

$ mkdir -pv ~/www/{templates,static}


Once the project directory is created, navigate to the project directory as follows:

$ cd ~/www

Switching the 5V Relay from Raspberry Pi

Now that you have connected the 5V relay to Raspberry Pi, you will switch the relay from the Raspberry Pi using the Python programming language.

NOTE: Switching is a term used in electronics. Switching means controlling (i.e. powering on/off) a certain electronic device.

To experiment with switching the relay using the Python programming language, create the new Python script test.py in the project directory as follows:

$ nano test.py


Type the following lines of codes in the test.py Python script.

from gpiozero import LED
from time import sleep

while True:
  relay = LED(4)
  print("Relay: On")
  sleep(5)

  relay.close()
  print("Relay: Off")
  sleep(5)

Once you are done, press <Ctrl> + X followed by Y and to save the test.py Python script.


Here, line 1 imports LED from the gpiozero library, and line 2 imports the sleep function from the time library.


Lines 6-14 are within an infinite loop.


Line 6 initializes an LED in the GPIO 4 of Raspberry Pi, which is connected to the IN pin of the relay.


Line 8 turns on the relay using the on() method.

Line 9 prints a message in the console using the print() function.

Line 10 delays the execution of the next line of code for five seconds using the sleep() function.


Line 12 turns off the relay using the close() method.

In the same way, line 9 prints a message on the console using the print() function and line 10 delays the execution of the next line of code for 5 seconds using the sleep() function.


Next, run the test.py Python script as follows:

$ python3 test.py


The test.py Python script should start switching the 5V relay. You should hear a clicking sound every five seconds. When the relay switches state (from on to off or from off to on), it makes a clicking noise. This means that the relay is functioning properly.


When the relay is in the off-state (normal operation – AC load is disconnected), only the red LED should light up, as you can see in the image below.


When the relay is in the on-state (AC load is connected), both the green LED and the red LED should light up, as you can see in the image below.


Once the testing is complete, press <Ctrl> + C to terminate the test.py script.

Connecting the AC Lightbulb to the 5V Relay

The 5V relay should now be functioning properly. Now, you will connect your AC home appliance (a lightbulb, in this case) to the 5V relay.

First, cut the black electrical wire connected to the lightbulb with a wirecutter.


Once the black electrical wire connected to the lightbulb has been cut with a wirecutter, it should look as shown in the image below.


Next, strip away the exterior layer to expose about ½ inch of the electrical wire, as shown in the image below.


Then, fold the exposed wires, as shown in the image below.


Loosen the marked screws of the relay with a CV-3 screwdriver.


Insert the exposed wires that you stripped and folded earlier in the two screw terminals and tighten the screws with a CV-3 screwdriver.

Testing Relay Switching After Connecting AC Load

Once the AC load is connected to the 5V relay, connect the lightbulb plug to the wall socket.


Run the test.py Python script from the project directory as follows:

$ python3 test.py


The test.py Python script should start switching the 5V relay, which, in turn, will switch the high voltage AC lightbulb at five-second intervals. The AC lightbulb should stay on for five seconds, then stay off for five seconds, and so on.

The lightbulb is off in the image below.


The lightbulb is on in the image below.


As you can see, we can switch the relay and control the high voltage AC lightbulb using the Python programming language. So, press <Ctrl> + C to terminate the test.py script.

Let us now move on to the next section.

Writing the Home Automation Web App

In this section, I will show you how to write an API-based web app using the Python programming language. You can use the web app to control the relay and the AC home appliance(s) or electrical device(s) connected to the relay from a web browser.

NOTE: All the codes shown in this section are available in my GitHub repository shovon8/raspberry-pi-home-automation. If you want, you can clone my GitHub repository and skip all the codes.

Create the server.py Python script in the project directory as follows:

$ nano server.py


Type the following lines of codes in the server.py Python script.

from flask import Flask, jsonify, url_for, render_template
from gpiozero import LED
from uuid import uuid4
rooms = {}
rooms['Room 1'] = [{
  'id': uuid4(),
  'name': 'Light 1',
  'icon': 'fa fa-lightbulb',
  'status': False,
  'relayPin': 4,
  'relayInstance': False
  }, {
  'id': uuid4(),
  'name': 'Fan 1',
  'icon': 'fa fa-fan',
  'status': False,
  'relayPin': 6,
  'relayInstance': False
}]
rooms['Bathroom 1'] = [{
  'id': uuid4(),
  'name': 'Light 1',
  'icon': 'fa fa-lightbulb',
  'status': False,
  'relayPin': 5,
  'relayInstance': False
}]
app = Flask(__name__)
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
@app.route('/')
def home():
  return render_template('./index.html', rooms=rooms)
def toggle_appliance_status(id):
  for room in rooms:
    for appliance in rooms[room]:
      if str(appliance['id']) == id:
        if appliance['relayInstance']:
          appliance['relayInstance'].close()
          appliance['relayInstance'] = False
        else:
          appliance['relayInstance'] = LED(appliance['relayPin'])
          appliance['relayInstance'].on()
        appliance['status'] = not appliance['status']
        return True
  return False
@app.route('/appliance/toggle/<id>')
def appliance_toggle(id):
  return jsonify({'status': toggle_appliance_status(id)})

Once you are done, press <Ctrl> + X followed by Y and to save the server.py Python script.


Here, lines 1-3 import all the necessary components from their respective libraries.


Line 5 creates an empty rooms dictionary. In this dictionary, we will store all the AC appliance details that we want to control from the web app.


The rooms details are stored in lines 7-29.


Let us discuss the data structure of one of the rooms.

Here, the room name will be Room 1. So, Room 1 is the key to the rooms dictionary.


The Room 1 key holds an array as the value. The number of array elements is equal to the number of AC home appliances you have in that room that you also want to control from the web app. In this case, we have two AC home appliances that we want to control: Light 1 and Fan 1.


Each home appliance definition has an id. The id is a randomly-generated UUID. This is used to identify which room we want to control using the API.

A home appliance also has all of the following:

  • name (Light 1 in this case)
  • icon (Font Awesome icon class, as we will be using Font Awesome for the icons)
  • status (True if on and False if off)
  • relayPin (the GPIO pin number used to control the relay connected to the AC home appliance)
  • relayInstance (the initialized LED object of gpiozero library responsible for controlling the respective GPIO pin – relayPin)


Line 31 initializes a flask Python web server.

Line 32 configures the flask web server.


Lines 34-36 send the index.html file from the templates/ directory when you visit the home automation web app.

Flask uses Jinja2 templating language to render the index.html file. So, I have passed the rooms dictionary to the index.html file. Jinja2 will render the homepage using the rooms data.


The function toggle_appliance_status() in lines 39-52 is used to turn on the home appliance if it is off and turn off the home appliance if it is on using the appliance’s id.

It returns True if the toggle operation is successful. If there is an error, it will return False.


Lines 55-57 are used to toggle a home appliance using the /appliance/toggle/ API endpoint of the webserver. Here, id is the ID of the home appliance.


Create the index.html file in the templates/ directory of your project as follows:

$ nano templates/index.html

Type the following lines of codes in the index.html script.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="{{ url_for('static', filename='fontawesome/css/all.min.css') }}">
  <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
  <title>Home Automation with Raspberry Pi</title>
</head>
<body>
<div id="content">
  <h1>Raspberry Pi Home Automation</h1>

  {% for room in rooms %}
  <div class="room">
    <h2>{{ room }}</h2>
    <div class="appliances">
    {% for appliance in rooms[room] %}
      <div class="appliance" id="{{ appliance['id'] }}" data-active="active">
        <i class="{{ appliance['icon'] }}"></i>
        <span>{{ appliance['name'] }}</span>
      </div>
    {% endfor %}
    </div>
  </div>
  {% endfor %}

</div>

<script src="{{ url_for('static', filename='app.js') }}" type="text/javascript"></script>
</body>
</html>

Once you are done, press <Ctrl> + X followed by Y and to save the index.html file.


Create a style.css file in the static/ directory of your project as follows:

$ nano static/style.css


Type the following lines of codes in the style.css file.

@import url('https://fonts.googleapis.com/css2?family=BenchNine:wght@300;400;700&display=swap');

* {
  margin: 0;
  padding: 0;
  font-family: 'BenchNine', sans-serif;
}

#content > h1 {
  background: linear-gradient(to right, rgb(112, 24, 163), rgb(86, 127, 240));
  color: #fff;
  text-align: center;
  padding: .5em 0;
}

div.room {
  margin: .5em;
  border: 2px solid rgb(112, 24, 163);
  border-radius: 5px;
}

div.room h2 {
  /* background: rgb(9, 76, 121); */
  background: linear-gradient(to right, rgb(112, 24, 163), rgb(86, 127, 240));
  padding: 0 0 0 .5em;
  color: #fff;
}

div.appliances {
  margin: .5em .5em 0 0;
  display: flex;
  flex-wrap: wrap;
}

div.appliance {
  border: 2px solid rgb(112, 24, 163);
  border-radius: 5px;
  width: 110px;
  height: 120px;
  text-align: center;
  margin: 0 0 .5em .5em;
  display: flex;
  flex-direction: column;
}

div.appliance i.fa {
  font-size: 4em;
  flex-grow: 1;
  padding-top: 0.3em;
  color: rgb(204, 50, 50);
}

div.appliance[data-active="active"] i.fa {
  color: rgb(32, 177, 51);
}

div.appliance span {
  display: block;
  font-weight: bold;
  background: rgb(112, 24, 163);
  color: #fff;
}

Once you are done, press <Ctrl> + X followed by Y and to save the style.css file.


Create an app.js file in the static/ directory of your project as follows:

$ nano static/app.js


Type the following lines of codes in the app.js file.

window.addEventListener('load', main);

function main() {
  function toggleApplianceState(e) {
    var id = e.path[1].id;

    var http = new XMLHttpRequest();
   
    http.onreadystatechange = function() {
        if(this.readyState === 4 && this.status === 200) {
          if(JSON.parse(this.responseText).status === true) {
            if(e.path[1].hasAttribute('data-active')) {
              e.path[1].removeAttribute('data-active')
            } else {
              e.path[1].setAttribute('data-active', 'active')
            }
          }
        }
    }
   
    http.open("GET", `/appliance/toggle/${id}`, true);
    http.send();
  }


  var appliances = document.getElementsByClassName('appliance');
  for(i=0; i < appliances.length; i++) {
    appliances[i].addEventListener('click', toggleApplianceState);
  }
}

Once you are done, press <Ctrl> + X followed by Y and to save the app.js file.


Here, line 1 runs the main() function when the web page finishes loading.

In the index.html file, each home appliance is enclosed in an appliance class. Lines 26-29 are used to select each home appliance from the web page and attach the click event to the appliance. When someone clicks on a home appliance from the web page, the toggleApplianceState() function will run.


In lines 4-23, the toggleApplianceState() function is used to request the /appliance/toggle/ endpoint of the webserver to change the state of the clicked home appliance. The request is made in the background via AJAX. Once the response is received, the web page is updated accordingly.


Navigate to the static/ directory in your project directory as follows:

$ cd static/


Download Font Awesome with the following command:

$ wget https://use.fontawesome.com/releases/v5.15.1/fontawesome-free-5.15.1-web.zip


Once Font Awesome is downloaded, you should find the new zip file fontawesome-free-5.15.1-web.zip in the static/ directory.

$ ls -lh


Unzip the fontawesome-free-5.15.1-web.zip file with the following command:

$ unzip fontawesome-free-5.15.1-web.zip


The fontawesome-free-5.15.1-web.zip file should now be unzipped.


The new directory fontawesome-free-5.15.1-web/ should be created in the static/ directory, as you can see in the screenshot below.

$ ls -lh

Rename the directory fontawesome-free-5.15.1-web/ to fontawesome/ with the following command:

$ mv -v fontawesome-free-5.15.1-web fontawesome


Now, you no longer need the fontawesome-free-5.15.1-web.zip file. So, remove the fontawesome-free-5.15.1-web.zip file with the following command:

$ rm -v fontawesome-free-5.15.1-web.zip


The static/ directory structure should look as shown in the screenshot below.

$ ls -lh


Navigate back to the project directory ~/www as follows:

$ cd ..

Testing the Home Automation Web App

To test the home automation web app, run the following command in your project directory:

$ FLASK_APP=server.py flask run


The web app should be available on port 5000 of your Raspberry Pi.


From the Chromium web browser, visit http://localhost:5000. The home automation web app should load.

Click on the lightbulb icon, indicated in the image below.


The AC lightbulb should now be turned on. The icon color should also change to green, indicating that the lightbulb is on.


So, the home automation web app is working. Press <Ctrl> + C to terminate the webserver.

Creating Systemd Service for the Home Automation Web App

In this section, I will show you how to create a systemd service file for the home automation web app so that it will automatically start on boot.

First, create the raspi-home-automation.service file in your project directory as follows:

$ nano raspi-home-automation.service

Type the following lines in the raspi-home-automation.service file.

[Unit]
Description=Raspberry Pi Home Automation Web Service
After=network.target
[Service]
WorkingDirectory=/home/pi/www
Environment=FLASK_APP=server.py
Environment=FLASK_ENV=production
ExecStart=/usr/bin/flask run --host=0.0.0.0
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi
[Install]
WantedBy=multi-user.target

Once you are done, press <Ctrl> + X followed by Y and to save the raspi-home-automation.service file.


Copy the raspi-home-automation.service file to the /etc/systemd/system/ directory with the following command:

$ sudo cp -v raspi-home-automation.service /etc/systemd/system/


Reload the systemd daemons for the changes to take effect as follows:

$ sudo systemctl daemon-reload


Add the raspi-home-automation service to the system startup of Raspberry Pi OS with the following command:

$ sudo systemctl enable raspi-home-automation.service


Reboot Raspberry Pi with the following command:

$ sudo reboot


Once Raspberry Pi boots, the raspi-home-automation service should be active/running, as you can see in the screenshot below.

$ sudo systemctl status raspi-home-automation.service

Accessing the Home Automation Web App from Other Devices

To access the home automation web app from other devices in your home network, you will need to know the IP address of your Raspberry Pi device.

You can find the IP address of your Raspberry Pi 4 device from the web management interface of your home router. In my case, the IP address is 192.168.0.103. This will be different for you. So, be sure to replace my IP with yours from now on.


If you have access to the Raspberry Pi console, you can run the following command to find the IP address, as well.

$ hostname -I


Once you know the IP address of your Raspberry Pi device, you can access it from any device in your home network.

As you can see in the screenshot below, I have accessed the home automation web app from my Android smartphone.


Be sure to plug the lightbulb plug into the wall power outlet.


The lightbulb should be switched off by default.


If you tap the lightbulb icon from the home automation web app, the lightbulb icon color should change to green, indicating that the lightbulb is on.


As you can see in the image below, the lightbulb is on.

Conclusion

This article showed you how to use a 5V relay to control a high-voltage AC electrical device from Raspberry Pi using the Python programming language. The article also showed you how to write an API based Python flask web app to control the relay from the web browser. This article should help you get started with home automation using Raspberry Pi.

]]>
How to Enable KVM Virtualization on Raspberry Pi 4 https://linuxhint.com/kvm_virtualization_raspberry_pi4/ Fri, 20 Nov 2020 20:31:21 +0000 https://linuxhint.com/?p=77470

The full form of KVM is Kernel Virtual Machine. It is the virtualization solution for Linux. KVM is a Linux kernel module that allows the Linux kernel to act as a hypervisor program like VMware ESXi or VSphere.

Up until now, you could not run KVM virtualization on Raspberry Pi devices. One of the main reasons for this was that the Raspberry Pi 3 and older versions have only 1 GB of memory. 1 GB of memory is insufficient for KVM virtualization. Docker is a better solution for these devices.

The recently released Raspberry Pi 4 8 GB model made KVM virtualization possible on the Raspberry Pi. Linux distributions like Fedora, Manjaro, etc., made KVM virtualization easy for the Raspberry Pi 4 by precompiling the KVM Linux kernel module. Our all favorite Raspberry Pi OS may follow this path someday as well.

In this article, I am going to show you how to install KVM on Raspberry Pi 4 and create a KVM virtual machine on the Raspberry Pi 4. So, let’s get started.

Things You Will Need:

To follow this article, you will need the following things:

  1. A Raspberry Pi 4 (4 GB or 8 GB version) single-board computer.
  2. A USB Type-C power adapter.
  3. A 32 GB or higher capacity microSD card with Fedora Workstation 33 ARM image flashed onto it.
  4. A keyboard.
  5. A mouse.
  6. A monitor.
  7. Internet connectivity on the Raspberry Pi 4.

If you need any assistance on installing Fedora Workstation 33 on your Raspberry Pi 4, check my article How to Install Fedora 33 on Raspberry Pi 4.

Installing KVM, libvirt, and Virtual Machine Manager:

Before you can create KVM virtual machines, you need to have KVM and all the required tools installed on your Fedora Workstation 33. Luckily, KVM and all the required tools are available in the official package repository of Fedora Workstation 33.

First, update the DNF package repository cache with the following command:

$ sudo dnf makecache


You can install KVM and all the required tools with the following command:

$ sudo dnf group install "Virtualization"


To confirm the installation, press and then press <Enter>.


The DNF package manager will automatically download and install all the required packages. It may take a while to complete.


At this point, KVM and all the required tools should be installed.


Add your login user to the libvirt group with the following command:

$ sudo usermod -aG libvirt $(whoami)


For the changes to take effect, reboot your Raspberry Pi 4 with the following command:

$ sudo reboot

Downloading Ubuntu Server ARM Installation Image:

Canonical has an official Ubuntu Server ARM release, which works great as a KVM guest (virtual machine) on the Raspberry Pi 4.

In this article, I will show how to install Ubuntu Server 20.04 LTS as a KVM virtual machine on the Raspberry Pi 4 as a demonstration. In a later section of this article, I will show you what other alternatives are available at the time of this article.

First, visit the official website of Ubuntu. Once the page loads, click on Download and then ARM from the Ubuntu Server section as marked in the screenshot below.


Click on the Download Ubuntu 20.04.1 LTS download button as marked in the screenshot below.


Select Save File and click on OK.


Your browser should start downloading the Ubuntu Server 20.04.1 LTS ARM ISO image. It may take a while to complete.

Moving Ubuntu Server ISO Image to the KVM Image Directory:

Once the Ubuntu Server 20.04.1 ARM ISO image is downloaded, you should be able to find it in the ~/Downloads directory, as you can see in the screenshot below.

$ ls -lh ~/Downloads


The default KVM image directory is /var/lib/libvirt/image/. You should copy your Ubuntu Server 20.04.1 ARM ISO image to the /var/lib/libvirt/image/ directory.

To move the Ubuntu Server 20.04.1 ARM ISO image to the /var/lib/libvirt/image/ directory, run the following command:

$ sudo mv -v ~/Downloads/ubuntu-20.04.1-live-server-arm64.iso /var/lib/libvirt/images/

Creating a Ubuntu Server 20.04.1 LTS KVM Virtual Machine:

In this section, I will show you how to create a KVM virtual machine and install Ubuntu Server 20.04.1 LTS on it using the KVM graphical management app Virtual Machine Manager (VMM).

First, search for Virtual Machine Manager in the Application Menu of your Fedora Workstation 33 desktop environment. Then, click on the Virtual Machine Manager icon as marked in the screenshot below.


Virtual Machine Manager should be opened.


To create a KVM virtual machine, click on the icon() as marked in the screenshot below.


Select Local install media (ISO image or CDROM) and click on Forward.


Click on Browse


Select the Ubuntu Server 20.04.1 ARM ISO installation image from the list and click on Choose Volume.


Click on Forward.


Type in the amount of memory (in megabytes/mebibytes) and the number of CPU cores you want for this virtual machine.

I will use 2 GB or 2048 MB of memory and 1 CPU core for this virtual machine.

Once you’re done, click on Forward.


Type in the amount of disk space you want to allocate for this virtual machine (in gigabytes/gibibytes). I will allocate 10 GB of disk space for this virtual machine.

Once you’re done, click on Forward.


Click on Finish.


The virtual machine is being created. It may take a few seconds to complete.


Once the virtual machine is created, it should start and boot from the Ubuntu Server 20.04.1 ARM ISO image.


Once you see the following GRUB menu, select Install Ubuntu Server and press <Enter>.


The Ubuntu Server installer is being loaded from the Ubuntu Server 20.04.1 LTS ISO image. It may take a few seconds to complete.

Once the Ubuntu Server installer is ready, you should see the following window.

Select Switch to the rich mode and press <Enter>.


The Ubuntu installer should switch to rich mode.

NOTE: This article is about enabling KVM virtualization on the Raspberry Pi 4. So, I won’t focus on explaining the ins and outs of the Ubuntu Server 20.04.1 LTS installer. To learn what each of the Ubuntu installer options does and how to configure it as you want, read my article Installing Ubuntu Server 20.04 LTS.


Select your language and press <Enter>.


Select your keyboard layout.

Once you’re done, select Done and press <Enter>.


Select Continue without network and press <Enter>.


Select Done and press <Enter>.


Select Done and press <Enter>.


Select Done and press <Enter>.


Select Done and press <Enter>.


Select Continue and press <Enter>.


Type in your full name, hostname (server name), login username, and password.

Once you’re done, select Done and press <Enter>.


To install the OpenSSH SSH server, you must check Install OpenSSH server as marked in the screenshot below.

To do that, select Install OpenSSH server and press <Space Bar>.


Install OpenSSH server should be checked.

Then, select Done and press <Enter>.


Select Done and press <Enter>.


Ubuntu installer should start installing Ubuntu Server 20.04 LTS on the virtual machine. It will take a while to complete.


Once the installation is complete, it will automatically install all the necessary updates. It will take a while to complete.

If you want, you can select Cancel update and reboot and press <Enter> to cancel the updates. You can install the updates later using the APT package manager. I will just let it continue.


Once the updates are installed, select Reboot and press <Enter> to reboot your virtual machine.


Once the virtual machine boots, you should see the Ubuntu Server 20.04.1 LTS login window.

You can log into the Ubuntu Server virtual machine using the login username and password you’ve set during the installation.


As you can see, I am logged into the Ubuntu Server virtual machine.


I am running Ubuntu Server 20.04.1 LTS on a KVM virtual machine. On my Raspberry Pi 4! Amazing!


You can manage your KVM virtual machines from the Virtual Machine Manager. As you can see, the Ubuntu Server 20.04 LTS KVM virtual machine I have created earlier is listed in the Virtual Machine Manager dashboard.

Other ARM Linux ISO Installation Images for KVM:

At the time of this writing, besides Ubuntu Server 20.04 LTS, you can also install Fedora Server 33 and CentOS 8 on the Raspberry Pi 4 as a KVM virtual machine.

To download the ISO installation image of Fedora Server 33, visit the official website of Fedora from a web browser.

Click on the Download Now button of Fedora Server as marked in the screenshot below.


Click on the Download button of either the aarch64 Fedora 33 standard ISO image or the netinstall ISO image as marked in the screenshot below.

Once the ISO image is downloaded, you can create a Fedora Server 33 KVM virtual machine using the Virtual Machine Manager app.


To download the ISO installation image of CentOS 8, visit the official website of CentOS from a web browser.

Click on the Download link as marked in the screenshot below.


Click on either the CentOS 8 ARM64 (aarch64) or the CentOS Stream ARM64 (aarch64) link as marked in the screenshot below.


Click on one of the mirror links.


From the FTP mirror of CentOS, you can download either the CentOS aarch64 netboot ISO image, the minimal ISO image, or the DVD1 ISO image.

Once the ISO image is downloaded, you can create a CentOS 8 or CentOS Stream KVM virtual machine using the Virtual Machine Manager app.

Conclusion:

In this article, I have shown you how to enable KVM virtualization on Raspberry Pi 4 and create a Ubuntu Server 20.04 LTS KVM virtual machine on the Raspberry Pi 4. I have used the Fedora Workstation 33 as the operating system for the Raspberry Pi 4 in this article. This article should help you get started with KVM virtualization on the Raspberry Pi 4.

]]>
How to Install Fedora 33 on Raspberry Pi 4 https://linuxhint.com/install_fedora_33_raspberry_pi4/ Fri, 20 Nov 2020 20:30:02 +0000 https://linuxhint.com/?p=77532

At the time of this writing, Fedora has official support for ARM devices like the Raspberry Pi 4. So, you can easily install Fedora 33 – the latest release of Fedora Linux distribution on your Raspberry Pi 4.

In this article, I am going to show you how to install Fedora Workstation 33 on the Raspberry Pi 4. So, let’s get started.

Things You Will Need:

To follow this article, you will need the following things:

  1. A Raspberry Pi 4 single-board computer.
  2. A USB Type-C power adapter.
  3. A 32 GB or higher capacity microSD card.
  4. A keyboard.
  5. A mouse.
  6. A monitor.
  7. A laptop or a desktop computer for downloading and flashing the Fedora 33 image on the microSD card.

Downloading Fedora 33 ARM Image:

To download the Fedora 33 ARM image, visit the official website of Fedora from your favourite web browser.

Once the page loads, click on Download Now from the Fedora Workstation section as marked in the screenshot below.


Click on the Download button from the Fedora 33 ARM section as marked in the screenshot below.


Your browser should prompt you to save the Fedora Workstation 33 ARM image file. Select a directory where you want to save the image file and click on Save.

Fedora Workstation 33 ARM image is being downloaded. It will take a while to complete.

Flashing Fedora 33 ARM Image on the MicroSD Card:

To flash the Fedora Workstation 33 ARM image on the microSD card, you can use many programs like Balena Etcher, Raspberry Pi Imager, Fedora Media Writer, and so on. In this article, I am going to use the Raspberry Pi Imager for the demonstration. Feel free to use any tool you like for this purpose.

If you need any assistance on installing the Raspberry Pi Imager, check my article How to Install and Use Raspberry Pi Imager.

First, insert the microSD card into your computer.


Start the Raspberry Pi Imager app and click on CHOOSE OS.


Scroll down a little bit and click on Use custom.


A file picker should be opened. Select the Fedora Workstation 33 ARM image that you just downloaded and click on Open.


Once the operating system image is selected, click on CHOOSE SD CARD.


Click on your microSD card from the list.


Once the MicroSD card is selected, click on WRITE.


All the existing data on your microSD card will be erased. To confirm the action, click on YES.


The Fedora Workstation 33 ARM image is being written to the microSD card. It may take a while to complete.


Once the Fedora Workstation 33 ARM image is flashed on to the microSD card,  you should see the following Write Successful window. Click on CONTINUE, close Raspberry Pi Imager, and remove the microSD card from your computer.

Booting Fedora 33 on Raspberry Pi 4:

  1. Insert the microSD card on your Raspberry Pi 4.
  2. Then, insert the micro HDMI cable of your monitor to the micro HDMI port of the Raspberry Pi 4.
  3. Also, Insert the keyboard and mouse to the USB 2.0 port of your Raspberry Pi 4.
  4. Optionally, you can plug in the network cable to the RJ45 Ethernet port of your Raspberry Pi 4.
  5. Finally, insert the USB Type-C power cable on the Raspberry Pi 4 and power it on.


Fedora Workstation 33 is being booted.


You have to configure Fedora Workstation 33 when it boots for the first time.


To start the configuration wizard, click on Start Setup, as shown in the image below.


You can configure the Wi-Fi network from here. I will use a wired Ethernet network. So, I will click on Skip.

NOTE: I could not connect to the Wi-Fi network. Maybe there are some bugs in the graphical user interface of Fedora Workstation 33. In a later update, the bugs may be fixed. As of now, you should be able to connect to your Wi-Fi network using the Network Manager’s command-line tools. But, I recommend using an Ethernet cable for network connectivity if you don’t strictly need Wi-Fi.


Click on Next.


Type in your Full Name and login Username. Once you’re done, click on Next.


Type in a login password and click on Next.


Click on Start Using Fedora.


Fedora Workstation 33 should be ready to use.


As you can see, I am using Fedora 33, and it’s using the Linux kernel 5.8.15.

$ cat /etc/redhat-release

$ uname -r


Fedora Workstation 33 uses about 1.2 GB of memory when no extra programs are running.

Removing Black Edges from the Monitor Display:

Fedora Workstation 33 may show black borders around your screen. It is because of overscan. In some monitors, overscan leaves exclusion zones around your monitor.

By default, overscan is enabled on Fedora Workstation 33. To fix this problem, all you have to do is disable overscan.


You should find a config.txt file in the /boot/efi/ directory, as you can see in the screenshot below.


To disable overscan, open the /boot/efi/config.txt file with the nano text editor as follows:

$ sudo nano /boot/efi/config.txt


The /boot/efi/config.txt file should be opened.


Scroll down to the end of the config.txt file and type in disable_overscan=1, as shown in the screenshot below.

Once you’re done, press <Ctrl> + followed by and <Enter> to save the config.txt file.


For the changes to take effect, reboot your Raspberry Pi 4 with the following command:

$ sudo reboot


Once your Raspberry Pi 4 boots, the black borders should be gone.

Expanding the BTRFS Filesystem:

The default filesystem of Fedora Workstation 33 is BTRFS.

By default, only a portion of the microSD card is used for storing the operating system files and user data. The rest of the disk space is kept unallocated.

As you can see in the screenshot below, only 9.5 GB of disk space (out of 32 GB) from my microSD card is used for the root (/) filesystem.

$ df -h


To expand the file system, you have to expand the partition first.

To do that, open the microSD card with the fdisk command-line partitioning tool as follows:

$ sudo fdisk /dev/mmcblk1


fdisk should open the microSD card.

To list all the existing partitions of the microSD card, press and then press <Enter>.


As you can see, the 9.4 GB partition is the 3rd partition of the microSD card. You have to remove the 3rd partition and re-create it. Don’t worry. You won’t lose any data.

To delete a partition, press and press <Enter>.


Type in 3 as the partition number and press <Enter>.


The 3rd partition should be removed.

To re-create the 3rd partition, press n and then press <Enter>.


Press and then press <Enter>.


Type in as the partition number and press <Enter>.


Press <Enter> to select the default first sector number.


Press <Enter> to select the default last sector number.

The default last sector number should be the last allocable sector number (from the unallocated space of the microSD card) of the microSD card.


Press n and then press <Enter> to keep the existing partition signature.

NOTE: Be extra careful in this step. If you remove the existing partition signature, you won’t be able to recover your existing files very easily.


The 3rd partition should be recreated.

To save the changes, press and then press <Enter>.


The updated partition table should be written to the microSD card, and the fdisk should be closed.


To resize the BTRFS root (/) filesystem to the max available space of the partition, run the following command:

$ sudo btrfs filesystem resize max /


The BTRFS root (/) filesystem should be resized.


As you can see, the root (/) filesystem is resized to 28 GB (from 9.4 GB).

Conclusion:

In this article, I have shown you how to install Fedora Workstation 33 on Raspberry Pi 4. I have also shown you how to remove the black edges from the monitor and expand the BTRFS root filesystem. This article should help you get started with Fedora Workstation 33 on the Raspberry Pi 4.

]]>
Best Raspberry Pi Cluster Case https://linuxhint.com/best-raspberry-pi-cluster-case/ Wed, 18 Nov 2020 18:36:32 +0000 https://linuxhint.com/?p=77178 The Raspberry Pi prides itself on being extraordinarily customizable and low-budget. And rightly so, you can tweak this little computer for a hundred different projects without spending much. No holds barred! You only need a little imagination (and, of course, some coding skills).

However, just because it’s inexpensive doesn’t mean you shouldn’t take its care. You need an enclosure of some sort for this purpose. So, whether you want to pack some extra capacity, better heat absorption, or protection against atmospheric anomalies, the best Raspberry Pi cluster case will hold your back.

These are our picks for the 5 best cluster cases for Raspberry Pi.

1. iUniker Raspberry Pi Cluster Case

The best of the best iUniker Cluster case is here to turn your mess of a desk into a clean configuration. And with style! The only aspect that you need to take care of is the installation. As long as you follow the instructions manual, you should be fine. If not, well, don’t blame us!

It’s a complete stackable grained acrylic case giving you up to four layers of Raspberry Pi(s). In addition, it’s compatible with the current Pi as well as Pi 3 B+, Pi 3 B, Pi 2 B, and Pi B+. The setup is also very straightforward and clean. Besides, the kit comes with enough hardware to get the job done without any hassle.

Each layer contains a pre-built air vent that allows maximum air circulation and keeps the temperature within limits. The fans are silent. Although there’s an option to run the fans either in full speed or quiet mode, we didn’t hear any unusual sounds.

Visually, the iUniker Raspberry Pi Cluster Case is one of the nicest looking cases available in the market. Ports are easily accessible, which makes for a very clean and aesthetically pleasing look. The price is also very economical. Overall, we couldn’t find any faults with this product.

Buy‌ ‌Here:‌ ‌‌Amazon‌

2. Micro Connectors 4 Layer Stackable Case

On the second spot is the Micro Connector’s 4-layer acrylic case. It’s a sturdy, compact, flexible, and functional piece of hardware that looks great too. Mount it right on the wall or keep it nicely tucked away in a corner; this cluster case allows both configurations. How many cluster cases this choice offer?

An open-frame design gives easy access to all the PI modules like the display DSI, microSD, Camera CSI, etc., without opening the case. Plus, it’s stackable, so you can organize different PI clusters in a much better and easily manageable way.

The package includes a 40mm fan and heatsinks to cool down the temperature. Just make sure you’re installing the fans the right way. Besides, the housing also works as a passive cooler. Therefore you don’t have to worry about overheating when using the clusters for extended periods.

The only annoying part is struggling with the power cables when you put the lid on the cover. But, considering how attractive and functional this compact case is, that’s a minor gripe. It works great with Raspberry Pi 1 Model B+, Pi 2 Model B, Pi 3 model B/B+ Pi 4, and Pi Zero/zero w.

Buy‌ ‌Here:‌ ‌‌Amazon‌

3. GeauxRobot Dog Bone Stack Clear Case Box

This is yet another economic 4-layer Cluster Case. There’s one difference, though. It has a dogbone configuration, which has much greater tensile strength. Plus, it is very versatile. You can keep on stacking new kits if need be in the future or just shrink it down if you don’t desire the extra layers.

It has precise and pre-drilled options that fit all the regular Raspberry Pi boards. Fans and heatsinks are not included in the package, but the enclosure can add it in the future. All the parts are neatly organized into separate bags for each layer. This is great because you don’t have to open up everything if you want to add just two layers.

Thick acrylic plates hold the boards well. The top and bottom plates are thicker than the three interior plates. Set up is easy, and once done, boards are easily accessible from all sides.

Our only disappointment is the instruction manual, which feels inadequate. Novices may struggle with putting everything together. There are no extra pieces, so if you misplace a tiny part, good luck with the installation! Overall, it’s a quality case with a classy look that comes at a very economical cost. This is highly recommended for home or professional networks.

Buy‌ ‌Here:‌ ‌‌Amazon‌

4. Yahboom Raspberry Pi Cluster Case

If you want a precisely machined and nicely cut cluster case for your Pi family, look no further. Yahboom clearly spent a fair amount of time on getting everything right. Screws fit (all Raspberry Pi models except zero), standoffs are of good quality, transparent acrylic construction is eye-pleasing, and there’s enough room for cooling.

PS. The package includes extra plastic standoffs.

Unfortunately, there’s no instruction manual. But you don’t need it anyway because the assembly is super easy. And the best thing is the tool-less installation. The plastic protection is a bit of a chore to remove. Once that is done, you’re all set to add up to six layers. There are SD card slots on every layer and a heatsink cutout at the bottom of the enclosure to cool down the equipment.

Once assembled, it’s not just an elegant design but also very transparent. You can clearly see the insides and monitor any changes in the RPI.

All in all, this is a solid multi-Pi case for playing around with. It’s multifunctional, convenient to set up, and comes at a very reasonable cost.

Buy‌ ‌Here:‌ ‌‌Amazon‌

5. Jun Electron’s Clear Stackable Case

If your budget is low and wants a cheap cluster case, this Chinese product is worth looking into. It’s a decent quality 4-layer rack that comes with enough “nuts and bolts” for clustering your Pis. Small nuts and spacers, however, require patience with assembly, as you should expect.

The best thing about this enclosure is that it comes with two big and one small heatsink for every layer. In total, there are eight big and four small heatsinks in the entire package. As it’s a semi-enclosed case, access to all the modules, ports, and cables is super easy.

Our only complaint is that the threading on some of the spacers isn’t properly aligned. Because of this, once you’ve put everything together, the case might wobble a little. Make sure you are assembling it on a flat surface, and all the corner posts are in line with each other.

That said, Jun Electron’s stackable case is compatible with the new Raspberry Pi 4 Model b, Pi 3 Model B+, Pi 3b, Pi 2B, etc. Keep in mind, though, you get what you pay for.

Buy‌ ‌Here:‌ ‌‌Amazon‌

Buyer’s Guide to the Best Raspberry Pi Cluster Case

Cluster cases for Raspberry Pi are a relatively new invention. Still, there are so many choices available in the market that separating the wheat from the chaff becomes a daunting task. In that case, consider these features to make the most out of your purchase:

Types

In terms of design, there are two main types of Raspberry Pi Cluster Cases. You can go for either an open-air design like the products mentioned in this article or a box enclosure. We prefer open-air design because it provides better air circulation and more room to add the peripherals.

Durability

Most cluster cases are made of transparent acrylic sheets. It’s a durable, low-cost, and long-lasting material. But some acrylic sheets get scratches easily. So make sure the enclosure you’re going for provides some scratch resistance, at least.

Heat Dissipation

When you’re stacking multiple Pi layers on top of each other, the most crucial factor to consider is overheating. High-end enclosures come with pre-built fans and heatsinks to get the job done. They are also designed to maximize airflow to give passive cooling to the equipment. If your Cluster case doesn’t include a fan, make sure there is enough room to place one nearby.

Versatility

How many layers your cluster case can hold? Of course, it depends on your use too. For typical office or homework, 2 or even 4 layers are more than enough. If you will need to expand the functionality of your Raspberry Pi configuration in the future, select a cluster case that provides enough versatility. So you can add more layers in the future.

Aesthetics

Lastly, consider the aesthetics. This is certainly not important for office work where the server is usually sitting in a dark room. Home users, though, should consider aesthetics merely for the eye candy.

Final Thoughts

A Pi cluster can start at two and grow into as many as a hundred. Nevertheless, for typical home and work use, a 4-layer best Raspberry Pi case is more than enough. We hope the products listed above give you enough options to choose the right one. All of them are quality products and will serve you well. If not, consider the points mentioned in the buyer’s guide portion to make the right purchase. Good luck, and have fun!

]]>
Build a Raspberry Pi Security Camera Network https://linuxhint.com/build-a-raspberry-pi-security-camera-network/ Sun, 15 Nov 2020 13:45:18 +0000 https://linuxhint.com/?p=76882

The Raspberry Pi official camera module can be used as a security camera. You can share the camera video stream on the network and access it remotely from any device on your Local Area Network (LAN).

You can use the VLC media player to share the video stream on a TCP port and access it from any device on your Local Area Network (LAN) using VLC media player.

In this article, I will show you how to build a Raspberry Pi security camera and stream the camera video feed from the Raspberry Pi using the VLC media player.

So, let’s get started!

Things You Will Need

To follow this article, you will need the following things:

  1. Raspberry Pi 3 or Raspberry Pi 4
  2. Raspberry Pi camera module
  3. Micro-USB (Raspberry Pi 3) or USB Type-C (Raspberry Pi 4) power adapter
  4. 16 GB or 32 GB MicroSD card with Raspberry Pi OS flashed
  5. Network connectivity on the Raspberry Pi
  6. Laptop or a desktop computer for VNC remote desktop or SSH access to the Raspberry Pi.

NOTE: If you don’t want to access your Raspberry Pi remotely via SSH or VNC, you need to connect a monitor, a keyboard, and a mouse to your Raspberry Pi as well. I won’t need any of these as I will be connecting my Raspberry Pi remotely via VNC or SSH. My setup is called the headless setup of Raspberry Pi.

If you need any assistance on flashing the Raspberry Pi OS image on the microSD card, check my article: How to Install and Use Raspberry Pi Imager.

If you’re a Raspberry Pi beginner and you need any assistance on installing Raspberry Pi OS on your Raspberry Pi, check my article: How to Install Raspberry Pi OS on Raspberry Pi 4.

If you need any assistance on the headless setup of Raspberry Pi, check my article: How to Install and Configure Raspberry Pi OS on Raspberry Pi 4 Without External Monitor.

If you need any assistance on connecting the Raspberry Pi camera module on the Raspberry Pi, check my article: Using Raspberry Pi Camera Module.

Enabling the Raspberry Pi Camera Module

The camera interface is disabled by default on the Raspberry Pi OS. You can enable it from the Raspberry Pi configuration tool, raspi-config.

Start the Raspberry Pi configuration tool with the following command:

$ sudo raspi-config

Select Interface Options and press <Enter>.

Select Camera and press <Enter>.

Select <Yes> and press <Enter>.

Press <Enter>.

Select <Finish> and press <Enter>.

Select <Yes> and press <Enter>. Your Raspberry Pi should reboot, and the changes should be applied.

Installing VLC Media Player

VLC Media Player is available in the official package repository of Raspberry Pi OS. So, it’s easy to install it on the Raspberry Pi OS.

First, update the APT package repository cache with the following command:

$ sudo apt update

To install VLC Media Player, run the following command:

$ sudo apt install vlc -y

VLC Media Player should be installed. In my case, it is already installed.

Creating a Camera Server with VLC Media Player

The raspivid command is used to record video from the Raspberry Pi camera module. I have explained how to use the raspivid command to record a video using Raspberry Pi in my article Using Raspberry Pi Camera Module.

The VLC Media Player has a command-line player cvlc. You can use the cvlc command to share a video stream on a TCP port. In this case, the video stream of the Raspberry Pi camera module.

To share the Raspberry Pi camera video feed on a TCP port using the VLC Media Player, run the following command:

$ raspivid -o - -t 0 -hf -w 1920 -h 1080 -fps 30 | cvlc -vvv stream:///dev/stdin
--sout '#standard{access=http,mux=ts,dst=:9000}' :demux=h264

The raspivid command is used to record the video from the Raspberry Pi camera module.

Here is the following meaning of the command below:

  • The video width will be 1920 pixels
  • The video height will be 1080 pixels (-h 1080).
  • The video will be flipped horizontally (-hf).
  • The video will be recorded at 30 frames per second (-fps 30).
  • The video will be recorded for an unlimited number of seconds (-t 0).
  • The video stream will be printed on the terminal instead of saving it on file (-o –).

You can change any of these options as you see fit.

The cvlc command is used to open a TCP port and send the Raspberry Pi camera video feed on the TCP port.

The video feed is taken from the standard input (stream:///dev/stdin) of the terminal (using a pipe |).

VLC will use the TS codec for multiplexing (–sout ‘#standard{…,mux=ts,…}’) the input video feed, and H264 codec for demultiplexing (:demux=h264) the output video feed.

The video stream will be available on the HTTP port 9000 (–sout ‘#standard{access=http,…,dst=:9000}’).

Once you run the command and the buffering is complete, you can stream the video from any device on the network using the VLC Media Player.

Streaming the Camera Feed from the Raspberry Pi Camera Server

To access the camera feed from other devices in your home network (LAN), you need to know the IP address of your Raspberry Pi.

You can find the IP address of your Raspberry Pi from the web management interface of your home router. In my case, the IP address is 192.168.0.103. It will be different for you. So, make sure to replace it with yours from now on.

If you have access to the Raspberry Pi console, you can run the following command to find the IP address as well.

$ hostname -I

Once you know the IP address of your Raspberry Pi, open the VLC Media Player app and go to Media > Open Network Stream… as shown in the screenshot below.

Type in the URL of the camera server in the Please enter a network URL section. In my case, the URL is http://192.168.0.103:9000.

Once you have typed in the URL, click on Play.

The VLC Media Player should start streaming the video feed from the Raspberry Pi, as you can see in the screenshot below.

Now, stop the camera server by pressing <Ctrl> + C.

Starting the Camera Server on System Boot

Manually starting the camera server each time, you boot your Raspberry Pi is not very practical. So, we can create a systemd service for the camera server that will automatically start the camera server on boot.

First, create a camera-stream-HTTP. Service file in the /etc/systemd/system/ directory as follows:

$ sudo nano /etc/systemd/system/camera-stream-http.service

Type in the following lines in the camera-stream-http.service file.

[Unit]
Description=Raspberry Pi Camera Streaming Server
After=network.target
[Service]
WorkingDirectory=/home/pi
Environment=APP_RES_WIDTH=800
Environment=APP_RES_HEIGHT=450
Environment=APP_RES_FPS=24
Environment=APP_PORT=9000
ExecStart=/bin/bash -c 'raspivid -o - -t 0 -hf -w $APP_RES_WIDTH -h
$APP_RES_HEIGHT -fps $APP_RES_FPS | cvlc -vvv stream:///dev/stdin
--sout "#standard{access=http,mux=ts,dst=:$APP_PORT}" :demux=h264'
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi
[Install]
WantedBy=multi-user.target

You can adjust the following environment variables to configure the camera server as you see fit.

Environment=APP_RES_WIDTH=800
Environment=APP_RES_HEIGHT=450
Environment=APP_RES_FPS=24
Environment=APP_PORT=9000

Once you’re done, press <Ctrl> + X followed by Y, and <Enter> to save the camera-stream-http.service file.

Reload the systemd daemons for the changes to take effect as follows:

$ sudo systemctl daemon-reload

As you can see, the camera-stream-http systemd service is not running at the moment.

$ sudo systemctl status camera-stream-http.service

You can start the camera-stream-http system service with the following command:

$ sudo systemctl start camera-stream-http.service

The camera-stream-http service should be active/running, as you can see in the screenshot below. So, camera-stream-http systemd service is working.

$ sudo systemctl status camera-stream-http.service

You can add the camera-stream-http systemd service to the system startup of Raspberry Pi OS with the following command:

$ sudo systemctl enable camera-stream-http.service

For the changes to take effect, reboot your Raspberry Pi with the following command:

$ sudo reboot

Once your Raspberry Pi boots, the camera-stream-http systemd service should be active/running, as you can see in the screenshot below.

$ sudo systemctl status raspi-home-automation.service

Conclusion

In this article, I have shown you how to build a Raspberry Pi security camera and access the video feed from your home network (LAN) using the VLC Media Player. If you just want a simple Raspberry Pi security camera setup, this article should help you get started.

]]>
Install Ubuntu Server 20.04 LTS on Raspberry Pi 4 in Headless Mode and SSH Into It https://linuxhint.com/install_ubuntu_ssh_headless_raspberry_pi_4/ Mon, 09 Nov 2020 09:24:46 +0000 https://linuxhint.com/?p=75234 Ubuntu is an open-source operating system. It is based on Debian GNU/Linux operating system. Ubuntu is a great operating system for your IoT projects on the Raspberry Pi 4.

In the headless setup of Ubuntu on Raspberry Pi 4, you don’t need a keyboard, a mouse, and a monitor. You can directly access the Ubuntu operating system installed on your Raspberry Pi 4 remotely via SSH.

In this article, I am going to show you how to install Ubuntu Server 20.04 LTS on your Raspberry Pi 4 in headless mode and configure SSH access. So, let’s get started.

Things You Will Need:

To follow this article, you need the following things:

  1. A Raspberry Pi 4 single-board computer
  2. A USB Type-C power adapter for your Raspberry Pi 4
  3. A 16 GB or 32 GB microSD card
  4. A laptop or a computer for flashing the Ubuntu Server image on the microSD card and accessing your Raspberry Pi 4 via SSH
  5. Raspberry Pi Imager or Balena Etcher installed on your laptop or computer for flashing the Ubuntu Server image on the microSD card.

If you need any assistance on installing Raspberry Pi Imager on your Linux operating system, check my article How to Install and Use Raspberry Pi Imager.

If you need any assistance on installing Balena Etcher on your Linux operating system, check my article Install Etcher on Linux.

In this article, I will use Raspberry Pi Imager for flashing the Ubuntu Server operating system image on the microSD card. You can use Balena Etcher if you want.

Downloading Ubuntu Server 20.04 LTS Image for Raspberry Pi:

To install Ubuntu on Raspberry Pi 4, you need to download the Ubuntu Server 20.04 LTS image for Raspberry Pi.

The Ubuntu Server 20.04 LTS Raspberry Pi image is available on the official website of Ubuntu.

Visit the official website of Ubuntu from your favorite web browser.

ubuntu website

Once the page loads, click on Download and click on Raspberry Pi 2, 3, or 4 from the Ubuntu for the IoT section as marked in the screenshot below.

ubuntu website screenshot

Once the page loads, scroll down a little bit and click on either the Download 64-bit or Download 32-bit button from the Ubuntu 20.04.1 LTS section as marked in the screenshot below.

If you’re using the 2GB or 4GB version of Raspberry Pi 4, then download the 32-bit Ubuntu 20.04 LTS image.

If you’re using the 8GB version of Raspberry Pi 4, then download the 64-bit Ubuntu 20.04 LTS image. Otherwise, you won’t be able to use the full 8GB RAM of your Raspberry Pi 4. A 32-bit operating system can address only 4GB of RAM.

download ubunti pi

Your browser should start downloading the Ubuntu Server 20.04 LTS image for Raspberry Pi shortly.

start downloading

Once your browser prompts you to save the Ubuntu Server 20.04 LTS image for Raspberry Pi, select the location where you want to save the image, and click on Save.

ubuntu prompts you to save

Your browser should start downloading the Ubuntu Server 20.04 LTS image for Raspberry Pi. It may take a while to complete depending on the speed of your internet connection.

start downloading ubuntu
 

Flashing Ubuntu Server 20.04 LTS Image to MicroSD Card:

Once the Ubuntu Server 20.04 LTS image is downloaded, you can use Raspberry Pi Imager to flash the Ubuntu Server 20.04 LTS image to the microSD card.

Insert the microSD card on your computer. Then, open the Raspberry Pi Imager and click on CHOOSE OS.

raspberry pi imager

Scroll down a little bit and click on Use custom.

raspberry pi imager - use custom

Select the Ubuntu Server 20.04 LTS image that you’ve just downloaded and clicked on Open.

raspberry pi imager - use custom

The Ubuntu Server 20.04 LTS image should be selected. Click on the CHOOSE SD CARD button as marked in the screenshot below.

raspberry pi imager - choose sd

Click on the microSD card from the list that you want to flash the Ubuntu Server 20.04 LTS image.

raspberry pi imager- click on the microsd

To write the Ubuntu Server 20.04 LTS image on your selected microSD card, click on WRITE.

raspberry pi imager- write
To confirm the operation, click on YES.

This will remove all the existing data from the microSD card and copy the Ubuntu Server 20.04 LTS image file to the microSD card.

raspberry pi imager - all existing data

Ubuntu Server 20.04 LTS image is being flashed on the microSD card. It may take a while to complete.

raspberry pi imager - loading

Once the Ubuntu Server 20.04 LTS image is flashed on the microSD card, click on CONTINUE and close Raspberry Pi Imager.

raspberry pi imager - continue

 

Configuring Wi-Fi Connectivity:

NOTE: If you want to use Wi-Fi for network connectivity on your Raspberry Pi 4, then this section is for you. If you want to use a wired connection, then you can skip this step.

For the headless configuration of Ubuntu Server 20.04 LTS, you must configure the network (Wi-Fi or wired).

To do that, eject and re-insert the microSD card on your computer. You should see a boot partition as you can see in the screenshot below.

wifi connectivity - boot partition

You should find a network-config file in the boot partition.

wifi connectivity - network config

Open the network-config file in a text editor. The file should have the following contents by default.

wifi connectivity - network config file

Remove the # character from the marked lines (to uncomment the code). Then, change the <WiFi-SSID> and <WiFi-PASSWORD> with the SSID and password of the Wi-Fi network you want to connect to.

Once you’re done, save the network-config file.

wifi connectivity - wifi ssid password

 

Powering on the Raspberry Pi 4:

Connect the microSD card and the USB Type-C power cable on the Raspberry Pi 4.

If you want to use a wired network, connect the RJ45 network cable to the Ethernet port of the Raspberry Pi 4 as well.

Once you’re done, power on the Raspberry Pi 4.

Powering on the Raspberry Pi 4
 

Finding the IP Address of your Raspberry Pi 4:

Login to your Router’s admin panel from a web browser and you should find the IP address of your Raspberry Pi 4 that is assigned to it via the DHCP server running on the Router of your home network.

As you can see, the IP address of my Raspberry Pi 4 is 192.168.0.104. It should be different in your case. So, make sure to replace it with yours from now on.

Finding the IP Address of your Raspberry Pi 4
 

Accessing the Ubuntu Server 20.04 LTS Remotely via SSH:

To remotely access the Ubuntu Server 20.04 LTS operating system running on your Raspberry Pi 4 via SSH, run the following command:

$ ssh ubuntu@192.168.0.104

Accessing the Ubuntu Server 20.04 LTS Remotely via SSH 1

To accept the fingerprint, type in yes and press <Enter>.

Accessing the Ubuntu Server 20.04 LTS Remotely via SSH 2

The default password is ubuntu. Type in ubuntu and press <Enter>.

Accessing the Ubuntu Server 20.04 LTS Remotely via SSH 3

The first time you log into Ubuntu Server 20.04 LTS on your Raspberry Pi 4, you will be asked to change the default password ubuntu.

Type in ubuntu and press <Enter>.

Accessing the Ubuntu Server 20.04 LTS Remotely via SSH 4

Type in a new password and press <Enter>.

Accessing the Ubuntu Server 20.04 LTS Remotely via SSH 5

Retype the password and press <Enter>.

Accessing the Ubuntu Server 20.04 LTS Remotely via SSH 6

The password should be changed and the SSH session should be closed.

Accessing the Ubuntu Server 20.04 LTS Remotely via SSH 7

You can SSH into your Raspberry Pi 4 again with the following command:

$ ssh ubuntu@192.168.0.104

ssh ubuntu 01

Type in the new password and press <Enter>.

ssh ubuntu 02

You should be logged into the Ubuntu Server 20.04 LTS operating system installed on your Raspberry Pi 4.

ssh ubuntu 03

As you can see, I am running Ubuntu 20.04.1 LTS on my Raspberry Pi 4.

$ lsb_release -a

lsb_release

Now, you can run any command you want on your Raspberry Pi 4 remotely via SSH.

Conclusion:

In this article, I have shown you how to install Ubuntu Server 20.04 LTS on your Raspberry Pi 4 in headless mode (without a monitor, a keyboard, and a mouse connected to your Raspberry Pi 4). I have also shown you how remotely manage your Raspberry Pi 4 via SSH.

]]>
Build Your Own Raspberry Pi Weather Station https://linuxhint.com/raspberry_pi_weather/ Sun, 08 Nov 2020 08:21:59 +0000 https://linuxhint.com/?p=75762 Raspberry Pi Sense Hat is an add-on board that can be used with Raspberry Pi single-board computers. The Raspberry Pi Sense Hat has an 8×8 LED display and a 5-button joystick, and it comes equipped with the following sensors:

  1. Gyroscope
  2. Accelerometer
  3. Magnetometer
  4. Temperature
  5. Barometric pressure
  6. Humidity

In this article, I am going to show you how to create a Python API based weather station web application by using the temperature, barometric pressure, and humidity sensors of the Raspberry Pi Sense Hat. To follow along with this article, you will need the following:

  1. A Raspberry Pi 3 or Raspberry Pi 4 with network connectivity.
  2. A Raspberry Pi Sense Hat module.
  3. A micro-USB (Raspberry Pi 3) or USB Type-C (Raspberry Pi 4) power adapter.
  4. A 16 GB or 32 GB microSD card with Raspberry Pi OS.
  5. A laptop or a desktop computer for VNC remote desktop access or SSH access to the Raspberry Pi.

NOTE: In this article, we will connect to the Raspberry Pi remotely via VNC or SSH using the headless setup of the Raspberry Pi. If you do not want to access your Raspberry Pi remotely via SSH or VNC, you will need to connect a monitor, a keyboard, and a mouse to your Raspberry Pi.

To learn how to flash the Raspberry Pi OS image onto a microSD card, please reference How to Install and Use Raspberry Pi Imager. If you need help installing Raspberry Pi OS on your Raspberry Pi, read How to Install Raspberry Pi OS on Raspberry Pi 4. If you need help with the headless setup of Raspberry Pi, check out How to Install and Configure Raspberry Pi OS on Raspberry Pi 4 Without External Monitor.

Connecting Raspberry Pi Sense Hat to Raspberry Pi

Raspberry Pi Sense Hat kit comes with the Raspberry Pi Sense Hat add-on board, a 40-pin male-to-female header, and some screws and spacers.

Before you can attach the Sense Hat board to the Raspberry Pi, you have to connect the 40-pin header to the Sense Hat. Connect the male pins of the 40-pin male-female header to the Sense Hat as shown in the images below.

 

Raspberry Pi single-board computers have 4 holes that can be used to attach add-on boards or a case. To attach the add-on board, insert screws from the back of the Raspberry Pi, as shown in the images below.

Then, connect a spacer to the screw.

Once you add all four screws and spacers , your Raspberry Pi should look like that shown in the image below.

Connect the Raspberry Pi Sense Hat to the 40-pin GPIO male header of the Raspberry Pi, as shown in the images below.

NOTE: Be careful while disconnecting the Raspberry Pi Sense Hat from the Raspberry Pi 40-pin GPIO header to avoid bending the pins of the Raspberry Pi GPIO.

With the four remaining screws, fasten the Raspberry Pi Sense Hat, as shown in the images below.

Powering on the Raspberry Pi

Now that the Raspberry Pi Sense Hat is connected to the Raspberry Pi, insert the microSD card with Raspberry Pi OS into the microSD card slot of the Raspberry Pi, connect the power cable to the Raspberry Pi, and power it on.

Installing the Raspberry Pi Sense Hat Python Library

To use Raspberry Pi Sense Hat on the Raspberry Pi, the sense-hat Python library must be installed on the Raspberry Pi OS. The sense-hat library is available in the official package repository of Raspberry Pi OS.

To install the Raspberry Pi sense-hat Python library on the Raspberry Pi OS, first update the APT package repository cache with the following command:

$ sudo apt update

Then, run the following command:

$ sudo apt install sense-hat -y

Installing the Flask Micro Web Framework Python Library

We will use the Flask Python framework to create our weather application. You can install Flask from the official package repository of Raspberry Pi OS with the following command:

$ sudo apt install python3-flask -y

Creating a Project Directory

It is a good idea to create a project directory to organize your project files. To create a project directory ~/work, use the following command:

$ mkdir ~/work

Once the project directory is created, navigate to the project directory as follows:

$ cd ~/work

Testing the Raspberry Pi Sense Hat

To test whether the Raspberry Pi Sense Hat is working, we can write a simple test Python script. You can create a new Python script called test.py with the nano text editor as follows:

$ nano test.py

Enter the following code in the test.py file. Line 1 imports SenseHat from the sense_hat module, line 3 creates a SenseHat object and stores a reference in the sense variable, and lines 5–6 set the color of all 8×8 LEDs to red. Once you are done, press <Ctrl> + X followed by Y and <Enter>.

You can run the test.py Python script with the following command:

$ python3 test.py

The 8×8 LED matrix should glow in red color as shown in the image below.

To turn off the LEDs of the Sense Hat, run the clear() method without any color value in the test.py Python script, as shown in the screenshot below, and run the test.py Python script again.

The LEDs of the Sense Hat should now be turned off, as shown in the image below.

If the Sense Hat is working properly, then move on to the next section.

Getting Weather Data from Sense Hat

You can obtain sensor data from the Sense Hat very easily by using the sense-hat Python library. To retrieve sensor data from the Sense Hat, you can create a new Python script read_sensor_data.py as follows:

$ nano read_sensor_data.py

Enter the following code in the read_sensor_data.py Python file.

from sense_hat import SenseHat
from time import sleep
sense = SenseHat()
sense.clear()
while True:
    tempC = sense.get_temperature()
    tempF = tempC * (9/5) + 32
    pressure = sense.get_pressure()
    humidity = sense.get_humidity()

    print("Temperature: %.2f°C/%.2f°F\n" % (tempC, tempF))
    print("Pressure: %.2f mb\n" % (pressure))
    print("Humidity: %.2f%%\n\n" % (humidity))
    sleep(5)

Once you are done, press <Ctrl> + X followed by Y and <Enter>.

In the code above, lines 1 and 2 import all the required libraries, line 4 creates a SenseHat object, and line 5 turns off all the LEDs of the Sense Hat using the clear() method. The while loop in line 7 is an infinite loop that will run the code in lines 8–16 forever.

In line 8, the get_temperature() method is used to read the temperature data (in degrees Celsius) from the humidity sensor of the Sense Hat. In line 9, the temperature data is converted from degrees Celsius to degrees Fahrenheit. In line 10, the get_pressure() method is used to read the air pressure data (in millibars) from the pressure sensor of the Sense Hat. In line 11, the get_humidity() method is used to read the humidity data (in %) from the humidity sensor of the Sense Hat.

Lines 13–15 are used to print the sensor data to the console, and line 16 is used to wait for 5 seconds before reading the sensor data again.

You can run the read_sensor_data.py Python script as follows:

$ python3 read_sensor_data.py

Once the script is run, sensor data will be printed to the console.

Now that we can read the sensor data from the Sense Hat, press <Ctrl> + C to stop the program.

Creating a Weather Station Web App

In this section, we will show you how to use the Python Flask web framework to create a weather API and a weather application. The weather application will access the weather data API and show the weather data in real time. All the code discussed in this section is available on GitHub at shovon8/raspberry-pi-sense-hat-weather-app.

First, create a server.py Python script in the project directory as follows:

$ nano server.py

Enter the following code in the server.py Python file.

from flask import Flask
from flask import jsonify
from flask import render_template
from flask import url_for
from sense_hat import SenseHat
app = Flask(__name__)
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
sense = SenseHat()
sense.clear()
with app.test_request_context():
    url_for('static', filename='style.css')
    url_for('static', filename='app.js')
@app.route('/api')
def api():
    tempC = sense.get_temperature()
    tempF = tempC * (9/5) + 32
    pressure = sense.get_pressure()
    pressurePsi = pressure * 0.0145038
    pressureP = pressure * 100
    humidity = sense.get_humidity()
   
    return jsonify({
        "temperature": { "C": tempC, "F": tempF },
        "pressure": { "mb": pressure, "hPa": pressure,
        "psi": pressurePsi, "P": pressureP },
        "humidity": humidity
    })
@app.route('/')
def home():
    return render_template('./home.html')

Then, press <Ctrl> + X followed by Y and <Enter> to save the server.py Python script.

In the code above, lines 1–5 import all the required libraries, line 7 creates a Flask app, line 11 creates a SenseHat object, and line 12 turns off all LEDs of the Sense Hat. Line 8 disables web caching for the Flask app. Because this app is lightweight, there is no need for caching. If you want to modify the app, then having web caching disabled will make testing much easier.

Lines 18–31 read the sensor data from the Sense Hat and return the API data in JSON format on HTTP GET request in the /api endpoint of the web server. Lines 37–39 return the weather web app homepage on the / endpoint of the web server. The homepage is rendered from the home.html file, which should be in the templates/ directory of the project directory.

Lines 14–16 are used to allow access to the style.css and app.js static files. These files should be in the static/ directory of the project directory. The style.css file is used to style the home.html homepage, and the app.js file is used to request the API data from the /api endpoint and update the weather data on the home.html page every 5 seconds.

Create the static/ and templates/ directory in the project directory as follows:

$ mkdir -v {static,templates}

Create a home.html file in the templates/ directory as follows:

$ nano templates/home.html

Enter the following code in the home.html file.

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Raspberry Pi Weather Station</title>
    <link rel="stylesheet" type="text/css"
   href="{{ url_for('static', filename='style.css') }}"/>
</head>
<body>
<div id="content">
    <h1>Raspberry Pi Weather Station</h1>

    <div class="data-content">
        <h2>Temperature</h2>
        <div class="data-row">
            <div class="data-cell" id="tempC">
                ...
            </div>
            <div class="data-cell" id="tempF">
                ...
            </div>
        </div>
    </div>

    <div class="data-content">
        <h2>Pressure</h2>
        <div class="data-row">
            <div class="data-cell" id="pressureMb">
                ...
            </div>
            <div class="data-cell" id="pressurePsi">
                ...
            </div>
        </div>
        <div class="data-row">
            <div class="data-cell" id="pressureHpa">
                ...
            </div>
            <div class="data-cell" id="pressureP">
                ...
            </div>
        </div>
    </div>

    <div class="data-content">
        <h2>Humidity</h2>
        <div class="data-row">
            <div class="data-cell" id="humidity">
                ...
            </div>
        </div>
    </div>
</div>

<script type="text/javascript" src="{{ url_for('static', filename='app.js') }}"></script>
</body>
</html>

Then, press <Ctrl> + X followed by Y and <Enter> to save the home.html file.

Create a style.css file in the static/ directory as follows:

$ nano static/style.css

Enter the following codes in the style.css file.

@import url('https://fonts.googleapis.com/css2?family=Roboto&amp;display=swap');
* {
    padding: 0;
    margin: 0;
    font-family: 'Roboto', sans-serif;
}
body {
    background: #737373;
}
h1 {
    display: block;
    color: #79DC7B;
    text-align: center;
    font-weight: 400;
    background: #000;
    padding: 0.5em 0;
}
h2 {
    display: block;
    background: #000;
    color: #fff;
    text-align: center;
    font-weight: 400;
    font-size: 1em;
}
.data-content {
    margin: 10px;
    border: 2px solid black;
    border-radius: 5px;
    background-color: #79DC7B;
}
.data-row {
    display: flex;
    flex-direction: row;
}
.data-cell {
    width: 100%;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.5em;
    color: #006902;
}
.data-cell:hover {
    background: #FFE891;
    color: #AA8600;
    cursor: pointer;
}

Then, press <Ctrl> + X followed by Y and <Enter> to save the style.css file.

Create an app.js file in the static/ directory as follows:

$ nano static/app.js

Enter the following code in the app.js file.

window.addEventListener('load', main);
function main() {
  function getAPIData() {
    var http = new XMLHttpRequest();
   
    http.onreadystatechange = function() {
        if(this.readyState === 4 && this.status === 200) {
          update(JSON.parse(this.responseText));
        }
    }
   
    http.open("GET", "/api", true);
    http.send();
  }
 
 
  function update(apiData) {
    var tempC = document.getElementById("tempC");
    var tempF = document.getElementById("tempF");
    var pressureMb = document.getElementById("pressureMb");
    var pressurePsi = document.getElementById("pressurePsi");
    var pressureHpa = document.getElementById("pressureHpa");
    var pressureP = document.getElementById("pressureP");
    var humidity = document.getElementById("humidity");
   
    tempC.innerHTML = parseFloat(apiData.temperature.C).toFixed(2) + "°C";
    tempF.innerHTML = parseFloat(apiData.temperature.F).toFixed(2) + "°F";
   
    pressureMb.innerHTML = parseFloat(apiData.pressure.mb).toFixed(2) + " mb";
    pressurePsi.innerHTML = parseFloat(apiData.pressure.psi).toFixed(2) + " psi";
    pressureHpa.innerHTML = parseFloat(apiData.pressure.hPa).toFixed(2) + " hPa";
    pressureP.innerHTML = parseFloat(apiData.pressure.P).toFixed(2) + " P";
     
    humidity.innerHTML = parseFloat(apiData.humidity).toFixed(2) + " %";
  }
 
 
  function app() {
    window.setInterval(function() {
      getAPIData();
    }, 5000);
  }
 
  app();
}

Then, press <Ctrl> + X followed by Y and <Enter> to save the app.js file.

Here, line 1 runs the main() function when the web page finishes loading. In the main() function, the getAPIData() function fetches the weather API data using AJAX and calls the update() function (in line 10) once the data has been successfully fetched. The update() function updates the web page element using the API data.

In line 20, the document.getElementById() method is used to get the reference of the web page element with the id tempC. Line 28 is used to replace the content of the web page element that has the id tempC with the temperature (in Celsius) from the API. In the same way, the contents of all web elements (lines 21–26) are replaced with their respective API data.

In the app() function, the getAPIData() is called every 5 seconds (5000 milliseconds) to keep the weather data up to date in the weather app. Finally, in line 46, the app() function is executed.

To test the web app, enter the following command:

$ FLASK_APP=server.py flask run --host=0.0.0.0

The weather app should run on port 5000 (by default).

To test whether the Weather API is working, run the following command:

$ curl -s <a href="http://localhost:5000/api">http://localhost:5000/api</a> | json_pp

As you can see, the Weather API data is printed to the console. Therefore, the API is working.

To test the Weather app, visit http://localhost:5000 from a Chromium web browser. The Weather app should be loaded on the web browser, but no weather data should be displayed at first.

After a few seconds, the weather app should finish fetching the weather data from the API and display it.

At any point, you can press <Ctrl> + C to stop the web server.

Creating Systemd Service for the Weather Web App

In this section, we will show you how to create a systemd service file for the weather app so that it will automatically start upon booting.

First, create a weather-station.service file in your project directory as follows:

$ nano weather-station.service

Enter the following lines of code in the weather-station.service file.

[Unit]
Description=Raspberry Pi Weather Station Web App Using Raspberry Pi Sense Hat
After=network.target

[Service]
WorkingDirectory=/home/pi/work
Environment=FLASK_APP=server.py
Environment=FLASK_ENV=production
ExecStart=/usr/bin/flask run --host=0.0.0.0
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi

[Install]
WantedBy=multi-user.target

Then, press <Ctrl> + X followed by Y and <Enter> to save the weather-station.service file.

Copy the weather-station.service file to the /etc/systemd/system/ directory with the following command:

$ sudo cp -v weather-station.service /etc/systemd/system/

Reload the systemd daemons for the changes to take effect as follows:

$ sudo systemctl daemon-reload

The weather-station systemd service should be inactive at the moment, as shown in the screenshot below.

$ sudo systemctl status weather-station.service

Start the weather-station service with the following command:

$ sudo systemctl start weather-station.service

As you can see, the weather-station service is now running.

$ sudo systemctl status weather-station.service

Now that the weather-station service is working, you can add it to the system startup of Raspberry Pi OS with the following command:

$ sudo systemctl enable weather-station.service

Reboot your Raspberry Pi with the following command:

$ sudo reboot

Once your Raspberry Pi boots, the weather-station service should be running, as shown in the screenshot below.

$ sudo systemctl status weather-station.service

Accessing the Weather App from Other Devices

To access the weather app from other devices in your home network, you need to know the IP address of your Raspberry Pi. You can find the IP address of your Raspberry Pi 4 from the web management interface of your home router. In our case, the IP address is 192.168.0.103, but this address will be different for you, so make sure to replace this address with yours in all subsequent steps.

If you have access to the Raspberry Pi console, you can run the following command to find the IP address as well.

$ hostname -I

Once you know the IP address of your Raspberry Pi, you can access it from any device in your home network. As shown in the screenshot below, we have accessed the weather app from an Android smartphone.

Conclusion

In this article, we showed you how to use the Raspberry Pi Sense Hat to build a Raspberry Pi weather station. We used the sense-hat Python library to extract weather data from the Raspberry Pi Sense Hat. Then, we used the Flask Python micro web framework to create a weather API and a web application. The web app gets the weather data from the weather API every 5 seconds to keep the web app up to date with the latest weather data. ]]> Using Raspberry Pi Camera Module https://linuxhint.com/raspberry_pi_camera/ Sun, 08 Nov 2020 08:06:08 +0000 https://linuxhint.com/?p=75922

With the Raspberry Pi Camera module, you can take pictures and record videos using your Raspberry Pi. The module does not require much power to work, and the 5V power supply that you use to power your Raspberry Pi is enough to run both the camera module and the Raspberry Pi.

The Raspberry Pi camera module is available with different camera resolutions. Currently, there are three Raspberry Pi camera modules available: (1) the Camera Module V2 with an 8-megapixel Sony IMX219 camera sensor, (2) the Pi NoIR Camera V2, which also has an 8-megapixel Sony INX219 camera sensor but does not have an infrared filter, and (3) the Raspberry Pi High-Quality Camera, which uses the 12.3-megapixel Sony IMX477 sensor.

In this article, we will show you how to connect the Raspberry Pi camera module to the Raspberry Pi and how to take pictures and record videos using the camera module. We will use the Raspberry Pi Camera Module V2 in this article, but the other camera modules work the same way.

To follow this article, you will need the following:

  1. a Raspberry Pi 3 or Raspberry Pi 4 with network connectivity;
  2. a Raspberry Pi camera module;
  3. a micro-USB (Raspberry Pi 3) or USB Type-C (Raspberry Pi 4) power adapter;
  4. a 16 GB or 32 GB microSD card with Raspberry Pi OS; and
  5. a laptop or desktop computer for VNC remote desktop access or SSH access to the Raspberry Pi.

NOTE: In this article, we will connect to the Raspberry Pi remotely via VNC or SSH using the headless setup of the Raspberry Pi. If you do not want to access your Raspberry Pi remotely via SSH or VNC, you will need to connect a monitor, a keyboard, and a mouse to your Raspberry Pi.

To learn how to flash the Raspberry Pi OS image onto a microSD card, please reference How to Install and Use Raspberry Pi Imager. If you need help installing Raspberry Pi OS on your Raspberry Pi, read How to Install Raspberry Pi OS on Raspberry Pi 4. If you need help with the headless setup of Raspberry Pi, check out How to Install and Configure Raspberry Pi OS on Raspberry Pi 4 Without External Monitor.

Hardware Setup

The Raspberry Pi Camera V2 camera module kit comes with the documentation and the camera module.

The camera module should go in the CAMERA CSI Connector, as shown in the image below. The Raspberry Pi CAMERA CSI Connector should have a thin plastic film attached to it for protection. Remove the thin plastic film from the CAMERA CSI Connector.

Once the thin plastic film is removed from the CAMERA CSI Connector, it should look as shown in the image below.

The CAMERA CSI Connector is locked by default. To connect the Raspberry Pi camera module to the CAMERA CSI Connector, you must first unlock it. To unlock the CAMERA CSI Connector, pull the black part as shown in the images below, to lift it.

The, the Ribbon cable of the Raspberry Pi Camera module should be inserted into the CAMERA CSI Connector.

Put the ribbon cable of the Raspberry Pi camera module in the CAMERA CSI Connector. Make sure that the pins of the ribbon cable are facing forward, as shown in the image below.

Push the ribbon cable into the CSI connector carefully. Make sure that a the pins are partially visible, as shown in the image below.

Push the black holder of the CSI Connector down to lock the ribbon cable in place.

Once the ribbon cable is locked to the CSI Connector, it should look as shown in the image below.

The camera module has a thin plastic film attached to the lens of the camera by default to protect the lens from accidental damage. However, before you use the camera, you must remove the plastic film.

Once the thin plastic film is removed from the camera, it should look like that shown in the image below. Now, the camera is ready to take photos and record videos.

Powering on the Raspberry Pi

Once the camera module is connected to the Raspberry Pi, connect the power cable to the Raspberry Pi and power it on.

Configuring Raspberry Pi Camera Module

To take pictures and record videos with the Raspberry Pi camera module, you must enable it from the Raspberry Pi configuration software. Start the Raspberry Pi Configuration command-line utility with the following command:

$ sudo raspi-config

Select Interfacing Options and press <Enter>.

Select Camera and press <Enter>.

Select <Yes> and press <Enter>.

Press <Enter>.

Select <Finish> and press <Enter>.

Select <Yes> and press <Enter>. Your Raspberry Pi should reboot.

Once your Raspberry Pi boots, the Raspberry Pi camera module should be enabled.

Creating a Project Directory

To organize your project files, create a project directory ~/work with the following command:

$ mkdir ~/work

Once the project directory is created, navigate to the project directory as follows:

$ cd ~/work

Taking Images from the Command Line

You can capture images from the Raspberry Pi camera from the command line using the raspistill command line program. raspistill comes preinstalled with Raspberry Pi OS.

To take an image from the Raspberry Pi camera and save it as a new file image1.jpg, run the following command:

$ raspistill -o image1.jpg

As you can see, a new image file image1.jpg has been created.

$ ls -lh

As you can see, the Raspberry Pi Camera module has taken an image.

The maximum supported image resolution for my Raspberry Pi Camera V2 8-megapixel camera is 3280×2464 pixels.

To take image at a lower resolution (i.e., 1024×768 pixels), run the following command:

$ raspistill -w 1024 -h 768 -q 100 -o image2.jpg

As you can see, a new image has been taken.

$ ls -lh

The new image has a resolution of 1024×768 pixels.

You can flip the image vertically using the -vf flag as follows:

$ raspistill -vf -o image3.jpg

As you can see, the image has been flipped vertically.

You can also flip the image horizontally using the -hf flag as follows:

$ raspistill -hf -o image4.jpg

As you can see, the image has been flipped horizontally.

Recording Videos from the Command Line

You can record videos with the Raspberry Pi camera from the command line by using the raspivid command line program. raspivid comes preinstalled on the Raspberry Pi OS.

To record a video with the Raspberry Pi camera and save it as a new file video1.h264, run the following command:

$ raspivid -o video1.h264

NOTE: The video filename must end with .h264 (H264 video extension).

A short video clip has been recorded and saved as video1.h264, as shown in the screenshot below.

The image below shows the video recorded using the Raspberry Pi Camera module being played.

You can record a video at a specific resolution (e.g., 1024×768 pixels) as follows:

$ raspivid -w 1024 -h 768 -o video2.h264

The image below shows that a new video with a resolution of 1024×768 pixels has been recorded.

$ ls -lh

In the image below, the video with a resolution of 1024×768 pixels is being played in VLC Media Player.

As with the raspistill command ine program, you can use the -vf and the -hf options to flip the recorded video vertically and horizontally, respectively.

Working with the Raspberry Pi Camera using Python

In this section, I will show you how to take pictures and record videos with the Raspberry Pi Camera module using the Python programming language. First, we will take pictures with the Raspberry Pi Camera module using Python.

Create a Python script ex01.py in the project directory as follows:

$ nano ex01.py

Then, type in the following lines of code in the ex01.py file. Once you’re done, press <Ctrl> + X followed by Y and <Enter> to save the ex01.py file.

Here, line 1 imports the PiCamera module from the picamera library, and line 2 imports the sleep function from the time library. In line 4, a new PiCamera object is created and a reference to the object is stored in the camera variable.

The camera start_preview() method is used to open a camera preview window before taking a picture. You can only see the preview window if you’re connected to your Raspberry Pi via an external monitor. The sleep() function is used to wait 5 seconds before taking the picture. The preview window will be displayed for the number of seconds provided. The camera capture() method is used to take a picture with the Raspberry Pi camera module and save it as the image5.jpg file. Once the image is taken, the camera preview window is no longer needed, and the camera stop_preview() method is used to close the camera preview window.

Run the ex01.py Python script as follows:

$ python3 ex01.py

As you can see, the camera preview window is being displayed. The camera preview window will help you align the camera module correctly while taking pictures.

As you can see, a new image has been saved as image5.jpg.

You can also take images at a specific resolution (e.g., 1024×768 pixels) by using a Python script. To do so, first create a new Python script ex02.py as follows:

$ nano ex02.py

Type the following lines of code into the ex02.py Python script file. The code in ex02.py is mostly the same as the code in ex01.py, but the camera resolution property is used in line 5 to set the resolution. Press <Ctrl> + X followed by Y and <Enter> to save the ex02.py Python script.

Run the ex02.py Python script as follows:

$ python3 ex02.py

The camera preview window should be displayed.

As you can see, a new image of resolution 1024×768 pixels has been captured by using ex02.py.

You can also capture multiple images using the Python programming language. To do so, create a Python script file called ex03.py in the project directory as follows:

$ nano ex03.py

Type in the following lines of code in the ex03.py Python script file. Once you are done, press <Ctrl> + X followed by Y and <Enter> to save the ex03.py file.

The code is the mostly same as that in the ex02.py Python script, but the code used to capture the image is inside a for loop. The for loop runs 5 times in this example, and there is a delay of 10 seconds before an image is captured. Therefore, ex03.py will take 5 images at 10-second intervals.

Run the ex03.py Python script as follows:

$ python3 ex03.py

As you can see, ex03.py took 5 images with the Raspberry Pi Camera module.

You can also record videos with your Raspberry Pi Camera using the Python programming language. To do so, create a new Python script ex04.py as follows:

$ nano ex04.py

Type in the following lines of code in the ex04.py Python script. Once you are done, press <Ctrl> + X followed by Y and <Enter> to save the ex04.py Python script.

Here, line 1 imports PiCamera from the picamera library, line 3 initializes the PiCamera, and line 4 sets the camera resolution to 640×480 pixels. Line 6 starts the camera preview so that you can see what the Raspberry Pi Camera module is recording, and line 7 starts the recording and saves the recording to video3.h264. Remember the filename must end with .h264 extension.

Line 8 is used to record the video for 120 seconds., and line 9 is used to stop the recording. Once the recording is complete, line 10 is used to stop the camera preview, as we will no longer need it.

Run the ex04.py Python script as follows:

$ python3 ex04.py

As you can see, the video is recorded and saved to the file video3.h264.

As you can see, the recorded video is being played.

Converting H264 Video Files to MP4

By default, the videos recorded by the Raspberry Pi Camera module are saved in H264 format. However, the most commonly used format is the MP4 format. In this section, we will show you how to convert an H264 video to MP4 video format on Raspberry Pi OS by using the gpac command-line program. This program does not come preinstalled on the Raspberry Pi OS, but it is available in the official package repository of the Raspberry Pi OS.

First, update the APT package repository cache with the following command:

$ sudo apt update

To install gpac, run the following command:

$ sudo apt install gpac

To confirm the installation, press Y and then press <Enter>.

Now, gpac should be installed.

To convert a video3.h264 file to MP4, run the following command:

$ MP4BOX -add video3.h264 video3.mp4

The H264 video is being converted to MP4 format.

At this point, the video has been converted to MP4.

By now, a new MP4 file should have been created in the project directory, as shown in the screenshot below.

$ ls -lh

As you can see, the converted MP4 file is being played on the VLC Media Player.

Conclusion

In this article, we showed you how to connect the Raspberry Pi camera module to the Raspberry Pi and how to take pictures and record videos from the command line using the Raspberry Pi camera module and the Python programming language.

]]>
Build a Raspberry Pi 4 NAS with Open Media Vault 5 https://linuxhint.com/raspberry_pi_open_media_vault/ Sun, 01 Nov 2020 11:57:32 +0000 https://linuxhint.com/?p=75026 OpenMediaVault is an open-source network-attached storage (NAS) solution based on the Debian GNU/Linux operating system. You can easily create an NAS server with OpenMediaVault, and OpenMediaVault runs well on Raspberry Pi 4.

At the time of writing, the latest version of OpenMediaVault is OpenMediaVault 5, which can be installed on Raspberry Pi OS to convert your Raspberry Pi 4 into an NAS server. In this article, we will show you how to install and use OpenMediaVault 5 on Raspberry Pi OS.

To create a Raspberry Pi 4 NAS with OpenMediaVault, you will need:

  1. a Raspberry Pi 4 single-board computer,
  2. a Raspberry Pi 4 USB Type-C power supply,
  3. a microSD card (16 GB or more) with the Raspberry Pi OS Lite image flashed onto it,
  4. internet connectivity, and
  5. a laptop or desktop computer for flashing the Raspberry Pi OS Lite image onto the microSD card and accessing the Raspberry Pi 4 via SSH.

NOTE: If you do not want to access your Raspberry Pi 4 remotely via SSH, you need to connect a monitor and a keyboard to your Raspberry Pi. However, we will connect to our Raspberry Pi 4 remotely via SSH using the headless Raspberry Pi 4 setup.

Click here if you need help flashing the Raspberry Pi OS Lite image onto the microSD card. If you are still getting the hang of Raspberry Pi and you need help installing Raspberry Pi OS Lite on your Raspberry Pi 4, click here. Finally, if you want to learn more about the headless setup of Raspberry Pi 4, click here.

Connecting to Raspberry Pi 4 via SSH:

For this example, let’s say the IP address of your Raspberry Pi 4 is 192.168.0.104. To connect to your Raspberry Pi 4 via SSH, run the following command from your computer:

$ ssh pi@192.168.0.104


Type in the password of your Raspberry Pi OS and press .


Now, you should be logged into your Raspberry Pi 4.

Upgrading Raspberry Pi OS

Before installing OpenMediaVault 5 on your Raspberry Pi OS, you should upgrade all existing packages of your Raspberry Pi OS. To do so, first update the APT package repository cache of your Raspberry Pi OS with the command $ sudo apt update.


To upgrade the other packages of your Raspberry Pi OS, run the command $ sudo apt upgrade.


To carry out the upgrade, press Y and then <Enter>.


The APT package manager should start downloading all the required packages from the internet. Once the packages are downloaded, the APT package manager should install them one by one.


At this point, all the updates should be installed.


For the changes to take effect, reboot your Raspberry Pi 4 with the command $ sudo reboot.

Installing OpenMediaVault 5 on Raspberry Pi OS

Once your Raspberry Pi 4 boots, run the following command to download the installation script of OpenMediaVault 5:

$ wget https://github.com/OpenMediaVault-Plugin-Developers/installScript/raw/master/install


Now, the OpenMediaVault 5 installation script should be downloaded.


In addition, the OpenMediaVault 5 installation script install should be in your current working directory.

$ ls -lh


Add execute permission to the install script with the command $ chmod +x install.


Now, the install script should have execute permission.

$ ls -lh


To install OpenMediaVault 5, run the install script as follows:

$ sudo bash ./install


The installation script should start installing OpenMediaVault 5. This step will take a while to complete.


At this point, OpenMediaVault 5 should be installed.


Once OpenMediaVault 5 is installed, your Raspberry Pi 4 should reboot.

Accessing OpenMediaVault 5

Once your Raspberry Pi 4 boots, you should be able to access OpenMediaVault 5 from a web browser. To do so, visit http://192.168.0.104 using the web browser of your choice.

You should see the login page of OpenMediaVault 5. The default OpenMediaVault 5 username is admin and the password is openmediavault. Type in admin as the username and openmediavault as the password and click on Login.


Now, you should be logged into the control panel of OpenMediaVault 5.

Changing Your Password in OpenMediaVault 5

If you want to change the default password, then go to System > General Settings > Web Administrator Password, as marked in the screenshot below. Then, type in the new password and click Save.

Now, the OpenMediaVault 5 administrative password should be changed. For the changes to take effect, log out of the OpenMediaVault web interface and then log back in.

Creating an SMB/CIFS Share using OpenMediaVault 5

In this section, we will show you how to set up a simple SMB/CIFS share using OpenMediaVault 5 by using a USB thumb drive as a storage device for OpenMediaVault 5. You can use a USB HDD/SSD if you want; the process will be the same.

If you want to use a USB HDD/SSD or a thumb drive to store data for OpenMediaVault, you have to format it first. To do that, go to Storage > Disks and select the USB HDD/SSD or thumb drive that you want to use as a storage device for the share and click Wipe.


Click Yes to confirm the wipe operation.


Click Quick as the wiping method.


Once the wipe operation is complete, click Close.

Now, the USB HDD/SSD or thumb drive should be wiped clean.


Next, you have to create a file system. To do so, go to Storage > File Systems and click Create.


Select your USB HDD/SSD or thumb drive from the Device dropdown menu, type in a Label, select a File System format, and click OK.


To confirm the format operation, click Yes.


Then, click Close.


Now, a filesystem should be created on the USB HDD/SSD or thumb drive.


Next, select the newly created file system and click Mount.


For the changes to take effect, click Apply.


To confirm the changes, click Yes.


Once the changes are applied, the newly created filesystem should be mounted.


Now, you can share a folder using OpenMediaVault 5. To share a folder, go to Access Rights Management > Shared Folders and click Add.


Type in the Name of your shared folder, select the file system that you just created from the Device dropdown menu, and select the permissions for your shared folder using the Permissions dropdown menu.

Once you have completed this step, click Save.


A shared folder should be created. For the changes to take effect, click Apply.


To confirm the changes, click Yes.


Next, you have to enable the SMB/CIFS service to share folders from OpenMediaVault 5 for the Windows operating system. To enable Windows share, go to Services > SMB/CIFS and then click the marked toggle button.


Click Save.


For the changes to take effect, click Apply.


To confirm the changes, click Yes.


To create a Samba or SMB/CIFS share, navigate to Services > SMB/CIFS > Shares and click Add.


Select the Shared folder you just created from the dropdown menu. There are many options. You can configure your share however you want. To allow everyone to have full access to the share, we choose Guests allowed from the Public dropdown menu.


Once you are done, click Save.


For the changes to take effect, click Apply.


To confirm the changes, click Yes.

Accessing the SMB/CIFS Share from Windows 10

Once you have created an OpenMediaVault 5 SMB/CIFS share, you can access it from Windows 10. Open File Explorer on Windows 10 and navigate to \\192.168.0.104. The SMB/CIFS share running on the Raspberry Pi 4 should be displayed as shown in the screenshot below.


As you can see, we can copy files to the SMB/CIFS share.


In this image below, the files have been successfully added to the share. Therefore, the OpenMediaVault 5 SMB/CIFS share is working.

Conclusion

In this article, we showed you how to build a Raspberry Pi 4 NAS using OpenMediaVault 5 and how to create and access an SMB/CIFS share using OpenMediaVault 5 from Windows 10.

]]>
How to Setup Raspberry Pi Bluetooth https://linuxhint.com/setup_bluetooth_raspberry_pi/ Fri, 30 Oct 2020 22:15:03 +0000 https://linuxhint.com/?p=74790 Bluetooth is a very popular communication protocol for short-distance wireless communication. There are many Bluetooth devices such as keyboards, mouses, headphones, speakers, etc. that you can connect to your Raspberry Pi using Bluetooth. If you need to transfer small files between your Raspberry Pi and another device like a laptop, or a smartphone, Bluetooth can also come in handy.

In this article, I am going to show you how to setup Bluetooth devices on your Raspberry Pi running the Raspberry Pi OS. So, let’s get started.

Things You Will Need:

To follow this article, you will need the following things:

  1. A Raspberry Pi 3 or Raspberry Pi 4
  2. A micro-USB (Raspberry Pi 3) or USB Type-C (Raspberry Pi 4) power adapter.
  3. A 16 GB or 32 GB microSD card with Raspberry Pi OS (with the desktop environment) flashed.
  4. Network connectivity on the Raspberry Pi
  5. A laptop or a desktop computer for VNC remote desktop access to the Raspberry Pi.

NOTE:

If you don’t want to access your Raspberry Pi remotely via VNC, you need to connect a monitor, a keyboard, and a mouse to your Raspberry Pi as well. I won’t need any of these as I will be connecting to my Raspberry Pi remotely via VNC. My setup is called the headless setup of Raspberry Pi.

If you need any assistance on flashing the Raspberry Pi OS image on the microSD card, check my article How to Install and Use Raspberry Pi Imager.

If you’re a Raspberry Pi beginner and you need any assistance on installing Raspberry Pi OS on your Raspberry Pi, check my article How to Install Raspberry Pi OS on Raspberry Pi 4.

Also, if you need any assistance on the headless setup of Raspberry Pi, check my article How to Install and Configure Raspberry Pi OS on Raspberry Pi 4 Without External Monitor.

Pairing Bluetooth Keyboard, Mouse, and Audio Devices

On Raspberry Pi OS, the default Bluetooth applet (on the top right corner) will let you connect to a Bluetooth input/output device like a keyboard, a mouse, a headphone, or a speaker.

I don’t have any Bluetooth keyboard, mouse, headphone, or speaker. So, I can’t show you exactly how to connect to one. I do have an Android smartphone. It has Bluetooth. I will show you how to pair it with the Raspberry Pi OS. The process should be similar and easier for a Bluetooth keyboard, mouse, headphone, or speaker.

First, right-click (RMB) on the Bluetooth icon ( ) and click on Turn On Bluetooth as marked in the screenshot below.

Bluetooth should be turned on. The color of the Bluetooth icon should be changed to blue.

To pair a Bluetooth device, right-click (RMB) on the Bluetooth icon and click on Add Device… as marked in the screenshot below.

As you can see, it’s searching for a new Bluetooth device.

Once I have turned on Bluetooth on my Android smartphone, it detected my device as you can see in the screenshot below.

To pair the Bluetooth device, select the device and click on Pair.

You should see a 6-digit code on the screen.

You should also get a pairing request on your phone. Make sure the 6-digit number is the same. If it is, click on PAIR.

Click on OK.

Your Bluetooth device should be paired. Click on OK.

Making the Raspberry Pi Bluetooth Discoverable:

To connect to some Bluetooth devices, your Raspberry Pi Bluetooth needs to be discoverable by these devices.

To make your Raspberry Pi Bluetooth discoverable, right-click (RMB) on the Bluetooth icon and click on Make Discoverable as shown in the screenshot below.

The Bluetooth icon should start blinking. It means that the Bluetooth of your Raspberry Pi is now discoverable.

Transferring Files with Bluetooth:

If you want to transfer files from your Raspberry Pi to other devices, or other devices to your Raspberry Pi using Bluetooth, then you need a Bluetooth Manager. There are many Bluetooth managers out there. But in this article, I am going to use Blueman Bluetooth Manager.

Blueman is available in the official package repository of Raspberry Pi OS. So, it’s very easy to install on the Raspberry Pi OS.

First, update the APT package repository cache with the following command:

$ sudo apt update

Update all the existing packages of Raspberry Pi OS with the following command:

$ sudo apt full-upgrade

To confirm the upgrade, press Y and then press .

The APT package manager should start downloading all the required packages from the internet and install them one by one. It may take a while to complete.

At this point, all the updates should be installed.

For the changes to take effect, reboot the Raspberry Pi with the following command:

$ sudo reboot

To install Blueman, run the following command:

$ sudo apt install Blueman

To confirm the installation, press Y and press .

The APT package manager should start downloading all the required packages from the internet and install them one by one. It may take a while to complete.

At this point, Blueman should be installed.

Once Blueman is installed, you can start Blueman from the Raspberry Pi OS Menu > Preferences > Bluetooth Manager.

If Bluetooth is turned off, you should see the following window. Click on Enable Bluetooth to enable Bluetooth.

Blueman should start.

Blueman icon ( ) should also appear in the top menubar.

If you want your Raspberry Pi to be visible to other Bluetooth devices, go to Adapter > Preferences from Blueman as shown in the screenshot below.

Then, select Always visible from Visibility Setting.

If you want, you can also set a name for your Bluetooth device in the Friendly Name section.

Once you’re done, click on Close.

To search for a Bluetooth device, click on Search.

Blueman should find your Bluetooth device.

To pair with the Bluetooth device, right-click (RMB) on the device from the list and click on Pair.

Blueman should show a 6-digit number.

You should also get a pairing request on the selected Bluetooth device. If the 6-digit code matches, click on PAIR.

Then, click on Confirm on the Blueman side.

Click on OK.

The device should be paired. Click on OK.

Once the device is paired, it should be listed in Blueman Bluetooth Manager.

To send a file to your Bluetooth device, right-click (RMB) on it and click on Send a File… as marked in the screenshot below.

A file picker should be opened. Select the file you want to share using Bluetooth and click on OK.

Blueman should start the file transfer process.

Click on ACCEPT to confirm the file transfer on your receiving Bluetooth device (where you are trying to send the file).

The file should be transferred as you can see in the screenshot below.

I have sent an image to my Android smartphone. As you can see, the image was successfully transferred to my Android device via Bluetooth.

You can also send files from your Android device or other Bluetooth enabled devices to your Raspberry Pi via Bluetooth.

First, make sure your Raspberry Pi Bluetooth is discoverable. Then, share any file from your Bluetooth enabled device and select your Raspberry Pi from the list of receiving devices.

Blueman should ask you whether you want to accept the incoming file over Bluetooth. Click on Accept.

As you can see, the file is being transferred to the Raspberry Pi via Bluetooth.

File transfer statistics should also be displayed on the bottom panel of Blueman as you can see in the screenshot below. You can see that Bluetooth communication is very slow.

Once the transfer is complete, you should see the following message.

The files transferred to your Raspberry Pi via Bluetooth should be in the ~/Downloads directory of your Raspberry Pi.

As you can see, the file was successfully transferred to my Raspberry Pi from my Android smartphone.

Conclusion:

In this article, I have shown you how to use Bluetooth on the Raspberry Pi single-board computer with Raspberry Pi OS installed. I have shown you how to pair a Bluetooth device on the Raspberry Pi. I have also shown you how to transfer files from your Raspberry Pi to other Bluetooth enabled devices and vice versa.

]]>
How to Give Your Raspberry Pi a Static IP Address https://linuxhint.com/raspberry_pi_static_ip_address/ Wed, 28 Oct 2020 17:45:47 +0000 https://linuxhint.com/?p=74333 If you want to set up a server (i.e., media server, or web server, or Docker) on your Raspberry Pi system, setting a static IP address is very important. If the IP address changes, your Raspberry Pi server will be inaccessible, defeating the purpose of having a server. So, it is essential to configure a static IP address on your Raspberry Pi system if you are planning to run some kind of server software on it.This article shows you how to configure a static IP address on the Ethernet and Wi-Fi network interface of your Raspberry Pi system running the Raspberry Pi OS.

Things You Will Need

To follow this article, you will need the following:

  1. Raspberry Pi 3 or Raspberry Pi 4
  2. Micro-USB (Raspberry Pi 3) or USB Type-C (Raspberry Pi 4) power adapter
  3. 16 GB or 32 GB microSD card with Raspberry Pi OS flashed
  4. Network connectivity on the Raspberry Pi
  5. Laptop or desktop computer for VNC remote desktop access or SSH access

NOTE: If you do not want to access your Raspberry Pi system remotely via SSH or VNC, you will need to connect a monitor, a keyboard, and a mouse to your Raspberry Pi system, as well. I will not need any of these, as I will be connecting to my Raspberry Pi system remotely via VNC or SSH. My setup is called the headless setup of Raspberry Pi.

If you need any assistance with flashing the Raspberry Pi OS image on the microSD card, check out the article How to Install and Use Raspberry Pi Imager at linuxhint.com.

If you are a Raspberry Pi beginner and you need assistance installing Raspberry Pi OS on your Raspberry Pi system, check out the article How to Install Raspberry Pi OS on Raspberry Pi 4 at linuxhint.com.

Also, if you need any assistance with the headless setup of Raspberry Pi, check out the article How to Install and Configure Raspberry Pi OS on Raspberry Pi 4 Without External Monitor at linuxhint.com.

Configuring Static IP Addresses Graphically

If you are running Raspberry Pi OS in a desktop environment, you can configure a static IP address for your desired network interface very easily from the graphical desktop environment.

Right-click (RMB) on the network icon and click Wireless & Wired Network Settings.

Make sure that interface is selected in the dropdown menu.

Click the empty dropdown menu, as marked in the screenshot below.

Select the network interface you want to configure.

eth0 – the wired ethernet network interface.

wlan0 – the wireless (Wi-Fi) network interface.

Suppose you want to configure the wlan0 Wi-Fi network interface of your Raspberry Pi system.

After selecting the network interface you want to configure, you should see the following window.

Type in your desired static IP address, gateway (Router) address, DNS server address, etc.

If you want, you can also type the IP address in CIDR notation, like 192.168.0.110/24. Here, 24 is the subnet mask length. 24 is equivalent to the subnet mask 255.255.255.0.

To add multiple DNS server addresses, simply separate them with a space, as shown in the screenshot below.

If you only know the IP address you want to set and nothing else about your home or office network, then selecting Automatically configure empty options will request the network configuration from a DHCP server, and will only configure the network information that you did not specify here.

If you know all the required network information, I recommend that you uncheck Automatically configure empty options, as this eliminates the need for a DHCP server on the network.

If you do not need IPv6, check the Disable IPv6 option.

Once you are done, click Apply.

Then, click Close to exit the Network Preferences window.

For the changes to take effect, reboot your Raspberry Pi system with the following command:

$ sudo reboot

Once your Raspberry Pi boots, your desired static IP address should be set on your desired network interface.

You can confirm this with the following command:

$ ip a

Configuring Static IP Addresses via Command-Line

If you are running the minimal version of the Raspberry Pi OS (without any graphical desktop environment) on your Raspberry Pi, then you will not have access to any graphical tools to configure static IP addresses, as shown in an earlier section of this article.

Worry not! From the command line, configuring a static IP address on the wired (eth0) or wireless (wlan0) network interface of your Raspberry Pi system is very easy. In this section, I will show you how to do just that.

First, open the dhcpcd.conf configuration file with the nano text editor as follows:

$ sudo nano /etc/dhcpcd.conf

To configure a static IP address for the wireless (Wi-Fi) network interface (wlan0), add the following lines at the end of the file.

interface wlan0
static ip_address=192.168.0.110/24
static routers=192.168.0.1
static domain_name_servers=8.8.8.8 4.4.4.4
static domain_search=
noipv6

NOTE: Make any necessary adjustments to the configuration (i.e., change IP address, change router/gateway address, change DNS servers) depending on your desired network configuration.

To configure a static IP address for the wired Ethernet network interface (eth0), add the following lines to the end of the file.

interface eth0
static ip_address=192.168.0.111/24
static routers=192.168.0.1
static domain_name_servers=8.8.8.8 4.4.4.4
static domain_search=
noipv6

NOTE: Make any necessary adjustments to the configuration (i.e., change IP address, change router/gateway address, change DNS servers) depending on your desired network configuration.

Once you’re done, press <Ctrl> + X followed by Y and <Enter> to save the dhcpcd.conf configuration file.

For the network configuration changes to take effect, reboot your Raspberry Pi with the following command:

$ sudo reboot

Once your Raspberry Pi boots, your desired static IP address should be set on your desired network interface.

You can confirm this with the following command:

$ ip a

Conclusion

This article showed you how to set up a static IP address on the wired and wireless (Wi-Fi) network interface of your Raspberry Pi system running the Raspberry Pi OS. I have shown both the graphical method and the command-line method of configuring a static IP address in Raspberry Pi.

]]>
How to Boot Raspberry Pi 4 from USB SSD? https://linuxhint.com/how_to_boot_raspberry_pi_4_from_usb_ssd/ Wed, 28 Oct 2020 14:15:36 +0000 https://linuxhint.com/?p=73864

Raspberry Pi 4 firmware supports USB boot. You can easily boot your favorite operating system on your Raspberry Pi 4 from a USB HDD, SSD, or a USB thumb drive instead of the traditional microSD card. There are many benefits of USB boot:

1) Cheaper Storage

USB HDD or USB SSD is cheaper than the same capacity microSD card. So, the cost of storage can be reduced.

2) Faster Boot Time

USB SSDs are a lot faster than the traditional microSD card. The operating system will boot faster from a USB SSD than a traditional microSD card.

3) Longevity

USB SSD or USB HDD has a much longer lifespan than a microSD card. There is a lower chance of hardware failure compared to a microSD card. Again, a USB SSD or USB HDD can handle heavy I/O workloads, unlike a microSD card.

In this article, I am going to show you how to enable USB boot on Raspberry Pi 4 and boot Raspberry Pi OS from a USB SSD/HDD/thumb drive. So, let’s get started!

Things You Will Need:

To follow this article, you will need the following things:

  1. Raspberry Pi 4 single-board computer
  2. USB Type-C power supply for Raspberry Pi 4
  3. MicroSD card with Raspberry Pi OS image flashed
  4. Internet connectivity on the Raspberry Pi 4
  5. Laptop or desktop computer for VNC remote desktop access or SSH access to the Raspberry Pi 4

NOTE: If you don’t want to access your Raspberry Pi 4 remotely via SSH or VNC, you need to connect a monitor, keyboard, and mouse to your Raspberry Pi as well. I won’t need any of these as I will be connecting  my Raspberry Pi 4 remotely via VNC remote desktop protocol. My setup is also called the headless setup of Raspberry Pi 4.

If you need any assistance on flashing the Raspberry Pi OS image on the microSD card, check my article How to Install and Use Raspberry Pi Imager.

If you’re a Raspberry Pi beginner and you need any assistance on installing Raspberry Pi OS on your Raspberry Pi 4, check my article How to Install Raspberry Pi OS on Raspberry Pi 4.

Also, if you need any assistance on the headless setup of Raspberry Pi 4, check my article How to Install and Configure Raspberry Pi OS on Raspberry Pi 4 Without External Monitor.

Enabling USB Boot on Raspberry Pi 4:

In this section, I am going to show you how to enable USB boot on Raspberry Pi 4.

Before you can enable USB boot on your Raspberry Pi 4, you must update all the existing packages of your Raspberry Pi OS. So that we can update the firmware and enable USB boot.

First, update the APT package repository cache with the following command:

$ sudo apt update


The APT package repository cache should be updated.

As you can see, I have some updates available.


To update all the existing packages, run the following command:

$ sudo apt upgrade


To confirm the update, press Y and then press <Enter>.


The APT package manager will download and install all the required updates from the internet. It may take a while to complete.


At this point, all the existing packages should be installed.


For the changes to take effect, reboot your Raspberry Pi 4 with the following command:

$ sudo reboot


Now, you have to update the firmware of your Raspberry Pi 4.

Once your Raspberry Pi 4 boots, open a Terminal and run raspi-config Raspberry Pi configuration tool as follows:

$ sudo raspi-config


From here, select Boot Options and press <Enter>.


Select Boot ROM Version and press <Enter>.


Select Latest Use the latest version boot ROM software and press <Enter>.


Select <Yes> and press <Enter>.


Press <Enter>


Select <Finish> and press <Enter>.


Select <Yes> and press <Enter>. Your Raspberry Pi 4 should reboot. Once it boots, the firmware should be updated.


Now, you can enable USB boot on your Raspberry Pi 4.

Once your Raspberry Pi 4 boots, open a Terminal and run raspi-config as follows:

$ sudo raspi-config


Select Boot Options and press <Enter>.


Select Boot Order and press <Enter>.


Select USB Boot and press <Enter>.


Press <Enter>.


Select <Finish> and press <Enter>.


Select <Yes> and press <Enter>. Your Raspberry Pi 4 should reboot. Once it boots, you should have USB boot enabled.

Checking USB Boot Status:

To check whether USB boot is enabled, open a Terminal and run the following command:

$ vcgencmd bootloader_config


If you have 0xf41 as the BOOT_ORDER, then USB boot is successfully enabled on your Raspberry Pi 4.

Cloning the microSD Card to USB HDD/SDD/Thumb Drive:

You can simply flash your favorite operating system on your USB storage device using Balena Etcher or Raspberry Pi Imager. You can also clone the operating system from the microSD card to your USB storage device (i.e. HDD, SSD, or thumb drive). If you clone the operating system from the microSD card to your USB storage device, you can keep all the data and won’t have to reconfigure the operating system or reinstall the programs you use.

In this section, I am going to show you how to clone Raspberry Pi OS from your microSD card to the USB HDD/SDD/Thumb Drive using your Raspberry Pi 4.

As you can see, currently, Raspberry Pi OS is installed in the microSD card mmcblk0.

$ lsblk


Insert the USB HDD/SSD/Thumb Drive in your Raspberry Pi 4.

It should show up in the storage/block device list, as you can see in the screenshot below.

$ lsblk


From the Raspberry Pi OS menu, go to Accessories > SD Card Copier.


SD Card Copier should start.


Select the microSD card (source) from the Copy From Device dropdown menu and select the USB HDD/SSD/Thumb Drive (target) from the Copy To Device dropdown menu. Once you’re done, click on Start.


To confirm the clone operation, click on Yes.


SD Card Copier should start copying the contents from the microSD card to the USB storage device. It will take a while to complete.


Once the clone operation is complete, click on OK.


Click on Close to close the SD Card Copier.


Now, power off your Raspberry Pi 4 with the following command:

$ sudo poweroff

Booting OS on Raspberry Pi 4 from USB HDD/SDD/Thumb Drive:

Now that the USB storage device is ready, take out the microSD card from the Raspberry Pi 4 and keep only the USB HDD/SSD/Thumb Drive. Then, power on your Raspberry Pi 4.


Your Raspberry Pi 4 should boot from the USB HDD/SSD/Thumb drive.


As you can see, the operating system booted from the USB HDD/SSD/Thumb Drive.

$ lsblk

Conclusion:

In this article, I have shown you how to enable USB boot on Raspberry Pi 4 using the Raspberry Pi OS. I have also shown you how to clone the OS from the microSD card to the USB HDD/SSD/Thumb drive and boot from the USB storage device.

]]>
Monitoring Temperature in Raspberry Pi https://linuxhint.com/monitoring-temperature-in-raspberry-pi/ Wed, 28 Oct 2020 14:13:24 +0000 https://linuxhint.com/?p=71351


 
Monitoring temperatures may be a requirement in many of your Raspberry Pi projects. It is relatively easy to do in Raspberry Pi and the components required for this project are not too costly.This article shows you how to use the DS18B20 digital thermometer module to monitor temperature using Raspberry Pi. The article also demonstrates how to create a web app to display the temperature.

Things You Will Need:

To try out the examples in this article, you will need the following:

  1. A Raspberry Pi single-board computer
  2. A power adapter for the Raspberry Pi device
  3. A microSD card with Raspberry Pi OS installed
  4. Network connectivity on the Raspberry Pi device
  5. A Breadboard
  6. 3 pcs of female-to-female connecting wires
  7. Some male-to-male connecting wires
  8. A 10k resistor
  9. A DS18B20 Digital Thermometer module

DS18B20 Digital Thermometer Pinouts

If you hold the DS18B20 digital thermometer as shown in the image below, the first pin will be ground (GND), the second pin will be DATA, and the third pin will be VCC.

DS18B20 Digital Thermometer Pinouts

Circuit Diagram

The circuit diagram of the temperature monitor is shown in the image below.
Circuit Diagram

Here, the PIN2/5V of the Raspberry Pi device should be connected to the PIN3/VCC of the digital thermometer module.

The PIN7/GPIO4 of the Raspberry Pi device should be connected to the PIN2/DATA of the digital thermometer module.

The PIN9/GND of the Raspberry Pi device should be connected to the PIN1/GND of the digital thermometer module.

A 10kΩ resistor should be connected between PIN2 and PIN3 of the digital thermometer module.

You should hold your Raspberry Pi as shown in the image below. Then, the top-left pin will be PIN1. The pin right next to PIN1 will be PIN2. Then, if you move forward one row, the left one will be PIN3 and the right one will be PIN4, and so on.

raspberry pin1-4

Once you have connected all the components to your Raspberry Pi device, it should look something like this:

raspberry pin 279

Take a closer look at how I placed the components on the breadboard.

breadboard raspberry zoom

Once you have connected all the components to your Raspberry Pi device, power on the Raspberry Pi device. Then, connect to your Raspberry Pi device via VNC or SSH.

Reading Temperature Data from DS18B20 Digital Thermometer

The DS18B20 thermometer module uses the 1-wire communication protocol to send data to the Raspberry Pi. By default, the 1-wire interface is not enabled. You can easily enable the interface from the Raspberry Pi configuration tool.

To enable the 1-wire interface, run raspi-config with the following command:

$ sudo raspi-config

sudo raspbery

Select Interfacing Options and press <Enter>.

pi at raspberry interfacing options

Select 1-Wire and press <Enter>.

select 1 wire enter

Select <Yes> and press <Enter>.

yes and enter

Press <Enter>.

one wire interface is enabled

To exit out of the raspi-config utility, press <Esc>.

raspi config

For the changes to take effect, reboot your Raspberry Pi as follows:

$ sudo reboot

sudo reboot

To check whether the w1_gpio and w1_therm kernel modules are loaded, run the following command:

$ sudo lsmod | grep w1

sudo lsmed grep

If for some reason, the w1_therm module is not loaded, then you can manually load it with the following command:

$ sudo modprobe w1_therm

sudo modprobe

Once you have enabled 1-wire communication and loaded the w1_therm module, a new device (28-00000ba693e9, in my case) should be listed in the /sys/bus/w1/devices directory, as you can see in the screenshot below.

$ ls /sys/bus/w1/devices/

1 wire communcation

Navigate to the new directory, as follows:

$ cd /sys/bus/w1/devices/28-00000ba693e9

cd sys bus

You should find a temperature file in the directory, as you can see in the screenshot below.

$ ls -lh

pi raspberry temperature file

The temperature file is a plain text file. You can read the temperature data using the cat command, as follows:

$ cat temperature

cat temperature

As you can see, the temperature data is printed on the console. Here, 30375 means 30.375°C.

temperature data 30375

You can use a programming language, such as Python or Node.js, to parse this temperature data and use it on your app. I will show you how to do that in the next section of this article.

To parse the temperature data using a programming language, you will need the absolute path to the temperature file. You can find this using the readlink command, as follows:

$ readlink -f temperature

readlink -f temperature

Create a Web App to Display Temperature Data:

In this section, you will learn how to parse the temperature data from the DS18B20 thermometer module and display it on a web app.

In this example, I will create an API, which will parse the temperature data from the DS18B20 thermometer module that can be accessed from the API. I will also create a web app that will fetch the temperature data from the API and display it nicely. I will use the Node.js programming language to do so. The codes are uploaded in my GitHub repository shovon8/ds18b20-raspberrypi-api. You may want to check it out if you are having difficulties copying-and-pasting codes from this article.

Node.js is not installed on Raspberry Pi OS by default. But, it is available in the official package repository of Raspberry Pi OS. You can easily install Node.js from the Raspberry Pi OS package repository.

First, update the APT package repository cache with the following command:

$ sudo apt update

sudo apt update

Next, install Node.js and NPM with the following command:

$ sudo apt install nodejs npm

sudo apt install nodejs npm

To confirm the installation, press Y and then press <Enter>.

confirm the installation

The APT package manager will download and install all the required packages. It may take a while to complete.

apt package manager

At this point, Node.js and NPM should be installed.

node js npm

Once Node.js and NPM are installed, check whether the node and npm commands are available, as follows:

$ node --version
$ npm --version

npm version

Upgrade NPM with the following command:

$ sudo npm install --global npm

sudo npm install

NPM should be upgraded.

npm should be upgraded

As you can see, NPM has been updated from version 5.8.0 to version 6.14.8.

$ node --version
$ npm --version

npm --version

Now that Node.js and NPM are installed, create the new project directory ~/ds18b20, as follows:

$ mkdir -v ~/ds18b20

mkdir -v

Navigate to the ~/ds18b20 directory, as follows:

$ cd ~/ds18b20

cd ds18b20

Create the empty package.json file with the following command:

$ npm init --y

npm init --y

Install the Express.js library for the project with the following command:

$ npm install --save express

npm install save express

The Express.js library should now be installed.

express js library

Create the new file server.js in the project directory, as follows:

$ nano server.js

nano serverjs

Enter the following lines of codes in the server.js file.

let express = require('express');
let fs = require('fs');
let server = express();
const PORT = 8080;
const WEBROOT = './public';
server.get('/', express.static(WEBROOT));
server.get('/temperature', (req, res) =&gt; {
   let tempDataPath = '/sys/bus/w1/devices/28-00000ba693e9/temperature';
   let temperature = fs.readFileSync(tempDataPath, {encoding: 'utf8', flag: 'r'}) / 1000;
   res.json({temperature, rangeStart: -55, rangeEnd: 125});
});
server.listen(PORT, () =&gt; {
   console.log(`server running on port ${PORT}`);
});

Once you are done, press <Ctrl> + X followed by Y and <Enter> to save the server.js file.

ctrl xy serverjs

Here, line 1 imports express, and line 2 imports the fs module.

express fs module

Line 4 initializes express.

line 4 initializes express

Line 6 and 7 define the PORT and WEBROOT constant variables, respectively. The API and webserver will run on PORT (which is 8080, in this article), and the webserver will serve static contents from the WEBROOT (which is the public/ directory inside the project directory in this article).

line 6 7 port webroot

Line 9 is used to configure express to serve static contents from the WEBROOT.

line 9 configure

Lines 11-15 define the API endpoint /temperature, which will be used to get the temperature data into JSON format.

In line 12, the tempDataPath variable holds the absolute path to the temperature file of the DS18B20 digital thermometer module, shown in an earlier section of this article.

In line 13, the temperature data is read from the temperature file using the Node.js fs module, and the temperature data is stored in the temperature variable.

In line 14, the temperature data is printed in JSON format. The DS18B20 digital thermometer module can measure between the temperatures -55°C to 125°C. I have added that in the JSON output using the rangeStart and rangeEnd properties.

line 14 range

Finally, line 17-19 runs the API and webserver on PORT (which is 8080, in this article).

line 17 19 port

Create a public/ directory in the project directory, as follows:

$ mkdir -v public

mkdir -v public

Run the server.js program with the following command:

$ node server.js

node serverjs

The server should be running on port 8080.

running port 8080

You can access the temperature data of the DS18B20 thermometer module from the /temperature endpoint of the API.

To test whether you can get the temperature data from the API, run curl, as follows:

$ curl -s http://localhost:8080/temperature | json_pp

As you can see, the temperature data is printed on the console in JSON format. So, the API is working.

temperature json

Press <Ctrl> + C to stop the server.

ctrl c stop server

Now, I will create a webpage that will request the API server for the temperature data and display it nicely on the page. The temperature data will be updated every 5 seconds.

Create a new index.html file in the public/ directory of the project, as follows:

$ nano public/index.html

nano public indexhtml

Enter the following lines of codes in the index.html file.

<!DOCTYPE html>
<html>
<head>
<title>Temperature Monitor</title>
<style type="text/css">
@import url('https://fonts.googleapis.com/css2?family=Roboto&display=swap');

body, * {
   margin: 0;
   padding: 0;
   font-family: 'Roboto', sans-serif;
   background: black;
}

.progress-container {
   display: fixed;
   width: 100%;
   height: 15px;
   top: 0;
   left: 0;
   background: black;
}

#progress {
   display: block;
   box-sizing: content-box;
   width: 0%;
   height: 100%;
   background: rgb(0,101,181);
   background: linear-gradient(90deg, rgba(0,101,181,1) 0%, rgba(59,255,226,1) 100%);
}

.content-container {
   display: block;
   background: black;
   text-align: center;
}

.content-container h1 {
   color: white;
   font-size: 10em;
}

.content-container span {
   display: block;
   color: #02dd2e;
   padding-bottom: 2em;
}

</style>
</head>
<body>

<div class="progress-container">
   <div id="progress"></div>
</div>

<div class="content-container">
<h1 id="tempContainer">00.00°C</h1>
<span>Temperature updates in every 5 seconds</span>
</div>

<script type="text/javascript">
window.addEventListener('load', main);

function main() {
   function getTemperature() {
      var http = new XMLHttpRequest();
      http.onreadystatechange = function() {
         if (this.readyState == 4 && this.status == 200) {
           updateTemperature(JSON.parse(this.responseText));
         }
   };
   http.open("GET", "/temperature", true);
   http.send();
   }

   function updateTemperature(data) {
      var element = document.getElementById("tempContainer");
      element.innerText = parseFloat(data.temperature).toFixed(2) + "°C"
      console.log(data.temperature);
   }

   function updateProgress(percentage) {
      var element = document.getElementById('progress');
      element.style.width = percentage + "%";
   }

   function app() {
      var percentage = 0;
      var id = window.setInterval(function() {
         updateProgress(percentage);
         if(percentage == 100) {
            getTemperature();
            percentage = 0;
            window.clearInterval(id);
      }
      percentage+=1;
   }, 50);
}

function start() {
   getTemperature();
   window.setInterval(app, 5000);
}

start();
}
</script>
</body>
</html>

Once you are done, press <Ctrl> + X followed by Y and <Enter> to save the index.html file.

ctrl x y index html

The HTML file index.html is easy to understand. It is the format in which the temperature data will be displayed in the web app.

Here, lines 53-55 are used to display a progress bar, and lines 57-60 are used to display the temperature.

line 53-55 progress bar

Lines 5-49 are used to decorate the web app nicely using CSS (Cascading Style Sheet).

line 5-49 css

Lines 62-109 are used to make the web app functional. The JavaScript codes are used to animate the progress bar, fetch the temperature data from the API, and display the information.

Line 63 runs the main function once the web app is loaded in the browser.

line 63 main function

The main function is very long. It spans from line 65 to line 108. Inside the main function, we have some other functions, such as getTemperature, updateTemperature, updateProgress, app, and start.

The updateProgress function, in lines 83-86, takes the percentage of progress as the input and updates the progress bar.

updateProgress

The updateTemperature function in lines 77-81 takes the temperature data as the input and updates the web app with the temperature data.

updateTemperature

The getTemperature function in lines 66-75 makes a request to the /temperature endpoint of the API and gets the temperature data. Once the data is received, it calls the updateTemperature function with the data. The updateTemperature function then updates the web app with the new temperature data.

getTemperature

The app function, in lines 88-99, animates the progress bar and requests the temperature data from the API every 5 seconds.

appfunction

The start function, in lines 101-104, starts the web app.

startfunction

Open the package.json file with the nano text editor as follows:

$ nano package.json

nano package json

Change main to server.js and add the new script serve in the scripts section, as marked in the screenshot below.

Once you are done, press <Ctrl> + X followed by Y and <Enter> to save the package.json file.

ctrl xy packagejson

Now that everything is ready, run the web app and the API with the following command:

$ npm run serve

npm run serve

The server should be running on port 8080.

server should be running port 8080

Now, open a web browser on your Raspberry Pi device and visit http://localhost:8080. The temperature data from the DS18B20 digital thermometer module should be displayed on your web browser, as you can see in the screenshot below.

Temperature Monitor Chromium

The temperature data should be updated every 5 seconds.

Temperature Monitor every 5 seconds

As you can see, the temperature is changing every 5 seconds.

Temperature Monitor as you can see

If you want to access the web app from another computer on your network, you will need to know the IP address of your Raspberry Pi device.

You can find the IP address of your Raspberry Pi device with the following command:

$ hostname -I

As you can see, the IP address of my Raspberry Pi device is 192.168.0.107. This will be different for you. So, make sure to replace the IP address from now on.

Raspberry Pi IP Address

Once you know the IP address of your Raspberry Pi device, you should be able to access the web app from any computer on your network using a web browser. Just visit http://192.168.0.107:8080, and the web app should show the temperature data from the DS18B20 digital thermometer module.

Conclusion

In this article, you learned how to use the DS18B20 digital thermometer module in Raspberry Pi to measure the temperature. You also learned how to create a Node.js API for showing the temperature data in a web app, which accesses the temperature data from the API and displays it. This article should help you get started with Raspberry Pi temperature monitoring with the DS18B20 digital thermometer module and IoT with Raspberry Pi.

]]>
Overclocking Raspberry Pi 4 https://linuxhint.com/overclocking_raspberry_pi_4/ Tue, 27 Oct 2020 20:54:01 +0000 https://linuxhint.com/?p=74252

The processor of the Raspberry Pi 4 can run a specific number of instructions per CPU and GPU clock cycle. This clock cycle unit is called a hertz (Hz). By default, the CPU of the Raspberry Pi 4 runs at 1500 MHz clock frequency (at max) and the GPU runs at 500 MHz clock frequency(at max).Here, 1 MHz = 1,000,000 Hz

So, if the CPU of the Raspberry Pi runs Y number of instructions per clock cycle, the CPU runs = 1500 MHz x Y = 1,500 x 1,000,000 x Y = 1.5x109Y instructions at max

And if the GPU of the Raspberry Pi runs Z number of instructions per clock cycle, the GPU runs = 500 MHz x Z = 500 x 1,000,000 x Z = 0.5x109Z instructions at max

To improve the performance, you can either increase the number of instructions the CPU and the GPU can run per clock cycle or increase the clock frequency. Sadly, you can’t change the number of instructions a processor can run per clock cycle. So, the only way to improve the performance of your Raspberry Pi 4 is to increase the CPU and the GPU clock frequency.

If you need more processing power on your Raspberry Pi 4, you can increase the CPU and the GPU clock cycle of your Raspberry Pi 4 very easily. This will execute instructions much faster on the CPU and the GPU of your Raspberry Pi 4 and reduce program execution time. This is called overclocking.

You can overclock the CPU of your Raspberry Pi 4 from 1500 MHz to 2147 MHz and the GPU of your Raspberry Pi 4 from 500 MHz to 750 MHz.

In this article, I am going to show you how to overclock the CPU and the GPU of your Raspberry Pi 4. So, let’s get started.

Requirements:

To overclock your Raspberry Pi 4, you will need the following things:

  1. A Raspberry Pi 4 single-board computer
  2. A Raspberry Pi 4 USB Type-C power supply.
  3. A microSD card of size 32 GB or higher with Raspberry Pi OS image flashed on to it.
  4. A good Raspberry Pi 4 case including a cooling fan and heat sinks.
  5. Internet connectivity on the Raspberry Pi 4.
  6. A laptop or a desktop computer for VNC remote desktop access or SSH access to the Raspberry Pi 4.

NOTE: If you don’t want to access your Raspberry Pi 4 remotely via SSH or VNC, you need to connect a monitor, a keyboard, and a mouse to your Raspberry Pi as well. I won’t need any of these as I will be connecting to my Raspberry Pi 4 remotely via VNC remote desktop protocol. My setup is also called the headless setup of Raspberry Pi 4.

If you need any assistance on flashing the Raspberry Pi OS image on the microSD card, check my article How to Install and Use Raspberry Pi Imager.

If you’re a Raspberry Pi beginner and you need any assistance on installing Raspberry Pi OS on your Raspberry Pi 4, check my article How to Install Raspberry Pi OS on Raspberry Pi 4.

Also, if you need any assistance on the headless setup of Raspberry Pi 4, check my article How to Install and Configure Raspberry Pi OS on Raspberry Pi 4 Without External Monitor.

Benchmarking Raspberry Pi 4:

To demonstrate how much of a performance increase is possible by overclocking a Raspberry Pi 4, I have used the browser-based benchmarking tool BaseMark.

To use BaseMark, visit https://web.basemark.com from the Chromium web browser and click on Start as shown in the screenshot below.


BaseMark will do a few tests on the web browser. This may take a while to complete.


BaseMark tests are running…


Once the tests are complete, the benchmark result should be displayed. With the default configuration (no overclocking), Raspberry Pi 4 scored 72.08.


In a later section of this article, I will overclock the Raspberry Pi 4, redo the benchmark, and compare the results.

Upgrading Raspberry Pi OS:

Before you attempt to overclock the Raspberry Pi 4, it’s a good idea to upgrade all the existing packages of your Raspberry Pi OS. This way, you will be using the latest kernel and firmware. Any known overclocking bugs may be solved in this new kernel and firmware.

First, update all the APT package repository cache with the following command:

 $ sudo apt update


The APT package repository cache should be updated.


To upgrade all the packages including the kernel and firmware packages (if available), run the following command:

 $ sudo apt dist-upgrade


To confirm the upgrade, press Y and then press <Enter>.


The APT package manager will download and install all the required packages from the internet. It may take a while to complete.


At this point, all the updates should be installed.


For the changes to take effect, reboot your Raspberry Pi 4 with the following command:

 $ sudo reboot

Overclocking the CPU:

In this section, I am going to show you how to overclock the CPU of your Raspberry Pi 4.

You can display the CPU information of your Raspberry Pi 4 with the following command:

 $ lscpu


As you can see, the default maximum CPU clock frequency is 1500 MHz and the minimum CPU clock frequency is 600 MHz.


To overclock the CPU of your Raspberry Pi 4, open the /boot/config.txt file with the nano text editor as follows:

 $ sudo nano /boot/config.txt


To set the CPU clock frequency from 1500 MHz to 1700 MHz, add the line as marked in the screenshot below at the end of the /boot/config.txt configuration file.

Once you’re done, press <Ctrl> + X followed by Y and <Enter> to save the /boot/config.txt configuration file.


For the changes to take effect, reboot your Raspberry Pi 4 with the following command:

 $ sudo reboot


As you can see, the maximum CPU clock frequency has changed to 1700 MHz. The minimum CPU clock frequency has changed as well.

Overclocking the GPU:

In this section, I am going to show you how to overclock the GPU of your Raspberry Pi 4.

By default, the GPU clock frequency is 500 MHz. You can overclock it very easily.

To overclock the GPU clock frequency of your Raspberry Pi 4, open the /boot/config.txt with the nano text editor as follows:

 $ sudo nano /boot/config.txt


To set the GPU clock frequency from 500 MHz to 600 MHz, add the line as marked in the screenshot below.

Once you’re done, press <Ctrl> + X followed by Y and <Enter> to save the /boot/config.txt configuration file.

For the changes to take effect, reboot your Raspberry Pi 4 with the following command:

 $ sudo reboot

Max Overclocking the CPU and the GPU:

You can overclock the CPU and the GPU of your Raspberry Pi 4 to at max 2147 MHz and 750 MHz respectively. To do that, you also need to increase the CPU/GPU core voltage. Otherwise, your Raspberry Pi 4 won’t boot.

The CPU/GPU core voltage can be increased or decreased with the configuration option over_voltage in the /boot/config.txt file. The option over_voltage can be between -16 and 8. The minimum CPU/GPU core voltage is 0.8V (-16) and the maximum CPU/GPU core voltage is 1.4V (8). The increment and decrement step is 0.025V. The default over_voltage value is 0 or 1.2V.

The CPU/GPU core voltage formula is as follows:

CPU/GPU core voltage = 1.2V + over_voltage x 0.025V

Using this formula, you can determine the CPU/GPU core voltage.

For example, the over_voltage value 6 sets the CPU/GPU core voltage to (1.2V + 6 x 0.025V) = 1.35V.

First, open the /boot/config.txt with the nano text editor as follows:

 $ sudo nano /boot/config.txt


To set the CPU clock frequency to 2147 MHz, the GPU frequency to 750 MHz, and to increase the CPU/GPU core voltage, add the following lines at the end of your /boot/config.txt configuration file.

Once you’re done, press <Ctrl> + X followed by Y and <Enter> to save the /boot/config.txt configuration file.


For the changes to take effect, reboot your Raspberry Pi 4 with the following command:

 $ sudo reboot


To benchmark your Raspberry Pi 4 to see how much the performance has increased, visit the BaseMark website https://web.basemark.com from the Chromium web browser.

Once the page loads, click on Start.


BaseMark should start benchmarking your Raspberry Pi 4. It will take a while to complete.


BaseMark tests are running…


BaseMark tests are running…


Once the tests are complete, the benchmark result should be displayed. The max overclocked Raspberry Pi 4 scored 117.61. It is much better than the non-overclocked score of 72.08. We can observe about a 63% performance increase by just overclocking the Raspberry Pi 4.

Conclusion:

In this article, I have shown you how to overclock the CPU and the GPU of Raspberry Pi 4 to improve the performance of Raspberry Pi 4. I have also shown you how to benchmark the Raspberry Pi 4 single-board computer. The performance of Raspberry Pi 4 improves about 63% after maximum overclocking. You may have different results. This article should help you get started with Raspberry Pi 4 overclocking.

]]>