37,19 €
The Raspberry Pi Pico is the latest addition to the Raspberry Pi family of products. Introduced by the Raspberry Pi Foundation, based on their RP2040 chip, it is a tiny, fast microcontroller that packs enough punch to power an extensive range of applications. Raspberry Pi Pico DIY Workshop will help you get started with your own Pico and leverage its features to develop innovative products.
This book begins with an introduction to the Raspberry Pi Pico, giving you a thorough understanding of the RP2040's peripherals and different development boards for the Pico designed and manufactured by various organizations. You'll explore add-on hardware and programming language options available for the Pico. Next, you'll focus on practical skills, starting with a simple LED blinking project and building up to a giant seven-segment display, while working with application examples such as citizen science displays, digital health, and robots. You'll also work on exciting projects around gardening, building a weather station, tracking air quality, hacking your personal health, and building a robot, along with discovering tips and tricks to give you the confidence needed to make the best use of RP2040.
By the end of this Raspberry Pi book, you'll have built a solid foundation in product development using the RP2040, acquired a skillset crucial for embedded device development, and have a robot that you built yourself.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 265
Veröffentlichungsjahr: 2022
Build exciting projects in home automation, personal health, gardening, and citizen science
Sai Yamanoor
Srihari Yamanoor
BIRMINGHAM—MUMBAI
Copyright © 2022 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Group Product Manager: Rahul Nair
Publishing Product Manager: Rahul Nair
Senior Editor: Shazeen Iqbal
Content Development Editor: Romy Dias
Technical Editor: Rajat Sharma
Copy Editor: Safis Editing
Project Coordinator: Ashwin Kharwa
Proofreader: Safis Editing
Indexer: Subalakshmi Govindhan
Production Designer: Joshua Misquitta
Marketing Coordinator: Sanjana Gupta
First published: May 2022
Production reference: 1100522
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-80181-481-2
www.packt.com
To all the makers who start several projects at a time and dream of finishing them one day.
– Sai Yamanoor
To the wonderful cats that have owned my heart, Squeaky, Bob, Saxon, Gi-Ve, Fluffy Tux, Angel, Grey Cat, and now, Alphie, Fish-Bone, and Saxi!
– Srihari Yamanoor
Sai Yamanoor is a senior IoT applications engineer at an industrial gases company in Buffalo, NY. He has over 10 years of experience as an embedded systems expert, working on both hardware and software design and implementations. He is a co-author of two books on the use of Raspberry Pi to execute DIY projects, and he has also presented a personal health dashboard at Maker Faires across the country. Sai is currently working on projects aimed at improving the Quality of Life (QoL) for people with chronic health conditions.
I want to thank my parents and my brother and co-author, Sri, for all the help and encouragement. I would also like to thank our technical reviewers, Salman Faris and Jonathan Witts, for their insightful comments and for reviewing our work carefully. I would like to thank Rahul Nair for giving us this opportunity to work with Packt. I would also like to thank Romy Dias and Vaidehi Sawant for their patience and for supporting our work.
Srihari Yamanoor is a mechanical engineer with experience spanning medical device design, CAD/CAM, mechatronics, and sustainability. In collaboration with his brother, he develops open source hardware products aimed at public education and awareness. He has multiple certifications in quality assurance, CAD, and FEA. Besides design, manufacturing, and quality, his current interests include behavioral change and working toward active improvement in the fight against diabetes, innovation paradigms and methodologies, and the impact of AI on healthcare. He is the co-author of two books on Raspberry Pi applications and writes blogs on various topics.
I want to thank my parents, mentors, friends, cats, and my brother and co-author, Sai, for all the help and encouragement. Specifically, I would like to thank my mentors Anna Tamura and Dr. Sudhi Gautam. Similarly, I owe gratitude to my friend Satyakanth Thyagaraja for standing by me during tough times. I would also like to thank the Packt team for all their support with this book, and our efforts throughout the years.
Salman Faris is a digital fabrication and rapid product prototype enthusiast from India who holds a bachelor's degree in computer science and a digital fabrication diploma from the Fab Academy. He is currently working as a technical support engineer at Nebra and is a key contributor to the MakerGram Maker community, where he tinkers with electronics and hardware product development.
Salman is also part of the Edge Impulse expert group, Qubitro, RAK, and Seeed Studio as well as an ambassador and core member of India's largest Maker gathering, Maker Faire Hyderabad, and co-organizer of Maker Fest Kerala.
I'd like to thank Allah first, for His almighty guidance in whatever decisions I make. I'd also like to thank Packt Publishing for the opportunity to review this wonderful book, especially Shagun and Ashwin who managed the review and helped me with guidance and support throughout the process. Thanks also to my parents, siblings, relatives, friends, team Nebra, and mentors.
Jon Witts has worked in IT within the education sector for over 17 years. He holds degrees in fine art and the design and development of e-learning. In his current role, as director of digital strategy, Jon leads all technological solutions in his school, as well as teaching computer science to students aged 11-16. Jon also runs the Hull Raspberry Jam events in his hometown: free coding events for young people using the Raspberry Pi computer. Jon has reviewed a number of titles for Packt and has written his own book, Wearable-Tech Projects with the Raspberry Pi Zero, also published by Packt. In his free time, Jon enjoys creating generative art using the p5.js library and incorporating elements from Raspberry Pi physical computing.
I would like to thank my wife, Sally, and our three daughters, Mabel, Ember, and Ada, for all of their support in allowing me to work on this book. I would also like to thank the authors and all the team at Packt for allowing me to be involved in the process of creating this great publication.
The objective of this section is to introduce the Raspberry Pi Pico, its variants, and the peripherals available on the Raspberry Pi Pico. This part begins slowly by blinking an LED and reviewing the serial interfaces available on the RP2040 microcontroller. Then, we will progress by working on simple home automation and gardening projects.
This section contains the following chapters:
Chapter 1, Getting Started with the Raspberry Pi PicoChapter 2, Serial Interfaces and ApplicationsChapter 3, Home Automation Projects Chapter 4, Fun with Gardening!In this chapter, we would like to delve into a quick introduction to the Raspberry Pi Pico and the RP2040 microcontroller. We will discuss the Raspberry Pi Pico's features, the RP2040's peripherals, the add-on hardware for the Pico, and development boards for the RP2040 developed by other makers. We will also discuss the programming language options available for the Pico and supplement the chapter by discussing a simple "Hello World" example where we print something to the screen and blink a light-emitting diode (LED).
By the end of this first chapter, you will have gotten started with the Pico and will be ready to start programming the RP2040 microcontroller and start planning to implement projects from the later chapters of this book, as well as thinking ahead to how you can tackle your own projects with the Raspberry Pi Pico!
We are going to cover the following main topics:
Introducing the Raspberry Pi Pico and RP2040Discussing variants of the Pico boardSoldering the Pico's headersImplementing the "Hello World!" exampleImplementing the LED-blinking example Identifying useful add-on hardware for the PicoThe hardware and software required for this introductory chapter will be used throughout the book. In further chapters, we will provide any additional or chapter-specific requirements.
The hardware requirements are listed as follows:
A laptop or a Raspberry Pi with a Universal Serial Bus (USB) portOptional: Soldering equipment including iron, solder, safety glasses, and miscellaneous equipmentOptional: Prototyping breadboard and a jumper wire kitCode in Action videos for this chapter can be viewed at https://bit.ly/3MRdYjx.
The Raspberry Pi Pico is the latest educational and industrial tool introduced by the Raspberry Pi Foundation. The Pico, a low-cost microcontroller, costs USD 4, and even at the low price point, the Pico packs quite a punch. The Pico is centered on the RP2040, a dual-core Cortex-M0+ microcontroller. The board comes with a total of 40 pins, where there are 20 pins on each side, as shown in the following screenshot. The Pico also comes with 2 MB of onboard flash memory and an LED on the GP25 (GP refers to General Purpose Input/Output) button.
Figure 1.1 – Raspberry Pi Pico
The datasheet for the Raspberry Pi Pico is available from here: https://bit.ly/3cwv1Ic. In this book, we will be making use of the different peripherals available on the Pico in the projects discussed in each chapter. Hence, it is handy to print the pinout provided by the Raspberry Pi foundation (source: https://bit.ly/3wa0nwq). This pinout sheet can help with pin selection during project planning. A screenshot of the pinout from Adafruit Industries is shown next. You can purchase them for USD 0.50 from their website.
Figure 1.2 – Pico pinout (Image source: Adafruit Industries; License: CC BY-SA 3.0)
The Pico board can be used in various applications involving robots, remote monitoring, citizen science, and so on. In this book, we will walk you through different application examples while exploring the peripherals of the RP2040 microcontroller.
The RP2040 is a dual-core ARM Cortex-M0+ microcontroller with 264 kilobytes (KB) of static random-access memory (SRAM) but does not have have in-built flash memory. The RP2040 comes with a volley of peripherals including Inter-Integrated Circuit (I2C), Serial Peripheral Interface (SPI), and Programmable Input/Output (PIO). The PIO on the RP2040 microcontroller enables you to design your own interface, such as an additional universal asynchronous receiver-transmitter (UART) interface or a video interface. In Chapter 12, Best Practices for Working with the Pico, we will discuss using the PIO peripheral.
Here is a list of the resources for RP2040:
The datasheet for the RP2040 is available at the following link:https://bit.ly/3rw41x5
The datasheet for the Raspberry Pi Pico is available at the following link:https://bit.ly/3cwv1Ic
A video from the Raspberry Pi foundation on the RP2040's PIO can be found at the following link:https://bit.ly/39ni6Xg
Resources for the RP2040 from the Raspberry Pi Foundation can be found by visiting the following link:https://bit.ly/3flFLv9
We recommend that you download Pico's datasheet along with the RP2040 datasheet. It will come in handy as a reference during development, and we will refer you to the datasheet at certain points in this book for more information.
Since the launch of the Raspberry Pi Pico, there have been several developer board variants that include the RP2040 from various open hardware companies. These are boards that come with the RP2040 microcontroller and they are outlined in more detail here:
SparkFun Thing Plus – RP2040 (USD 17.95): This is an open source development board from SparkFun (https://bit.ly/2NS5vUn). The Thing Plus comes in the Feather form factor from Adafruit. Something unique about this board is that it comes with a microSD card holder and an individually addressable RGB LED. If you are not familiar with the Feather form factor, it simplifies prototyping due to its stacking capability and the ecosystem of prototyping tools available in the Feather form factor. In the following screenshot, you can notice the top (on the right) and bottom (on the left) sides of the RP2040 Thing Plus board:Figure 1.3 – SparkFun Thing Plus (RP2040)
SparkFun MicroMod RP2040 Processor (USD 11.95): This is another variant from SparkFun (https://bit.ly/3clp0hG). It comes with 16 MB of onboard flash memory. It comes in the MicroMod form factor that makes use of the M.2 standard. In the following screenshot, you can find the top and bottom sides of the RP2040 MicroMod board. You will notice a notch in a half-moon shape that is used to fasten the board to a carrier board using an M2.5 screw:Figure 1.4 – MicroMod RP2040 Processor
SparkFun also makes carrier boards for the MicroMod ecosystem. For example, the carrier board (https://bit.ly/3cnlrHF) shown in the following screenshot was designed to drive a high-definition multimedia interface (HDMI) display using the RP2040:
Figure 1.5 – MicroMod Big Display Board for the RP2040 processor
SparkFun Pro Micro – RP2040 (USD 9.95): The Pro Micro – RP2040 board (https://bit.ly/3cnhVgH) is a variant that belongs to the relatively small ecosystem of the Pro Micro family of boards. It comes with 16 MB of flash, individually addressable RGB LEDs, and castellated pads that enable soldering the module directly onto another printed circuit board (PCB). The castellated pins of the Pro Micro are shown in the following screenshot:Figure 1.6 – SparkFun Pro Micro – RP2040
Pimoroni Tiny 2040 (USD 11.55): This board from Pimoroni (https://bit.ly/3d9f7Tf) is about the size of a quarter and comes with 8 MB of flash and an RGB LED. The castellated pads enable it to be soldered onto your custom PCB directly. We must point out that you will need a cutout to solder the board onto your custom board. This is because the microcontroller in this development board is on the bottom side, as shown in the following screenshot. We will demonstrate using this board on your custom PCB.Figure 1.7 – Pimoroni Tiny 2040
Adafruit Feather RP2040 (USD 11.95): As the name indicates, this board from Adafruit (https://bit.ly/3cm3tW0) is a Feather board for the RP2040 microcontroller. As with the SparkFun Thing Plus, it packs a punch with a Qwiic/STEMMA connector and comes with 8 MB of flash. At the time of writing this book, this board was out of stock. Here's a screenshot showing the board:Figure 1.8 – Adafruit Feather RP2040
Adafruit ItsyBitsy RP2040 (USD 9.95): This board from Adafruit (https://bit.ly/3sqdB5R) is an addition to their Itsy Bitsy line of products. In terms of its pinouts, it is identical to other Itsy Bitsy products from Adafruit. This board comes with 8 MB of onboard flash memory. This Itsy Bitsy variant, shown along with the Feather board in the following screenshot, is breadboard-friendly. This enables the board to be embedded into your project:Figure 1.9 – Adafruit ItsyBitsy RP2040
Adafruit QT Py RP2040 (USD 9.95): This board (https://bit.ly/3lU2O1q) is an addition to the QT Py family (pronounced "cutie pie") of products from Adafruit. This board also comes with 8 MB of onboard flash memory. The castellated pads of the board shown in the following screenshot enable a PCB to be designed whereby the board could be embedded in your design. Since the RP2040 microcontroller is located on the bottom side, you need to ensure that your design has a cutout to accommodate the QT Py.Figure 1.10 – Adafruit QT Py RP2040
The variants we discussed here are not comprehensive, but we wanted to present some options on getting started with the RP2040 microcontroller. For example, if you are familiar with the Feather form factor, you could get started with the Thing Plus board from SparkFun or the Feather board from Adafruit, discussed in this section. You can use any board of your choice, but the mode of use and interface may differ according to the variant. We will try to highlight any differences wherever possible.
The Pico costs USD 4 and you can buy it from any Raspberry Pi distributor. You can check out the list of Raspberry Pi distributors at this link: https://bit.ly/3dgra1a. You can buy variants of the Pico from the links provided with their description.
We must note that the Raspberry Pi Pico was not in stock in the US at the time of writing this chapter. This can be attributed to supply-chain constraints due to the ongoing Covid-19 pandemic at the time. It was also difficult to purchase the variants for the same reason. Things may change in the future.
We must also note that the RP2040 microcontroller was not available for purchase at the time of writing this chapter.
In this section, we discussed variants of the Pico and where to buy them. In the next section, we will take a look at setting up the Pico.
In this section, we will discuss setting up the Pico for our upcoming projects. This includes soldering the headers and an optional three-dimensional(3D)-printed enclosure.
The Pico comes with 40 pins in two rows of 20 pins. We need to solder the headers to access the peripherals of the RP2040 microcontroller for our project.
Important Note
Soldering the headers requires prior training and adult supervision. Do not attempt soldering without prior training. Here is a tutorial on soldering: https://bit.ly/3focmjM.
You can purchase the headers from the same source as the Pico. For example, you could purchase it from the following link: https://bit.ly/3d9rrUT. The steps to be carried out for soldering include the following:
It is easier to solder the headers with a breadboard. Arrange the headers on a breadboard and stack the Pico on top of it, as shown in the following screenshot:Figure 1.11 – Pico with headers stacked on a breadboard
If you are not quick at soldering the individual pins, you might end up damaging the breadboard due to the excess heat. The following image shows the pins of the Pico soldered:Figure 1.12 – Pico on a breadboard
Now that we have soldered the headers, we are ready to take it for a spin. In the next section, we will review the optional step of adding a reset button to the Pico.
