Cooking with Simon Monk - Raspberry Pi Cookbook

Full article

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: 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: 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: Capturing images and image processing on the Pi. More on that below.

Chapters 9-14: 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: The amazing (frequently 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: 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"}

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:

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!)


Grant Winney

I write when I've got something to share - a personal project, a solution to a difficult problem, or just an idea. We learn by doing and sharing. We've all got something to contribute.

Comments / Reactions