Reader small image

You're reading from  Learn Robotics Programming - Second Edition

Product typeBook
Published inFeb 2021
PublisherPackt
ISBN-139781839218804
Edition2nd Edition
Concepts
Right arrow
Author (1)
Danny Staple
Danny Staple
author image
Danny Staple

Danny Staple builds robots and gadgets as a hobbyist, makes videos about his work with robots, and attends community events such as PiWars and Arduino Day. He has been a professional Python programmer, later moving into DevOps, since 2009, and a software engineer since 2000. He has worked with embedded systems, including embedded Linux systems, throughout the majority of his career. He has been a mentor at a local CoderDojo, where he taught how to code with Python. He has run Lego Robotics clubs with Mindstorms. He has also developed Bounce!, a visual programming language targeted at teaching code using the NodeMCU IoT platform. The robots he has built with his children include TankBot, SkittleBot (now the Pi Wars robot), ArmBot, and SpiderBot.
Read more about Danny Staple

Right arrow

Chapter 3: Exploring the Raspberry Pi

In the previous chapter, we saw the Raspberry Pi in the deconstruction of a robot. It's no surprise, then, that we'll build a robot using the Raspberry Pi.

In this chapter, we will be using the Raspberry Pi 3A+ as a controller. We'll look at various options when examining this choice, and look at features such as the connections on the Raspberry Pi and how we will use them to understand our decision. We'll move on to exploring Raspberry Pi OS, and will finish by preparing the OS for use on the Raspberry Pi.

The following topics will be covered in this chapter:

  • Exploring the Raspberry Pi's capabilities
  • Choosing the connections
  • What is Raspberry Pi OS?
  • Preparing an SD card with Raspberry Pi OS

Technical requirements

For this chapter, you will need the following:

  • A Micro SD card storing 16 GB or more
  • A Raspberry Pi 3A+
  • A Windows, Linux, or macOS computer or laptop connected to the internet and able to read/write to SD cards

Check out the following video to see the code in action: https://bit.ly/3bBJQt9.

Exploring the Raspberry Pi's capabilities

As we saw in Chapter 2, Exploring Robot Building Blocks – Code and Electronics, the controllers used for a robot can be one of the most critical choices you make. This will determine what kinds of inputs and outputs you have, what the power requirements of your electronics will be, what types of sensors you will be able to use, and what code you will run. Changing a controller could mean rewriting the code, redesigning where the controller would fit, and changing the power requirements.

The Raspberry Pi is a range of small computers designed for use in education. Having I/O pins for connecting it to custom hardware, while being a complete computer, makes it a favorite of makers (a term for people who like to make things for a hobby, like robots and gadgets). This is helped by the relatively cheap cost and small size of a microcontroller compared to standard computing devices. All Raspberry Pi models have abilities including attaching...

Choosing the connections

When building the robot, we will use a subset of the connections the Raspberry Pi has to offer. Let's take a look at what those connections are and how we will use them. As we connect sensors and parts to the Raspberry Pi, we will cover the connections in detail, so do not feel like you need to memorize these now. However, the following pin diagram can serve as a reference for these connections.

In Figure 3.1, the highlighted areas show the connections in use:

Figure 3.1 – Raspberry Pi connections

First, we will be using the power connector, labeled Power In and located at the bottom left of the diagram. This plugs in via a micro-USB connector similar to that on many phones. We will use this while learning to go headless, and this is one of the options for powering a robot. We can plug USB battery packs into this port if they can provide the correct amount of power. Raspberry Pi recommends 2.5 A power supplies, although...

What is Raspberry Pi OS?

Raspberry Pi OS is the choice of software we use to drive the Raspberry Pi, an OS that our code will run in. It is the Raspberry Pi Foundation's official OS and comes with software prepared to make working with the Raspberry Pi easier. Raspberry Pi OS can support a full desktop or a minimal command line and network-only system.

Raspberry Pi OS is based on the Debian Linux distribution. Debian is a collection of software set up to run together, giving lots of functionality and many possibilities. Linux distributions like this are the basis of many internet servers, mobile phones, and other devices. The OS's software is optimized for the Raspberry Pi hardware, namely the kernel and drivers, which are made specifically for it. It also has some neat ways to configure the specialized features that Raspberry Pi users might need.

We will use it in a more minimal way than a desktop, forgoing the keyboard, mouse, and monitor support. This minimal version...

Preparing an SD card with Raspberry Pi OS

To use Raspberry Pi OS on a Raspberry Pi, you need to put the software onto a micro SD card in a way that means the Raspberry Pi can load it.

Raspberry Pi has created the Raspberry Pi Imager to put software onto an SD card. Let's download it and get the right image on our card:

  1. Visit the Raspberry Pi software downloads page at raspberrypi.org/software, and select the Download for button for your computer, as shown in the following screenshot:

    Figure 3.3 – Downloading the Raspberry Pi Imager

    Figure 3.3 shows what this will look like; it should highlight the correct download button for your computer.

  2. Install this using the instructions from Raspberry Pi.
  3. Insert your micro SD card into the correct port on your laptop. You may need an adaptor.
  4. Launch the Imager. We'll start here by choosing the OS. Select the CHOOSE OS button:

    Figure 3.4 – The CHOOSE OS button

    Figure 3.4 shows the CHOOSE OS button, found...

Summary

In this chapter, you've seen more of what the Raspberry Pi is, and which connections on the Raspberry Pi we will use.

We've learned about the Raspberry Pi OS, which is derived from Linux, how to download it, and how to put this software onto a micro SD card for use in the Raspberry Pi.

In the next chapter, we will make this card headless so that we do not need a screen, keyboard, or mouse to use this Raspberry Pi and contact it from our computer.

Assessment

  1. I've recommended a Raspberry Pi 3A+. There are likely to be new models of the Raspberry Pi not considered. What would be their trade-offs? Think about cost, size, power consumption, and computing speed.
  2. Try other Raspberry Pi OS or Raspberry Pi distributions; some will need a keyboard and mouse. Be sure to return to Raspberry Pi OS Lite before carrying on in the book.
  3. I've mentioned the camera (CSI) connector, power, and GPIO ports. Take a look at the other ports on the Raspberry Pi, and perhaps see what they can be used for.

Further reading

Refer to the following links:

  • The Raspberry Pi Foundation guide to installing Raspberry Pi operating systems: https://www.raspberrypi.org/documentation/installation/installing-images/README.md.
  • Raspberry Pi By Example, Ashwin Pajankar and Arush Kakkar, Packt Publishing, which has a section on alternative OSes for a Raspberry Pi, along with many exciting Raspberry Pi projects.
  • Raspberry Pi GPIO pinout (https://pinout.xyz/): This describes how different boards are connected to the Raspberry Pi in terms of the pins they actually use. It's useful to know that most boards only use a subset of these pins.
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Learn Robotics Programming - Second Edition
Published in: Feb 2021Publisher: PacktISBN-13: 9781839218804
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Danny Staple

Danny Staple builds robots and gadgets as a hobbyist, makes videos about his work with robots, and attends community events such as PiWars and Arduino Day. He has been a professional Python programmer, later moving into DevOps, since 2009, and a software engineer since 2000. He has worked with embedded systems, including embedded Linux systems, throughout the majority of his career. He has been a mentor at a local CoderDojo, where he taught how to code with Python. He has run Lego Robotics clubs with Mindstorms. He has also developed Bounce!, a visual programming language targeted at teaching code using the NodeMCU IoT platform. The robots he has built with his children include TankBot, SkittleBot (now the Pi Wars robot), ArmBot, and SpiderBot.
Read more about Danny Staple