Reader small image

You're reading from  Raspberry Pi Pico DIY Workshop

Product typeBook
Published inMay 2022
PublisherPackt
ISBN-139781801814812
Edition1st Edition
Right arrow
Authors (2):
Sai Yamanoor
Sai Yamanoor
author image
Sai Yamanoor

Sai Yamanoor is an embedded systems engineer working for a private startup school in the San Francisco Bay Area, where he builds devices that help students achieve their full potential. He completed his undergraduate work in mechatronics engineering from Sri Krishna College of Engineering and Technology, Coimbatore, India and his graduate studies in mechanical engineering at Carnegie Mellon University, Pittsburgh PA. His interests, deeply rooted in DIY and open software and hardware cultures, include developing gadgets and apps that improve the quality of life, Internet of Things, crowdfunding, education, and new technologies. In his spare time, he plays with various devices and architectures, such as the Raspberry Pi, Arduino, Galileo, Android devices and others. Sai has earlier published a book titled Raspberry Pi Mechatronics Projects.
Read more about Sai Yamanoor

Srihari Yamanoor
Srihari Yamanoor
author image
Srihari Yamanoor

Srihari Yamanoor is a mechanical engineer, working on medical devices, sustainability, and robotics in the San Francisco Bay Area. He completed his undergraduate studies in mechanical engineering from PSG College of Technology, Coimbatore, India and graduate studies in mechanical engineering at Stanford University. He is certified in SolidWorks, simulation, sustainable design, PDM as well as in quality and reliability engineering and auditing. His has a wide range of interests, from DIY, crowdfunding, AI, travelling, photography to gardening and ecology.
Read more about Srihari Yamanoor

View More author details
Right arrow

Chapter 10: Designing TinyML Applications

In the previous chapters, our projects ranged from building a weather station to a line-following robot. In this chapter, we will discuss developing TinyML applications using the Pico. We will start by introducing TinyML and its potential uses. Then, we will discuss an example that involves image classification.

In this chapter, we will cover the following topics:

  • Introducing TinyML
  • Keyword recognition in audio samples
  • Classifying images
  • Developing edge devices

Technical requirements

The following hardware is required for this chapter:

Optional hardware

We also recommend the following optional hardware:

The code samples in this chapter can be found in this book's GitHub repository at https://github.com/PacktPublishing/Raspberry-Pi-Pico-DIY-Workshop/tree/main/chapter_10.

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

Now, let's introduce TinyML.

Introducing TinyML

What is TinyML? TinyML refers to Tiny Machine Learning and it is a nascent but growing field where machine learning (ML) tools are used on resource-constrained hardware, such as an RP2040 microcontroller, to interpret sensor data. The resource constraints refer to the limited memory and processing power available on a microcontroller compared to a server with enormous processing power and GPU. TinyML allows you to interpret data on a microcontroller powered by a coin cell. A device that can interpret sensor data using TinyML tools locally instead of having to upload the data to the cloud is called an edge device.

Let's illustrate this concept with an example. The following diagram shows the flow of data in a typical IoT application, where we have a device that is collecting data from various sensors and forwarding it to the cloud. The inference happens in the cloud and the server running in the cloud instructs the gateway to turn devices on/off:

...

Keyword recognition in audio samples

In this section, we will discuss keyword recognition in an audio sample using the Pico. This is similar to the voice assistant devices that are designed and marketed by tech giants such as Amazon Echo, Google Home, and others that respond to an activation keyword such as "Hey Alexa." We will be making use of Edge Impulse (https://edgeimpulse.com) to work on this example. Sign up for a developer account on Edge Impulse to work along with this example.

Edge Impulse

Edge Impulse is a platform that allows you to develop TinyML applications using their platform and deploy them on a microcontroller. Edge Impulse is an interactive tool that allows you to develop applications without prior knowledge of machine learning.

If you are interested in becoming a certified developer, we recommend these courses from Edge Impulse on Coursera: https://www.coursera.org/edgeimpulse.

We worked on this example while using the following tutorial...

Classifying images

In this section, we will discuss an image classification example using the Pico. We will use a binary that has been already compiled and can be downloaded to determine whether a person is present in the frame that's been captured by a camera. Let's get started:

  1. First, download the compiled binary from https://github.com/ArduCAM/RPI-Pico-Cam/blob/master/tflmicro/bin/person_detection_screen_int8.uf2.
  2. The next step is to put the Pico in bootloader mode to load the binary. We recommend checking out Chapter 1, Getting Started with the Raspberry Pi Pico, if you are not familiar with the process.
  3. Copy over the downloaded binary to the Pico.
  4. Now, we need to interface the camera module to the Pico as follows, where the left-hand side of the arrow refers to a pin on the camera module and the right-hand side of the arrow refers to a pin on the Pico:
    • CS → GP5
    • MOSI → GP3
    • MISO → GP4
    • SCK → GP2
    • GND pins tied together
    • VCC &...

Developing edge devices

There are some factors to consider before you start developing a product that makes use of TinyML, as follows:

  • The datasets that are available for developing your product. The best place to start is by making use of existing datasets or making use of data from an existing application.
  • Product development cycles involving TinyML require a lot of trial and error to refine the parameters.
  • TinyML applications are suitable for tapping new revenue streams and improving productivity.
  • You also need to account for retraining your model from time to time to account for problems identified in the system.

Now that we have discussed some of the factors to consider before developing a product, let's summarize this chapter.

Summary

In this chapter, we introduced the topic of TinyML, its applications, and getting started with TinyML development. We also discussed a keyword recognition example using Edge Impulse and discussed testing it with a Pico. We also discussed an image classification example where we used a compiled binary to detect whether a person is present in the frame. We pointed a camera at a bobblehead to demonstrate this.

Finally, we wrapped up this chapter by discussing some factors to consider while developing an edge device.

In the next chapter, we will discuss developing a product around the Pico.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Raspberry Pi Pico DIY Workshop
Published in: May 2022Publisher: PacktISBN-13: 9781801814812
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 €14.99/month. Cancel anytime

Authors (2)

author image
Sai Yamanoor

Sai Yamanoor is an embedded systems engineer working for a private startup school in the San Francisco Bay Area, where he builds devices that help students achieve their full potential. He completed his undergraduate work in mechatronics engineering from Sri Krishna College of Engineering and Technology, Coimbatore, India and his graduate studies in mechanical engineering at Carnegie Mellon University, Pittsburgh PA. His interests, deeply rooted in DIY and open software and hardware cultures, include developing gadgets and apps that improve the quality of life, Internet of Things, crowdfunding, education, and new technologies. In his spare time, he plays with various devices and architectures, such as the Raspberry Pi, Arduino, Galileo, Android devices and others. Sai has earlier published a book titled Raspberry Pi Mechatronics Projects.
Read more about Sai Yamanoor

author image
Srihari Yamanoor

Srihari Yamanoor is a mechanical engineer, working on medical devices, sustainability, and robotics in the San Francisco Bay Area. He completed his undergraduate studies in mechanical engineering from PSG College of Technology, Coimbatore, India and graduate studies in mechanical engineering at Stanford University. He is certified in SolidWorks, simulation, sustainable design, PDM as well as in quality and reliability engineering and auditing. His has a wide range of interests, from DIY, crowdfunding, AI, travelling, photography to gardening and ecology.
Read more about Srihari Yamanoor