Raspberry Pi and AVR Projects

By
Published by

As an incredibly cheap, credit-card sized computer, the Raspberry Pi is breaking down barriers by encouraging people of all ages to experiment with code and build new systems and objects; and this book provides readers with inspiring and insightful examples to explore and build upon. Written for intermediate to seasoned Raspberry Pi users, this book explores four projects from around the world, explained by their makers. These projects cover five major categories in the digital maker space: music, light, games, home automation, and the Internet of Things.


Published : Friday, November 07, 2014
Reading/s : 47
EAN13 : 9781457186226
Number of pages: 255
See more See less
Cette publication est uniquement disponible à l'achat
Make: Raspberry Pi and AVR Projects
AugmentYourPiWithAnalogICsand theChipThatPowersArduino Cefn Hoile, Clare Bowman, Sjoerd Dirk Meijer, Brian Corteil & Lauren Orsini
Hardware/Programming
Make:Raspberry Pi and AVR Projects What brings fish, music, fruit, and giraffes together? Raspberry Pi! The four projects inMake: Raspberry Pi and AVR Projectsexplore music, light, home automation, and the Internet of Things—made with a combination of the Raspberry Pi, the AVR chip that powers Arduino, and other components. Perfect for intermediate Raspberry Pi hackers, all the projects in this book are keyed to Raspberry Pi’s newest iteration: the model B+. Compiled in a very personal way by five international makers, this book takes you through the steps, concepts, and pointers you need to make your own inspired creations. If you’ve already learned the basics of the Raspberry Pi and are ready to take your knowledge to the next level, then you’re ready for the fun new challenges outlined in this book.
Using sensors, Scratch, web servers, and web services, you’ll learn to make:
»Picussion: A wearable sound sample player triggered by knock sensors »Raspberries from Scratch: Turn anything—including real raspberries—into a keyboard that controls a Scratch project »The Internet of Fish: Let your Pi text you when your fish tank or swimming pool hits a certain temperature »Giraffe Mood Lamp: This light fixture changes color based on the Twitter messages it receives
You’ve got 8-bit in my 32-bit and it tastes great!
US $24.99 CAN $26.99
ISBN: 978-1-4571-8624-0
Make: makezine.com
Make: Raspberry Pi and AVR Projects
Cefn Hoile, Clare Bowman, Sjoerd Dirk Meijer, Brian Corteil, Lauren Orsini
Make: Raspberry Pi and AVR Projects by Cefn Hoile, Clare Bowman, Sjoerd Dirk Meijer, Brian Corteil, and Lauren Orsini
Copyright © 2015 Backstop Media, LLC. All rights reserved.
Printed in the United States of America.
Published by Maker Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
Maker Media books may be purchased for educational, business, or sales promo-tional use. Online editions are also available for most titles (http://safaribookson-line.com). For more information, contact our corporate/institutional sales depart-ment: 800-998-9938 orcorporate@oreilly.com.
Editor:Patrick Di Justo Production Editor:Melanie Yarbrough Copyeditor:Charles Roumeliotis Proofreader:Kim Cofer Indexer:Angela Howard Interior Designer:David Futato Cover Designer:Brian Jepson Illustrators: Cefn Hoile, Clare Bowman, Sjoerd Dirk Meijer, Brian Corteil, and Rebecca Demarest Cover Photographer:Sjoerd Dirk Meijer
November 2014:
First Edition
Revision History for the First Edition
2014-11-04:
First Release
Seehttp://oreilly.com/catalog/errata.csp?isbn=9781457186240for release details.
Make:, Maker Shed, and Maker Faire are registered trademarks of Maker Media, Inc. The Maker Media logo is a trademark of Maker Media, Inc.Make: Raspberry Pi and AVR Projectsand related trade dress are trademarks of Maker Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and Maker Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages result-ing from the use of the information contained herein.
978-1-457-18624-0
[LSI]
Contents
Prefacevii. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.
2.
Introduction1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Power of the Pi. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Raspbian. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Who Is This Book For?2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Projects in This Book. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Picussion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Materials and Tools7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Solderless Breadboarding Materials7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Solderless Breadboard Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Soldering Materials9. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Soldering Tools9. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Configuring Your Raspberry Pi10. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 1: Blink11. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Attaching the UART. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Testing with the Blink Sketch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Troubleshooting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Exercise 2: Knock21. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Loading the Knock Sketch25. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Displaying Knock Messages in the Python Shell. . . . . . . . . . . . . . . . 26 Loading a Python Script to Display Knock! Messages28. . . . . . . . . Exercise 3: Sending Knock Messages Wirelessly29. . . . . . . . . . . . . . . . . . Using Bluetooth for Programming29. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Transmitting Wireless Messages32. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Triggering Audio33. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Troubleshooting Audio from the Pi. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
iii
3.
4.
Exercise 4: Talking Wearables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Using Python Threading for Multiple Wearables. . . . . . . . . . . . . . . . 36 Running Audio on Multiple Wearables37. . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 5: One Man Band37. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding an Accelerometer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Detecting Orientation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Adding the KnockLedControl Sketch41. . . . . . . . . . . . . . . . . . . . . . . . . . . . Processing Accelerometer Data on the Pi. . . . . . . . . . . . . . . . . . . . . . 48 Running the One Man Band. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 How the One Man Band Works54. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Proper Gestures for the One Man Band. . . . . . . . . . . . . . . . . . . . . . . . 60 Where Next?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Raspberries from Scratch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 The Conductive Keyboard70. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Materials70. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Installing Software71. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Raspberry Pi as AVR Programmer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 Building the Conductive Keyboard. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Exercise 178. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Exercise 3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 Exercise 481. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 583. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Testing the Conductive Keyboard. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 Extending the Conductive Keyboard. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Exercise 6. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 Exercise 789. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 Exercise 991. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Programming and Testing the Conductive Keyboard94. . . . . . . . . . Using the Conductive Keyboard96. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using the ShrimpKey with Scratch99. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A Scratch Primer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 Using the Conductive Keyboard in Scratch. . . . . . . . . . . . . . . . . . . . 102 Project 1: Interactive Art Project102. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using the Conductive Keyboard with the Art Project. . . . . . . . . 109 Project 2: Memory Game. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
The Internet of Fish123. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
iv Contents
5.
Materials. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 Hardware Materials. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 Software Materials. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 Before You Start128. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Setting Up SSH Communication. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 A Thermometer That Reads and Writes. . . . . . . . . . . . . . . . . . . . . . . . . . . 131 Texting with Raspberry Pi141. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Sign Up for Twilio141. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Put Raspberry Pi in the Loop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 Update temp.py143. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Building the Pi Web Server146. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Set Up Apache. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 Make a Basic Website. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148 Install MySQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 Build a Database150. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Connect the MySQL Database to temp.py. . . . . . . . . . . . . . . . . . . . 153 Connect the MySQL Database to data.php. . . . . . . . . . . . . . . . . . . . 158 Design a Graph160. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Next Steps and Acknowledgments164. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Internet-Connected Giraffe Mood Lamp167. . . . . . . . . . . . . . . . . . . . . . . . Materials and Tools168. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Hardware. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 Electronics169. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Selecting a Lamp170. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 Adding the Required Packages172. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating a Twitter Account for Your Lamp175. . . . . . . . . . . . . . . . . . . . Downloading Code for the Lamp and Configuring Twitter Access. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 Walking Through lamp.py178. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . onArg.py185. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Walking Through onArg.py. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186 Running lamp.py When the Raspberry Pi Starts188. . . . . . . . . . . . . . Building the Lamp. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188 Hacking the Lamp. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 DC-to-DC Converter. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 The RGB Matrix196. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Switch201. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Stripboard. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 The Base208. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Putting It All Together. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Contents v
A.
Where to Go from Here?213. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Appendix: The Missing Pieces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
vi Contents
Preface
All of the projects in this book use the Raspberry Pi. Read along to dis-cover how to receive Twitter alerts through a lamp, collect tempera-ture data from afishtank, control a game with Raspberries (the actual fruit!), or even learn how to make your own wearable one man band.
Book-wide bill of materials Table P-1.Book-wide bill of materials Item Item Raspberry Pi (Models B or B+) Pi Cobbler 2x ADXL 345 triple axis 2x 100 ohm resistor accelerometer breakout board (labeled GY-291) 2x piezoelectric transducer 7x 170 point mini breadboards 2x Bluetooth UART transceiver 2x 1M ohm resistor (board name JY-MCU, running HC-06firmware) 2x USB to UART serial programmer 3x 40-pin male header strip (CP2102) 2x ATmega328P-PU(flashed5mm red ultrabright LEDwith 2x Arduino Uno bootloader)
vii
Item 6x 10k ohm resistors 4x 100nF ceramic capacitor 2x 4-way female ribbon cables
Jumper wires male-male DS18B20 digital temperature sensor 3mm acrylic base plate
3mm acrylic top plate 4x PCB hex spacers 25mm
4x PCB hex spacers 10mm 2x PCB round spacers 6mm
Wireless USB adapter Darlington array ULN2803A 1x 400-point miniature breadboard Sparkfun Breadboard Power Supply 5V/3.3V part number PRT-00114 1x 4-pole screw connector block for stripboard, w/ 0.1” pitch hole spacing Stripboard prototyping PCB, w/ 0.1” pitch hole spacing 8GB SD card or 8GB SD card with NOOBS preloaded 1x ATmega328P-PU (DIP28) or ATmega8 (DIP28) 3x 100 nF/0.1 uF capacitor 16x 22 MΩor 20 MΩresistor (1/4W) 1x 2.2 kΩresistor (1/4W) 5x 330Ωresistor (1/4W)
viii Preface
Item 4x 22pF ceramic capacitor Solid core wire 2x LiPo battery and charger or 6x AAA battery pack and batteries Jumper wires male-female Push-to-make button/switch 2x 2.5mm hex bolts, length 12mm 2x 2.5mm nuts 16x 3mm hex bolts, length 6mm 4x sticky rubber feet Double-sided sticky foam tape/pads 4.7k (1/4 Watt) resistor Spotlight Kit LED RGB matrix 2mm heat shrink tube 12V DC 2A power supply to 9V DC 2A power supply Wire 22 AWG
2.1 jack socket (breadboard compatible) 2x button
1x 10 uF capacitor
2x 22 pF capacitor 2x 10 kΩresistor (1/4W) 2x 68Ωresistor (1/4W) 5x LED (5mm) (4different colors)
Be the first to leave a comment!!

12/1000 maximum characters.

Broadcast this publication

You may also like