Programming Raspberry Pi in 30 Days: Learn how to build amazing Raspberry Pi projects using Python with ease (English Edition)
()
About this ebook
The book begins with a detailed overview of how to start and set up your Raspberry Pi. It then introduces you to Raspberry Pi OS, including a comparison of 32-bit vs 64-bit and the difference between Raspberry Pi OS Legacy (Buster) and Raspberry Pi OS (Bullseye). Moving on, the book will help you get familiar with some basic Linux and Networking commands. The book also explains how to build GUI applications, web applications, and robots using Raspberry Pi and Python.
With clear explanations, practical examples, and plenty of opportunities for hands-on learning, this book will help you unleash the full potential of your Raspberry Pi and bring your ideas to life.
Related to Programming Raspberry Pi in 30 Days
Related ebooks
Computer Programming JavaScript, Python, HTML, SQL, CSS Rating: 0 out of 5 stars0 ratingsRaspberry Pi: Beginner's Guide - Learn Raspberry Pi in Easy Steps Rating: 2 out of 5 stars2/5PYTHON FOR BEGINNERS: Master the Basics of Python Programming and Start Writing Your Own Code in No Time (2023 Guide for Beginners) Rating: 0 out of 5 stars0 ratingsPython for Beginners: Learn It as Easy as Pie Rating: 0 out of 5 stars0 ratingsPython for Beginners: A Step by Step Guide on How to Program with Python Rating: 0 out of 5 stars0 ratingsLINUX FOR NOVICES: A Beginner's Guide to Mastering the Linux Operating System (2023) Rating: 0 out of 5 stars0 ratingsAndroid Programming For Beginners: The Simple Guide to Learning Android Programming Fast! Rating: 0 out of 5 stars0 ratingsEmbarcadero Delphi A Complete Guide - 2019 Edition Rating: 0 out of 5 stars0 ratingsWeb Data Mining with Python: Discover and extract information from the web using Python (English Edition) Rating: 0 out of 5 stars0 ratingsLinux - a Secure Personal Computer for Beginners Rating: 0 out of 5 stars0 ratingsAssembly Language Step-by-Step: Programming with Linux Rating: 3 out of 5 stars3/5Linux: A Beginner's Guide to Linux Operating System Rating: 0 out of 5 stars0 ratingsMathematics for Machine Learning: A Deep Dive into Algorithms Rating: 0 out of 5 stars0 ratingsAutoHotKey Computer Productivity Book 0: AutoHotKey productivity, #0 Rating: 0 out of 5 stars0 ratingsCryptocurrency Trading Guide : From Novice to Pro Trader: A Comprehensive Guide to Successful Cryptocurrency Trading Rating: 0 out of 5 stars0 ratingsIntro to Bluetooth Low Energy: Learn Bluetooth Low Energy in a single weekend Rating: 0 out of 5 stars0 ratingsLearning Web3 Development Rating: 0 out of 5 stars0 ratings«Guide on Practical Coding Skills for Beginners» Rating: 0 out of 5 stars0 ratingsLearning Apache Thrift Rating: 0 out of 5 stars0 ratingsCoding Basics with Microsoft Visual Studio: A Step-by-Step Guide to Microsoft Cloud Services Rating: 0 out of 5 stars0 ratingsBuilding NFTs with Ethereum: Learn how to create, deploy, and sell NFTs on Ethereum (English Edition) Rating: 0 out of 5 stars0 ratingsPython | Learn to Code Step by Step Rating: 0 out of 5 stars0 ratingsAI and ML for Coders: AI Fundamentals Rating: 0 out of 5 stars0 ratingsTensor Analysis and Elementary Differential Geometry for Physicists and Engineers Rating: 0 out of 5 stars0 ratingsJump Start Web Performance Rating: 0 out of 5 stars0 ratingsC++ Networking 101 Rating: 0 out of 5 stars0 ratingsWavelet Neural Networks: With Applications in Financial Engineering, Chaos, and Classification Rating: 0 out of 5 stars0 ratings
Computers For You
Slenderman: Online Obsession, Mental Illness, and the Violent Crime of Two Midwestern Girls Rating: 4 out of 5 stars4/5The Invisible Rainbow: A History of Electricity and Life Rating: 4 out of 5 stars4/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Standard Deviations: Flawed Assumptions, Tortured Data, and Other Ways to Lie with Statistics Rating: 4 out of 5 stars4/5Elon Musk Rating: 4 out of 5 stars4/5CompTIA IT Fundamentals (ITF+) Study Guide: Exam FC0-U61 Rating: 0 out of 5 stars0 ratingsProcreate for Beginners: Introduction to Procreate for Drawing and Illustrating on the iPad Rating: 0 out of 5 stars0 ratingsAlan Turing: The Enigma: The Book That Inspired the Film The Imitation Game - Updated Edition Rating: 4 out of 5 stars4/5The ChatGPT Millionaire Handbook: Make Money Online With the Power of AI Technology Rating: 0 out of 5 stars0 ratingsThe Hacker Crackdown: Law and Disorder on the Electronic Frontier Rating: 4 out of 5 stars4/5101 Awesome Builds: Minecraft® Secrets from the World's Greatest Crafters Rating: 4 out of 5 stars4/5Mastering ChatGPT: 21 Prompts Templates for Effortless Writing Rating: 5 out of 5 stars5/5CompTIA Security+ Practice Questions Rating: 2 out of 5 stars2/5Everybody Lies: Big Data, New Data, and What the Internet Can Tell Us About Who We Really Are Rating: 4 out of 5 stars4/5Childhood Unplugged: Practical Advice to Get Kids Off Screens and Find Balance Rating: 0 out of 5 stars0 ratingsThe Professional Voiceover Handbook: Voiceover training, #1 Rating: 5 out of 5 stars5/5People Skills for Analytical Thinkers Rating: 5 out of 5 stars5/5Going Text: Mastering the Command Line Rating: 4 out of 5 stars4/5Dark Aeon: Transhumanism and the War Against Humanity Rating: 5 out of 5 stars5/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5AP Computer Science Principles Premium, 2024: 6 Practice Tests + Comprehensive Review + Online Practice Rating: 0 out of 5 stars0 ratingsCreating Online Courses with ChatGPT | A Step-by-Step Guide with Prompt Templates Rating: 4 out of 5 stars4/5How to Create Cpn Numbers the Right way: A Step by Step Guide to Creating cpn Numbers Legally Rating: 4 out of 5 stars4/5
Reviews for Programming Raspberry Pi in 30 Days
0 ratings0 reviews
Book preview
Programming Raspberry Pi in 30 Days - Edgardo Peregrino
CHAPTER 1
Introducing Raspberry Pi
Introduction
Before you can start programming with your Raspberry Pi, it’s important to know what a Raspberry Pi is and what you can do with it. Also, it’s important to know the history and evolution of the Pi; in this chapter, we will cover that. This chapter will also get you familiarized with your Pi so that you can be ready to program with it.
Structure
This chapter will cover the following topics:
What is a Raspberry Pi
History and evolution of the Pi
Model B and B+
Model A, A+, and Model 3A+
Pi 2 Model B
Pi Zero, Zero W, Zero W 2
Pi 3 Model B and Model B+
Pi 4 Model B and Pi 400
Compute Module 4
Raspberry Pi Pico
Getting familiar with your Pi
Objectives
After going through this chapter, you should know about Raspberry Pi, and its history and evolution, and you should be familiar with and identify your Pi.
Welcome
First of all, welcome everyone who has picked up this book and is taking their first steps to learning how to use a Raspberry Pi or Raspberry Pi Pico. By the time you finish this book, you should be inspired to take on more challenging projects and publish your projects. It’s important to start small and work your way up so that you can take all that experience and build something really interesting. So, let’s begin!
Raspberry Pi defined
To start with, what is a Raspberry Pi? It’s certainly not a dessert. It is a microcomputer or single board computer that was first launched in 2012. The Raspberry Pi is often the size of a credit card or smaller, which is amazing considering how it compares to the size of our desktops, laptops, tablets or even some of the earliest computers.
The Pi was created by the Raspberry Pi Foundation, whose goal was to motivate kids and adults alike to get into computer science, especially in the developing countries. It has developed several initiatives to get children into computing, like the Code Club World for children of ages 9 to 13, CoderDojo for young aspiring computer scientists, and Astro Pi, which was responsible for sending two Raspberry Pis into space in 2015! Yes, this little computer made it into the International Space Station; that alone should give you plenty of inspiration.
Raspberry Pi is not as powerful as your typical desktop or laptop, but it has enough power and connectivity to create some interesting projects. For example, several known YouTube content creators like Jeff Geerling created their own Raspberry Pi Clusters to run their own websites, media servers, or even host Minecraft servers. Some have created their own smart mirrors, automated their homes and even built robots that can use deep learning and AI. Raspberry Pis are versatile and can be used for anything; the possibilities are endless.
Raspberry Pi has a large community online that continues to grow and support new users. Whether it’s video game emulation, robotics, AI, cloud native computing or media playback, there is a community for anything you want to create.
History and evolution of the Pi
The first Raspberry Pi was sold on February 29, 2012, and it has seen several iterations since. The following table shows a timeline of all the Raspberry Pi models released since the Model B in 2012:
Table 1.1: Raspberry Pi Release Date Timeline
Model B and B+
This section covers the original Model B and the updated Model B+. It looks at both the history and the specifications of each model.
Model B
The Model B was originally released in February 29, 2012, by the Raspberry Pi Foundation, but it was released with only 256 MB. By October, the board was re-released with 512 MB RAM.. The specifications are as follows:
256MB/512MB of RAM
700MHz processor
2 x USB 2.0 ports
Ethernet port
Micro USB for power
Separate composite video and audio connectors
Full size SD card slot
HDMI
26 Pin General Purpose Input Output Header (GPIO)
Display Serial Interface (DSI)
Camera Serial Interface (CSI)
As you can see, there was no WiFi or Bluetooth, but these features could be added using a USB Dongle. Unlike modern Pis, New Out Of The Box Software (NOOBS) was used to install operating systems like Raspbian (the previous name of Raspberry Pi OS). This board and Model A are the only boards to use full size SD cards to install the operating system and programs. Also, this board and Model A are the only boards to use the 26-pin header, which means that any Raspberry Pi HAT (Hardware Attached on Top) that uses the 40-pin connector will not work.
Despite its limitations in terms of power, it was used for many projects throughout the years. For example, YouTuber Explaining Computers used Model B in a tutorial on controlling motors for a robot in 2014. In 2018, YouTube content creators like the 8-bit Guy, Retro Recipes and Jan Beta used a Model B and an old Apple 2e case to create the Apple PIIe for the Think Different Challenge. So if you still have that Model B, you can use it for many projects, including the projects in this book. Figure 1.1 below shows a typical Model B.
Figure 1.1: Model B (source: sparkfun.com)
Trivia: The very first Raspberry Pi prototype was built in 2006.
Model B+
Model B+ was an updated release of the original Model B, which was first sold on July 14, 2014. This was the first board to use the standard form factor that was used in the later models, such as the Pi 3 Model B and Model B+. Figure 1.2 shows a typical Model B+.
This model added two extra USB ports and aligned them with the ethernet port. It also replaced the full size SD card slot with a Micro SD card slot and combined the composite audio and video connectors into a single connector. Additionally, this was the first Pi with 40 instead of 26 GPIO pins and was used with many Pi HATs and peripherals.
In 2015, the Raspberry Pi Foundation, along with the Astro Pi initiative, sent two Model B+ boards to the International Space Station by British Astronaut Tim Peake. This was possible through an initiative where young coders wrote code that was used to run these two Pis. Think about it: this $35 single-board computer was sent to space, thanks to young aspiring developers.
Figure 1.2: Model B+ (Source: sparkfun.com)
Model A, A+, and 3A+
This section is dedicated to Model A, the updated Model A+ and Pi 3 Model A+, which is currently the final Model A released by the Pi Foundation.
Model A
Model A was a cut down version of Model B and was released on February 4, 2013. Yes, it sounds strange that the Model A came after the Model B, but there is a reason why it has the name. The name comes from the old BBC Microcomputers from 1981, which were called Model A and Model B. Figure 1.3 shows a typical Model A.
Model A only has one USB port and no ethernet port, which means a USB WiFi dongle will be necessary to connect to the internet. Also, it has half the memory of Model B and Model B+. This board is more suited for embedded applications than as a desktop computer.
Figure 1.3: Model A (Source: sparkfun.com)
Model A+
Model A+ was an updated version of Model A and was released to the public on November 10, 2014. It has the exact same ports and connectors as the Model A but has a look similar to that of Model B+. Figure 1.4 shows a typical Model A+. Model A+ is different from Model A as it has 40 GPIO pins and has a micro SD card slot just like Model B+.
Figure 1.4: Model A+ (Source: pololu.com)
Pi 3 Model A+
Raspberry Pi 3 Model A+ is the final Model A at the time of writing this book; it was released on November 15, 2018. Pi 3 Model A+ very similar to Model B+, which was released months earlier. It had the same processor as Model B+ and the same WiFi and Bluetooth chip as Pi 3 Model B+. Figure 1.5 shows a typical Pi 3 Model A+.
The differences between Pi 3 Model B+ and Model A+ are that Model A+ has half the memory as Model B+ and only has one USB port.
Figure 1.5: Raspberry Pi 3 Model A+ (Source: sparkfun.com)
Pi 2 Model B
Raspberry Pi 2 Model B was released on February 2, 2015, and while the form factor was the same as Model B+, there were two changes in this model: it came with 1 GB memory, and it featured a more powerful processor. Figure 1.6 shows a typical Pi 2. The increase in power and memory allowed the Pi to be used as a low-end desktop. In fact, the Pi 2 was the first Pi to be able to use the Ubuntu MATE desktop. And the increase in power meant that it could be used for video game emulation and media playback. Open source media center (OSMC) was introduced for the Pi 2 to allow users to play media locally or using a network share. Also, extensions like YouTube could be added to provide more media streaming options.
It was also the first board to be used in Windows 10 IoT, which is a version of Windows 10 that is used for embedded devices like the Pi and can be used for Internet of Things projects.
Figure 1.6: Raspberry Pi 2 Model B (Source: pololu.com)
Pi Zero, Zero W, and Zero W 2
This section covers the Pi Zero family, which consists of the original Pi Zero, Pi Zero W and the newer Pi Zero W 2.
Pi Zero
The Raspberry Pi Zero was introduced on November 26, 2015, and it featured a smaller form factor than the previous models and was originally given a $5 price. Figure 1.7 shows a typical Pi Zero model. Pi Zero had a processor similar to Model B, Model A, Model B+ and Model A+, but it was clocked at 1 GHz rather than 700 MHz. It also has two Micro USB ports for power and connecting peripherals, a Mini HDMI port for a monitor, and a Micro SD card slot.
To keep the costs down, a GPIO header was not included by default and would have to be added by the user. So if you had a Pi Zero without a header connected, you had to solder it yourself; there was also a version of the Zero with a pre-soldered header. From the specifications listed, it had no WiFi, no Bluetooth and no camera connector. There was another version with a camera connector that was introduced later. The only way to connect to a network was either to buy a USB On the Go (OTG) hub that had a built-in Ethernet port or a USB WiFi Dongle. It used the same processor as the Model B, B+, A, A+ but was a little more powerful and had the same amount of memory.
Figure 1.7: Raspberry Pi Zero (Source: raspberrypi.com)
Pi Zero W
The Raspberry Pi Zero W (Wireless) was introduced on February 28, 2017, and had the same form factor as the Pi Zero but also included a camera connector and the same WiFi and Bluetooth chip that was included on Pi 3. Figure 1.8 shows a typical Pi Zero W. This allowed users to easily access a network without adding any adapters. Also, this board supported a headless setup, which meant you did not need to plug in a monitor to use the Pi. All you needed to do was access the Pi remotely using SSH.
In 2018, Pi Zero W was bundled with the Google AIY Voice Kit V2 and the Vision Kit. The Voice Kit was created to allow users to create programs with voice commands and machine learning, and the Vision Kit allowed users to capture images using machine learning.
Figure 1.8: Raspberry Pi Zero W (Source: my photo album)
Pi Zero W 2
The Raspberry Pi Zero W 2 was introduced on October 28, 2021 and had significant changes compared to the previous model. First, it had what is known as a system-in-package, which differs from a system-on-a-chip. This included both the memory and the processor. This was the first Pi Zero to have a 64-bit processor; in this case, the processor that was used in the early Pi 3 models. Another change was introducing a different WiFi and Bluetooth chip from the original. Figure 1.9 shows a typical Pi Zero W 2. As it was the first 64-bit Pi Zero W, it could run 64-bit software and also 64-bit Raspberry Pi OS. And it was powerful enough for more demanding applications like robotics and home automation.
Figure 1.9: Raspberry Pi Zero W 2 (Source: jeffgeerling.com)
Trivia: YouTube content creator Jeff Geerling took an X-Ray of the Pi Zero W 2 and found the Raspberry Pi logo etched inside the RP3A0-AU chip using gold.
Pi 3 Model B and B+
This section covers both the original Pi 3 Model B and the updated Pi 3 Model B+, along with its specifications, comparisons and differences.
Pi 3 Model B
The Raspberry Pi 3 was released on February 29, 2016, 4 years after the original Model B was released. As of March 2021, Pi 3 sold 13.2 million units according to estimates by Tom’s Hardware. Figure 1.10 shows a typical Pi 3 model. The Pi 3 had the exact same form factor, but it introduced a faster processor and was the first to have a WiFi and Bluetooth chip.
The inclusion of wireless connectivity and a more powerful processor made it possible to use it as a low-end desktop and also made it usable in remote projects that required WiFi. Additionally, it was the first Pi to utilize the PIXEL desktop and to enable USB boot. In 2017, the Amazon Alexa Voice Assistant was used with Pi 3 as shown in Figure 1.10 to enable users to send voice commands to Alexa, and Google introduced the AIY Voice Kit that allowed users to use voice commands with the Google Voice Assistant.
Figure 1.10: Raspberry Pi 3
Pi 3 Model B+
The Raspberry Pi 3 Model B+ was an incremental upgrade of the Pi 3 and was released on Pi Day (March 14) 2018. It had a similar form factor to the Pi 3 but a faster processor with better heat dissipation; a dual band WiFi, which meant it could use 2.4 and 5 GHz wireless network; a faster Ethernet port that was still relegated to USB 2.0 speeds; and a Power over Ethernet (PoE) HAT connector.
With the addition of a PoE header, it was used with the first official PoE HAT to power the Pi 3 B+ using a PoE Switch. This made it easier to build a Pi cluster as all that was needed was a switch and several PoE HATs; there was no need for numerous power adapters. The faster processor meant that the Pi could handle more intensive tasks, and the Dual Band WiFi meant that users could now use faster WiFi networks for remote projects. Figure 1.11 shows a typical Pi 3B+:
Figure 1.11: Raspberry Pi 3 Model B+ (Source: my photo album)
Pi 4 Model B and Pi 400
This section covers the Pi 4 Model B and the Pi 400. It explores the specifications of each and the differences between both models.
Pi 4 Model B
The Raspberry Pi 4 Model B was released on June 24, 2019, and had a few notable features that set it apart from the previous models. It was the first to have 2 USB 3.0 ports, Gigabit Ethernet, two micro HDMI ports, and had a faster processor. It originally came in three varieties: 1, 2 or 4 GB memory.
This model was an upgrade from the previous models. Figure 1.12 shows a typical Pi 4 model. With Gigabit Ethernet and USB 3.0, users could now build a Network Attached Storage (NAS). Pi 4 was the first board to support dual monitors at 4K resolution at 60 frames per second. On May 28, 2020, the Foundation released an 8 GB model that was a first for Pi. Also, the name of the operating system was changed from Raspbian to Raspberry Pi OS. Originally, there was a beta version of the 64-bit Raspberry Pi OS released on that same day. The final release of the 64-bit OS was finally available on February 2, 2022, and was compatible with the Pi 4, Pi 3, Pi 3B+ and the Pi Zero W 2. The Pi 4 also supported USB Boot, which made it possible to use an SSD or hard drive to boot from the Pi much quicker and allow for more storage. The faster processor also meant that Pi 4 was suited for clusters as the PoE HAT for the Pi 3B+ was still compatible with Pi 4, and more RAM and a faster processor allowed users to build clusters to host their websites or scale their applications.
Pi 4 made headlines when two models were sent to the International Space Station to replace the two Model B+ boards that were sent in 2015 thanks to the Astro Pi initiative.
Figure 1.12: Raspberry Pi 4 Model B 2GB (Source: my photo album)
Pi 400
Imagine that you took a 4 GB Pi 4 board and then stuffed it into an official Raspberry Pi Keyboard. You would get Pi 400, which was released on November 2, 2020. Its name derives from the historic Amiga 500 computer. Figure 1.13 shows a typical Pi 400. Unlike the previous models, Pi 400 is like using a computer with a built-in keyboard. All you would need is power, a monitor, a mouse, and a micro SD card, and you would be good to go. There is a notable change from Pi 4 in that the processor is much faster, clocking at 1.8 GHz. Pi 400 can boot from USB and also supports dual monitors.
Figure 1.13: Raspberry Pi 400 (Source: sparkfun.com)
Compute Module 4
The Raspberry Pi Compute Module is different from your Raspberry Pi because unlike Pi, Compute Module has no ports or connectors. Instead the Compute Module is a compact board that can connect to external boards. The following table shows the release dates of the Compute Modules in chronological order:
Table 1.2: Raspberry Pi Compute Module Release Date Timeline
Compute Module works differently from the Pi as you need to buy a carrier board to use it. This is often used in industrial applications like robotics, home automation and even deep learning. If you have any of the Compute Modules, then you can still follow along with this book.
Compute Module 4
Unlike previous modules, the Compute Module 4 does not use the form factor you would see with Laptop RAM. The module itself is shaped differently to accommodate the WiFi and Bluetooth chip, the memory, the System on a Chip and the flash storage . And unlike the previous models, it comes in several types. Some come with built in WiFi and Bluetooth, flash storage, and 1, 2, 4, or 8 GB RAM. It also includes a carrier board that connects to the Compute Module and can be used to test applications and hardware. Additionally, it is the first carrier board to include a Peripheral Component Interface Express (PCIe x1) slot that you normally see on your desktop motherboard and is used for graphics cards or other cards. This allows the user to test cards like network cards, storage cards, and USB 3 cards as USB 3 is not included on the carrier board. Figure 1.14 shows a typical Compute Module 4 connected to the official carrier board:
Figure 1.14: Raspberry Pi Compute Module 4 with carrier board (Source: sparkfun.com)
Raspberry Pi Pico
The Raspberry Pi Pico is the first micro controller that was introduced by the Pi Foundation on January 21, 2021 and was the first to use the new RP2040 micro controller chip. This chip was later used in boards like the Arduino Nano RP2040 Connect. This can be programmed using Micro Python, Circuit Python, or C++. Figure 1.15 shows a typical Pico:
Figure 1.15: Raspberry Pi Pico (Source: my photo album)
Note: The Pico W was released on June 30, 2022 and has built in WiFi and Bluetooth for IoT projects.
Getting familiar with your Pi
Now that you have learned about the history and evolution of the Pi, it’s time to get familiar with your Pi. First, you can reference the mentioned figures to know which model you have as that will be very important for what you want to do with your Pi. Now, unlike your desktop or laptop, the Pi’s ports, connectors and components are exposed, so you need to be careful while handling the Pi. To protect your Pi, it’s recommended to give it a case; the foundation sells official Pi cases. The Pi 3, 3B+, 3A+ and the Pi 4 get very hot since their processors are faster than those of the earlier models, so it’s best to keep the chips cooled down with a heat sink and optionally, a fan if you plan to run processor-intensive tasks.
When it comes to connectivity, it’s important to know what ports exist on your model. Whether it supports wireless connectivity, wired connectivity or both, it’s important to keep this in mind when your projects require using the internet, such as building a website, creating a server or connecting your storage to a network. Also, consider connectivity when it comes to USB ports. Most Pi models, except Pi Zero, Zero W and Zero W 2, use full size USB 2.0 ports. The Pi Zero models use a Micro-USB connector, and that will require an adapter, such as a USB On the go (OTG) adapter, to connect devices like a