Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Robotics at Home with Raspberry Pi Pico

You're reading from   Robotics at Home with Raspberry Pi Pico Build autonomous robots with the versatile low-cost Raspberry Pi Pico controller and Python

Arrow left icon
Product type Paperback
Published in Mar 2023
Publisher Packt
ISBN-13 9781803246079
Length 400 pages
Edition 1st Edition
Languages
Concepts
Arrow right icon
Author (1):
Arrow left icon
Danny Staple Danny Staple
Author Profile Icon Danny Staple
Danny Staple
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

Preface 1. Part 1: The Basics – Preparing for Robotics with Raspberry Pi Pico
2. Chapter 1: Planning a Robot with Raspberry Pi Pico FREE CHAPTER 3. Chapter 2: Preparing Raspberry Pi Pico 4. Chapter 3: Designing a Robot Chassis in FreeCAD 5. Chapter 4: Building a Robot around Pico 6. Chapter 5: Driving Motors with Raspberry Pi Pico 7. Part 2: Interfacing Raspberry Pi Pico with Simple Sensors and Outputs
8. Chapter 6: Measuring Movement with Encoders on Raspberry Pi Pico 9. Chapter 7: Planning and Shopping for More Devices 10. Chapter 8: Sensing Distances to Detect Objects with Pico 11. Chapter 9: Teleoperating a Raspberry Pi Pico Robot with Bluetooth LE 12. Part 3: Adding More Robotic Behaviors to Raspberry Pi Pico
13. Chapter 10: Using the PID Algorithm to Follow Walls 14. Chapter 11: Controlling Motion with Encoders on Raspberry Pi Pico 15. Chapter 12: Detecting Orientation with an IMU on Raspberry Pi Pico 16. Chapter 13: Determining Position Using Monte Carlo Localization 17. Chapter 14: Continuing Your Journey – Your Next Robot 18. Index 19. Other Books You May Enjoy

Wiring in encoders on a Raspberry Pi Pico robot

Our robot has already got encoders on board, and we have already wired them in. We can take a closer look at the motors and how they are wired into Raspberry Pi Pico GPIO pins to understand the robot better.

Examining the motors

We use N20 geared motors with encoders. The following diagram labels the motor parts:

Figure 6.3 – The N20 motor parts

Figure 6.3 – The N20 motor parts

Figure 6.3 shows a drawing of the motors we have used. Marked on it are essential features that affect how we use the encoders. On the left is a magnetic disk with markers in it. This disk is attached to the motor’s driveshaft and sensed by the encoder sensor board. On the right are the gearbox and the motor output shaft.

The driveshaft goes through the gearbox, so the output shaft will not make the same number of rotations as the disk – the gear ratio will determine this relationship. So one revolution of the output wheel could count many pulses; this gives us high resolution.

Consult the datasheet for the motors. Some Chinese characters are likely, but important numbers are usually in English. You may need translation services built into web search engines here. The datasheet and product page have two important numbers, the number of encoder counts per disk revolution and the gear ratio. The datasheet may note counts per disk revolution as pole count.

In my case, the gear ratio is 298:1, and the pole count is 14. Interpreting these facts means I get 298 turns of my encoder wheel per output wheel revolution. Each encoder turn produces 14 poles on each sensor (two sensors), so we get 28 edges. Multiplying the number of sensor pulses by the gear ratio gives 8344 edges per turn.

Examining the wiring

We saw the wiring for our robot in Figure 4.20 of Chapter 4, Building a Robot around Pico. However, to better illustrate the encoder connections, here is a diagram focusing only on the wiring of encoders to Pico:

Figure 6.4 – Encoders wired to Raspberry Pi Pico

Figure 6.4 – Encoders wired to Raspberry Pi Pico

The preceding figure takes a closer look at data connections for a robot encoder connection schematic. On the left is Raspberry Pi Pico; this has four connections from the encoders. These are on GPIO 20, 21, 26, and 27. Each of these can be set as input pins to read the state of the encoder pins.

If we were just reading encoders alone, we could write code to check each pin in sequence. However, doing this may tie things up. What if we could get components of the Pico to monitor these pins and pulse chains for us so that we could just read a counter for them when we need it?

lock icon The rest of the chapter is locked
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.
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 $19.99/month. Cancel anytime
Banner background image