Raspberry Pi 3 Cookbook for Python Programmers
Tim Cox, Dr. Steven Lawrence Fernandes
- 552 pages
- English
- ePUB (adapté aux mobiles)
- Disponible sur iOS et Android
Raspberry Pi 3 Cookbook for Python Programmers
Tim Cox, Dr. Steven Lawrence Fernandes
Ă propos de ce livre
A recipe-based guide to programming your Raspberry Pi 3 using PythonAbout This Book: âą Leverage the power of Raspberry Pi 3 using Python programmingâą Create 3D games, build neural network modules, and interface with your own circuitsâą Packed with clear, step-by-step recipes to walk you through the capabilities of Raspberry PiWho This Book Is For: This book is for anyone who wants to master the skills of Python programming using Raspberry Pi 3. Prior knowledge of Python will be an added advantage.What You Will Learn: âą Learn to set up and run Raspberry Pi 3âą Build text classifiers and perform automation using Pythonâą Predict sentiments in words and create games and graphicsâą Detect edges and contours in imagesâą Build human face detection and recognition systemâą Use Python to drive hardwareâą Sense and display real-world dataâą Build a neural network module for optical character recognitionâą Build movie recommendations systemIn Detail: Raspberry Pi 3 Cookbook for Python Programmers â Third Edition begins by guiding you through setting up Raspberry Pi 3, performing tasks using Python 3.6, and introducing the first steps to interface with electronics. As you work through each chapter, you will build your skills and apply them as you progress. You will learn how to build text classifiers, predict sentiments in words, develop applications using the popular Tkinter library, and create games by controlling graphics on your screen. You will harness the power of a built in graphics processor using Pi3D to generate your own high-quality 3D graphics and environments.You will understand how to connect Raspberry Pi's hardware pins directly to control electronics, from switching on LEDs and responding to push buttons to driving motors and servos. Get to grips with monitoring sensors to gather real-life data, using it to control other devices, and viewing the results over the internet. You will apply what you have learned by creating your own Pi-Rover or Pi-Hexipod robots. You will also learn about sentiment analysis, face recognition techniques, and building neural network modules for optical character recognition.Finally, you will learn to build movie recommendations system on Raspberry Pi 3.Style and approach: Written in a cookbook style, this book contains a series of recipes on various topics. It is an easy-to-follow step-by-step guide with examples of feature integration suitable for any search application.
Foire aux questions
Informations
Building Robots
- Building a Rover-Pi robot with forward driving motors
- Using advanced motor control
- Building a six-legged Pi-Bug robot
- Controlling servos directly with ServoBlaster
- Avoiding objects and obstacles
- Getting a sense of direction
Introduction
Building a Rover-Pi robot with forward driving motors
Getting ready
- Chassis: This example uses a modified, battery-operated push nightlight (although any suitable platform can be used). Remember that the larger and heavier your robot is, the more powerful the driving motors will need to be to move it. Alternatively, you can use one of the chassis kits listed in the There's more... section. A suitable push nightlight is shown in the following photo:
- Front skid or caster: This can be as simple as a large paper clip (76 mm/3 inches) bent into shape, or a small caster wheel. A skid works best when it is on a smooth surface, but it may get stuck on the carpet. A caster wheel works well on all surfaces, but sometimes, it can have problems turning.
- Wheels, motors, and gears: The wheel movement of the Rover-Pi robot is a combination of the motor, gears, and wheels. The gears are helpful, as they allow a fast-spinning motor to turn the wheels at a slower speed and more force (torque); this will allow for better control of our robot. A unit that combines the wheels, motors, and gears in a single unit is shown in the following photo:
- Battery/power source: The Rover-Pi robot will be powered using four AA batteries, fitted into the bay of the chassis. Alternatively, a standard battery holder can be used, or even a long wire connected to a suitable power supply. It is recommended that you power the motors from a supply independent from the Raspberry Pi. This will help to avoid a situation in which the Raspberry Pi suddenly loses power when driving the motors, which require a big jump in current to move. Alternatively, you can power the Raspberry Pi with the batteries using a 5V regulator. The following image shows a chassis with four AA batteries:
- Motor driver/controller: Motors will require a voltage and current greater than the GPIO can handle. Therefore, we will use a Darlington array module (which uses a ULN2003 chip). See the There's more... section at the end of this example for more details on how this particular module works. The following photo shows a Darlington array module:
- Small cable ties or wire ties: This will allow us to attach items, such as a motor or a controller, to the chassis. The following photo shows the use of cable ties:
- The Raspberry Pi connection: The easiest setup is to attach the control wires to the Raspberry Pi using long cables, so that you can easily control your robot directly using an attached screen and keyboard. Later, you can consider mounting the Raspberry Pi on the robot and controlling it remotely (or even autonomously, if you include sensors and intelligence to make sense of them).
How to do it...
- At the front of the chassis, you will need to mount the skid by bending the
paperclip/wire into a V shape. Attach the paperclip/wire to the front of the chassis by drilling small holes on either side, threading cable ties through the holes around the wire, and pulling tightly to secure. The fitted wire skid should look similar to the one shown in the following photo:
- Before you mount the wheels, you need to work out the approximate center of gravity of the chassis (do this with the batteries fitted in the chassis, as they will affect the balance). Get a feel of where the center is by trying to balance the unit on two fingers on either side and finding out how far forward or backward the chassis tilts. For my unit, this was about 1 cm (approximately one-third of an inch) back from the center. You should aim to place the wheel axles slightly behind this so that the rover will rest slightly forward on the skid. Mark the location of the wheels on the chassis.
- Drill three holes on each side to mount the wheels using the cable ties. If the cable ...