
It’s been too long since I messed with the Raspberry Pi. It started with Hacktoberfest a few months ago, then we had a baby, and then I got it in my head to write a Chrome extension and… life happened.
So I picked up a copy of Raspberry Pi Cookbook by Simon Monk to jump-start things again. I assumed it’d have “recipes” for some cool projects, but it ended up being much more comprehensive. It takes you from the very basics of unpacking your Pi and setting it up, to installing Raspbian and creating your first Python script, to integrating with other hardware… even the Arduino.
It’s a reference book more than anything else, full of useful advice from someone who I figure must’ve spent a fair amount of time messing around with the Pi before writing the book. It gets you started, goes into some detail, and often includes references for more information.
First, a brief break down of what’s in the book…
Chapters 1 – 4 is basic hardware and software issues, like connecting peripherals and installing Raspbian. If you’ve just unpacked your first Pi, this’ll get you going.
Chapters 5 – 7 describe the Python language. If you’re brand new to it (most of your programming on the Pi will be in Python), start at the beginning. Otherwise, skim 6 and check out 7 for more advanced topics.
Chapter 8 talks about capturing images *and image processing* on the Pi. More on that below.
Chapters 9 – 14 covers a lot of different hardware (200 pages), starting with GPIO pins, breadboards and HATs, then covering LEDs, buzzers and relays, motors and robots, and various sensors and other modules. I would’ve liked a little more detail on some topics, like relays and the different uses for resistors, but the book leans towards breadth not depth.
Chapter 15 gets into the wonderful (sometimes misguided) world of IOT. There’s a lot of cool potential here, but when you come up with The Next Big Thing make sure you don’t end up on here. 😏
Chapter 16 discusses possibilities for interfacing with an Arduino using Firmata and pyFirmata, or using Arduino components (like LCD displays) via the AlaMode interface board. Good stuff.
A couple Python take-aways:
A call to
random.choice(your_array)
will select a random item from an array.The pickle module lets you save a data structure to a file and reload it later – very convenient!
import pickle
# Save a dictionary into a pickle file.
pickle.dump({"lion":"yellow", "kitty":"red"}, open("save.p", "wb")
# Load the dictionary back from the pickle file.
favorite_color = pickle.load(open("save.p", "rb"))
### = {"lion":"yellow", "kitty":"red"}
- There’s a couple pages on threads. I used threads when I was first experimenting with pulse-width modulation, and again later to create a flickering candle using an RGB LED. If you want to do more than one thing at a time, or just one intense thing without locking up your application, this is worth a read.
Other important take-aways:
- There are some excellent “rules of thumb” for using the GPIO pins, which I’ll paraphrase here. - Do not put more than 3.3 V on any GPIO pin used as input.
- Do not draw more than 16mA per pin set to output.
- Do not draw more than 50mA total for all pins on older 26-pin Pi, or more than 100mA total on newer 40-pin Pi.
- Do not power the Pi with more than 5V.
- Do not draw more than 250mA from 5V supply pins.
- In other words, the GPIO pins will light an LED but larger devices should use an external power source.
- Care must be taken when tying a device that outputs over 3.3v, such as an Arduino that outputs 5v, to the Raspberry Pi. To safely connect the two devices requires a converter, like this logic level converter from SparkFun, or a HAT that has it built in like the author’s own RasPi Robot Board that allows for running two motors off a battery pack.
- Pi HATs should (but some don’t) contain an EEPROM chip, which Raspbian will use at some point in the future to auto-configure itself when a HAT is connected (such as downloading required software).
My original idea was to get a few ideas from the book for projects I’d like to try out, or at least some concepts to demonstrate, and here’s what I came up with:
- Process images using SimpleCV and Haar cascade files to detect features.
- Extract text from an image using tesseract OCR.
- Turn the Raspberry Pi into an FM transmitter!
- Setup a Python web server with Bottle. It seems light-weight like Sinatra… maybe I’ll write up a comparison at some point.
- Use the MCPI API to control the Pi edition of Minecraft that comes with Raspbian.
- Experiment with the serial port (Rx and Tx pins) using PySerial. Not many details in the book, but maybe PySerial has good docs.
- Create a GUI using TKinter.
- [Done] Demonstrate the use of charlieplexing for lighting multiple LEDs with as few connections as possible. With this design, n pins can handle n2 – n LEDs, so 4 GPIO pins can support 12 LEDs… and 10 pins can support 90!
- Track conditions in the indoor garden (grow-light box) I’m planning to make with the kids, by using a DS18b20 temperature sensor or a Sense HAT.
- Create a fruit keyboard using the Capacitive Touch HAT or Explorer HAT Pro. 🍎🍐🍊🍋
Final thoughts:
Raspberry Pi Cookbook is a reference book more than anything else. It gets you started, describes some of the detail, and often includes references for more reading. The layout lets you quickly scan the table of contents for the material you’re interested in and just skip to that section.
The author must’ve spent a fair amount of time messing around with the Pi before writing the book. His advice is solid, and he seems to have a good grasp on everything he covers. He uploaded his code samples to GitHub too, which is a nice bonus, although they’ll probably make more sense in the context of the book.
My recommendation? Grab a copy and keep it nearby for quick reference!
Have you read it? What’d you think.. good, bad.. like it, not like it? Did you get something out of it that I didn’t mention?
Share your thoughts below!
(The link above is an aff link, but I wouldn't post it if I wouldn't recommend it to a friend!)