Raspberry Pi Pico DIY Workshop - Sai Yamanoor - E-Book

Raspberry Pi Pico DIY Workshop E-Book

Sai Yamanoor

0,0
37,19 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

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:

EPUB
MOBI

Seitenzahl: 265

Veröffentlichungsjahr: 2022

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Raspberry Pi Pico DIY Workshop

Build exciting projects in home automation, personal health, gardening, and citizen science

Sai Yamanoor

Srihari Yamanoor

BIRMINGHAM—MUMBAI

Raspberry Pi Pico DIY Workshop

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

Contributors

About the authors

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.

About the reviewers

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.

Table of Contents

Preface

Section 1: An Introduction to the Pico

Chapter 1: Getting Started with the Raspberry Pi Pico

Technical requirements

Introducing the Raspberry Pi Pico and RP2040

RP2040 microcontroller

Discussing variants of the Pico board

Where to buy the Pico

Soldering the Pico's headers

Soldering the headers

Implementing the "Hello World!" example

MicroPython

Implementing the LED-blinking example

Description of the code sample

CircuitPython example

Launching Mu

Second LED-blinking example

CircuitPython or MicroPython?

Identifying useful add-on hardware for the Pico

Pico Breadboard Kit (USD 19.31)

Pico GPIO Expansion Board (USD 10.34)

Pico HAT Expansion (USD 13.79)

Grove Shield for Pi Pico (USD 3.90)

Pimoroni Pico Decker (Quad Expander) (USD 16.55)

Summary

Chapter 2: Serial Interfaces and Applications

Technical requirements

Installing requisite libraries

HTU21D-F temperature sensor

DHT20 temperature and humidity sensor

OLED display (driven by SSD1306)

Wireless pack

Using the UART interface to communicate between two Pico boards

The UART interface

Setting up the Pico

Programming the Pico boards

Testing the code

Applications of the UART interface

Interfacing sensors using the I2C interface

Introduction to the I2C interface

Pull-up resistors

Testing the HTU21D-F temperature sensor

HTU21D-F temperature sensor code

Testing the DHT20 temperature sensor

AHT20 temperature sensor code

The Feather RP2040 board

Troubleshooting

Displaying temperature data using the SPI

The Serial Peripheral Interface (SPI)

Wiring up the display

Displaying the temperature and humidity data

The LILYGO RP2040 board

Setting up the wireless pack

Summary

Chapter 3: Home Automation Projects

Technical requirements

Installing the requisite libraries

NeoPixel

Wireless pack

Interfacing sensors

Controlling appliances

Publishing sensor events to the cloud

Setting up Adafruit IO

Publishing events

Controlling LED strips

Introducing the RP2040 Connect

Installing CircuitPython on the RP2040 Connect

Connecting the RP2040 to the internet

Summary

Chapter 4: Fun with Gardening!

Technical requirements

Why gardening?

Installing the requisite libraries

Soil sensor

Wireless pack

NeoPixel

Setting up the soil sensor

Setting up the wireless pack

Setting up the NeoPixel LED

Publishing data to ThingSpeak

Putting it all together

Summary

Section 2: Learning by Making

Chapter 5: Building a Weather Station

Technical requirements

Conducting citizen science experiments

Installing the requisite libraries

The AM2315 sensor

BME280 sensor

VEML6075 UV light sensor

Testing the sensors

Testing the BME280 sensor

Testing the AM2315 temperature/humidity sensor

Testing the VEML6075 sensor

Testing the weather meter sensors

Testing the wireless pack

Assembling and testing the weather station

Next steps

Summary

Chapter 6: Designing a Giant Seven-Segment Display

Technical requirements

Inspiration for the project

Potential use cases

Installing the required libraries

Wireless pack

Selecting a seven-segment display

Wiring up the giant seven-segment display

Writing the drivers for the giant seven-segment display

Using the display

Simple web server

Serial port example

Tracking physical activity

Putting it all together

Summary

Chapter 7: Designing a Visual Aid for Tracking Air Quality

Technical requirements

Inspiration for the project

Installing requisite libraries

Stepper motor

Wireless pack

SCD30 CO2 sensor

Using public data sources for air quality data

Running the query on a Pico

Interfacing a CO2 sensor with the Pico

Interfacing the stepper motor

Building the display

Making an interactive display

Summary

Section 3: Advanced Topics

Chapter 8: Building Wireless Nodes

Technical requirements

Installing requisite libraries

Adafruit Bluefruit LE SPI Friend

Optional – the LoRa module

Optional – the CO2 sensor

Interfacing a Bluetooth Low Energy module

Publishing sensor data via the Bluetooth module

Interfacing a Sigfox module

What is Sigfox?

Sigfox module

Setting up the Sigfox module

Interfacing a LoRa module

What is LoRa?

Considering an example scenario

Summary

Chapter 9: Let's Build a Robot!

Technical requirements

Installing the prerequisites

Installing the batteries

Controlling the LEDs

Motor selection and control

DC motors

Stepper motors

Servo motors

DC motor control

Servo motor control

Testing the sensors

Ultrasonic sensor

Line-following sensor

Testing the robot

Robotics contests

Summary

Chapter 10: Designing TinyML Applications

Technical requirements

Optional hardware

Introducing TinyML

Introducing the Pico4ML

Keyword recognition in audio samples

Edge Impulse

Classifying images

Developing edge devices

Summary

Chapter 11: Let's Build a Product!

Technical requirements

Understanding the Pico phone

Capturing the requirements

Selecting components

Building a proof-of-concept

Installing the requisite libraries

Testing the Notecard

Testing the keypad

Designing a PCB

Schematic capture

PCB layout

Enclosure selection

Gerber file generation

Board fabrication

Assembling the PCB

Bringing up the board

Final assembly and testing

Taking the project forward

Replacing the Pico

Pimoroni PGA2040 – USD 9.05

RP2040 Stamp – USD 14.55

Summary

Chapter 12: Best Practices for Working with the Pico

Technical requirements

Upgrading your Pico's firmware

Programming the Pico using the Arduino IDE

Downloading and installing the Arduino IDE

Installing a board package for the Pico

Programming in C/C++ using the Pico SDK

Debuggers for the Raspberry Pi Pico

Tools to aid with prototyping and product development

Breadboard with Pico's pinout labels

Power profiling your application

Nordic Power Profiler Kit – USD 81.25

Joulescope – USD 999

Programming the PIOs

Summary

Why subscribe?

Other Books You May Enjoy

Section 1: An Introduction to the Pico

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!

Chapter 1: Getting Started with the Raspberry Pi Pico

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 Pico

Technical requirements

The 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 kit

Code in Action videos for this chapter can be viewed at https://bit.ly/3MRdYjx.

Introducing the Raspberry Pi Pico and RP2040

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.

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.

Discussing variants of the Pico board

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.

Where to buy the Pico

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.

Soldering the Pico's headers

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.

Soldering the headers

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.