Teaching Physical Computing with Arduino


David, Theo, Me, Josh, Kazu, Roberta & Archer

Recently, my infatuation with Raspberry Pi, Arduino, and Physical Computing coincided nicely with Safari Books Online’s dedication to ongoing education and involvement with ConnectEd. Having volunteered at Seabury Hall in Makawao, Hawaii (Maui) in the past, I was given the opportunity to submit an idea for a “Winterim” 4-day workshop on the topic of my choice. If enough students signed up, I would spend a week in Maui teaching the workshop (and have a few days on the beach, of course).

Bill is busy turning his workshop into a free Arduino Bootcamp, which will be featured here on the Flow blog. If you’d like to be notified when it starts, follow us on Twitter, Facebook, or Google+.

Realizing that Raspberry Pi may be a little too finicky for middle schoolers, I shifted my attention to Arduino. I turned to Safari Flow to learn Arduino myself, and then used it to build a syllabus that matched my own educational journey and discovery curve. After submitting my proposal to the school, I anxiously waited to hear how many students I would get. The fact that alternative workshops were on topics such as sailing, canoeing, hiking, and windsurfing didn’t help my anxiety! I was pleased when I learned that 6 students had signed up. Almost immediately, I started receiving questions from the enthusiastic students, such as “Can I bring in my box of junk electronics to make a robot?” and “Can we hack my remote control car?” Once I saw those questions, I knew we were going to have a great week.

With the books and videos that I had in Flow and a few rather large orders from Maker Media and Adafruit, I was able to gather enough course material to ensure that we eased into programming and electronics while laying a strong foundation for tinkering, setting up the students for continued learning beyond the 4-day workshop.

An overview of my workshop is below, and in the near future I’m planning to share specific chapters and videos that were useful to me. I’m hoping that our story and pictures below will inspire you to use the material to support students of your own.

Day 1: Basic Circuits and Blinking LEDs

Kazu sets up

Kazu had the most complex breadboards, but somehow always knew exactly which wire went where, and what it did!

On the morning of the first day, we built some basic circuits without a microcontroller to get a feel for prototyping circuits using tactile buttons, potentiometers, force sensitive resistors, and ambient light sensors. In the afternoon we went over to the lab to demonstrate how a microcontroller can do many things with the same basic circuits, using code to modify blink patterns, blink durations, and multiple LEDs. After some more light coding, we were able to play a melody using a piezo-buzzer via pulse-width modulation.

Day 2: More Inputs and Outputs


Josh prepares to upload a sketch

On day two, we used a third-party library and switch statements to decode signals via an infrared receiver, which listened for commands from universal remotes to control various outputs. We were able to switch on LEDs, control servos, and change colors of an RGB LED. We learned to read and sketch schematics and dug into basic programming concepts like switch and if/else statements and for loops. We also got a lot of practice mashing up code samples from books with our own code and modifying them to achieve our desired functionality.

Day 3: Field Trip

Drones in the courtyard

Drones in the courtyard

Unfortunately, I don’t have pictures from the field trip (the exact location is “classified,” sort of), but we saw a web-controllable telescope, which was part of the DoD telescope array for tracking US and foreign satellites. We also got to check out the Boeing electrical systems integration room, where there were “real live” electrical engineers designing and soldering circuits to create custom, rack-mounted motor controllers for various telescopes. In the afternoon, we built “brush bots” from a toothbrush, vibration motor, coin-cell batteries, and LEDs. We then let the bots fight it out. We also took turns flying a Parrot AR drone!

Day 4: Show and Tell

Archer demonstrates arming and disarming his intruder alarm with a universal remote

Archer demonstrates arming and disarming his intruder alarm with a universal remote

On the final day, each student combined what he or she had learned to build a personal project. Here are some examples of what they came up with. It was amazing to see what they were able to design in a 5-hour day after only 2.5 days of instruction:
  • A temperature probe that turns on an LED when the temperature exceeds 23° Celsius
  • A game that challenges you to press a button as many times as you can (counted on a 7-segment display) until your toast pops up, as detected by a PIR motion sensor
  • A fortune-telling “magic” 8-ball: Ask it a question and push a button on the remote, which triggers a servo pointer to randomly move back and forth before stopping at a response on the dial
  • A motion-activated intruder alarm that can be armed/disarmed via remote control
  • A motion-activated intruder alarm that plays a threatening melody with a buzzer when motion is detected

Special Thanks to Jaqueline Peterka and Roberta Hodara at Seabury Hall in Makawao, Hawaii, for making this happen!

Why So Many Searches for “2600″? (Hint: It’s performance evaluation season)

Our recent site analytics reveal that Flow users have been searching for the phrase “2600.” In the past month, we’ve had over 70 unique searches for variations of the term. At first, none of us around the office knew what “2600” meant…. Are Flow users looking for information on the long-running hacker quarterly? Or searching for books and videos on the beloved video game console?

Neither of those, it turns out. In fact, they’re looking for help on everyone’s favorite annual ritual: performance evaluations. Specifically, they’re searching for a book in Flow titled 2600 Phrases for Effective Performance Reviews, which is exactly what you think it is—copypasta for evaluations.

Whether for your boss, your employees, or (perhaps worst of all) yourself, this is the time of year when you’re likely to be writing a professional evaluation of some kind. If you’re like us, you could probably use some help. We’ve put together a list of 5 bits of advice so that we can all stop stressing about it.

image of book coverCommunication and Cooperation from
2600 Phrases for Effective Performance Reviews by Paul Falcone

As you’d expect, this chapter suggests phases related to communications skills, for example: “cultivates a culture of openness in information sharing.” Even if you don’t care for the exact phrases, they can help you generate ideas. It’s easy to imagine how a single phrase can generate a more substantial paragraph about, say, how you or your employee needs to improve on communication across departments in order to achieve certain OKRs (see next suggestion).

image of book coverFocusing on Key Performance Indicators from
Advanced Web Metrics with Google Analytics by Brian Clifton

Setting goals for the upcoming year is one of the challenges of writing evaluations. You usually want to set goals that are measurable and realistic, but also challenging. If you use a tool such as Google Analytics to track and help analyze data about your sites and products, you probably have a few key metrics that you care most about. This chapter describes how to align those key performance indicators (KPIs) with the objectives and key results (OKRs) of your organization, which can help you create your goals for 2014.

image of book coverPerformance Reviews from
Perfect Phrases for Coaching Employee Performance by Laura Poole

Once you write your appraisals, you have to deliver the results. Many managers have a hard time with this part of the process, especially if they have to deliver negative reviews. This chapter on performance reviews takes you step by step through the best things to say to your employee. Sections such as “Giving and Receiving Feedback,” “Acknowledging Good Work,” and “Learning from Challenges” include questions that you can use as a guide (or use word for word, if you’re really stuck). More generally, this book dives into the psychology of appraisals, which can be surprisingly helpful.

image of book cover
Feedback from
Coaching for Performance by John Whitmore

We wish we had read this succinct, practical, smart section years ago. The advice found here is useful for anyone who finds herself needing to evaluate and help improve another’s actions and motivations, be it a manager or an employee who is looking to “manage up.” The section starts by identifying ways in which feedback is typically delivered and how those methods fall short, before arguing for a superior approach. From there, the section describes how this approach works well regardless of the format of the evaluation. A subsequent section on self-assessment is equally useful.

image of book coverDevelop your CV writing skills from
The One Page CV by Paul Hichens

While writing a performance evaluation, you may find yourself evaluating your career more generally. Maybe it’s time to make a change? Writing a resume might be the only thing worse than writing a performance evaluation, and this chapter provides examples to make it easier. Even if you’re not interested in updating your resume, the chapter includes tutorials for how to improve your writing more generally. We especially like the tips on how to write concisely.

Do you have a favorite resource for writing performance evaluations? Let us know in the comments or on Twitter.

Safari + ConnectED = Awesome

Here at Safari, we’ve been incredibly excited all week by our involvement in President Obama’s ConnectED initiative.

The best part of the ConnectED announcement, to me, is how this initiative lays a foundation for the kinds of resources my daughter will have available to her when she starts going to school some years from now. Who knows what the landscape will look like then, but ConnectED is an important step, for all organizations involved. As a parent, of course I want to give my daughter the opportunity to grow into a more intelligent, more capable human being than I am, and I take great pride in being part of an organization that believes in these same ideas. By bringing together our respective talents, we can change the way our kids (and millions of others!) learn and become more awesome.

At O’Reilly Media and Safari, working on things that matter is part of our company DNA. We strive to have a lasting impact beyond just improving the financial bottom line. I think our participation in the ConnectED initiative goes a long way toward achieving that goal.

Here’s to a bright future.

New Books and Videos on Flow

In reviewing customer feedback, we’ve come to appreciate just how important it is that Flow offers a large, diverse, and growing selection of books and videos. We’re glad to receive that feedback because we built Flow to recommend an unending and evolving stream of content on our favorite topics. At Safari, we’re lucky enough to partner with some of the best publishers in the world, and in 2014, we’ll be adding more content more often so that the “flow” never stops.

Over the past week, we’ve added over three thousand new books and videos to Flow, many of them published in 2013 and early 2014. This latest batch of books and videos includes the kind of technical content you’ve come to expect from Safari. Read and watch on topics such as programming (including Java, C++, .NET, and Python), data science, DevOps, system administration, networking, Linuxmobileweb development and operationsinformation architecture, and sales development.

In addition to books and videos on technical topics, we’ve added over six hundred business-related titles, on topics such as startups and entrepreneurship, strategy for growth, web analytics, time management, distribution management, customer development, and sales and marketing to name just a few.

These new titles are just the beginning. We’ll be adding new books and videos on an ongoing basis. And in the coming weeks, we’ll be adding to Flow new and better ways to sort books and videos so that you can find the newest stuff easier. As always, we’d love to hear your opinion, so send your feature or content requests our way via email or Twitter.

Building Vagrant VMs with the VMWare Fusion provider

In order to streamline Chef cookbook development and give everyone in IT a dev node where they could make and test infrastructure changes locally, we decided to build a Vagrant box to distribute internally. Having built many Vagrant boxes in recent months, I set out in earnest and configured the Virtual Machine just how I wanted it. When I went to `vagrant package`, however, I discovered the vmware_fusion provider does not support this action and that this box would have to be packaged manually.

I read through the official Vagrant docs, and I packaged up the VM, only to discover–when it was just a bit too late–that I had packaged up the wrong virtual disk and didn’t save any of my changes. Since I hadn’t seen this clearly documented anywhere else, I wanted to share the key finding I had overlooked the first time through.

When working on a Mac, at least, you will find VMWare virtual disk files in a boxes dir in ~/vagrantd/ as well as inside a similarly named directory in ~/.vagrant.d/. However, those are not the vmdk, vmxf, and metadata.json files that you need to archive to make your running VM into a Vagrant box. As it happens, the section of the Vagrant vmware_fusion provider docs that mention a `vm.vmwarevm` directory weren’t erroneous after all–it just wasn’t totally clear that they were pointing to a subdirectory of the .vagrant/ directory that lives in the directory with your Vagrantfile–the directory from which you ran vagrant up.

Having worked with the Virtualbox provider pretty extensively, I did not expect this pattern and wanted to share this experience since I hadn’t seen it clearly documented elsewhere online. Whereas Virtualbox puts VM disk files inside ~/VirtualBox VMs, when using the vmware_fusion provider with Vagrant, the virtual disks are stored in ~/running_vagrant_dir/.vagrant/machines/default/vmware_fusion/vm.vmwarevm. Now you know and can build VMWare Fusion-based Vagrant VMs following the instructions provided in the official Vagrant vmware_fusion provider docs.

Practical Philosophy in Chef Land

The difficulty in surfing is a function of having to move while balancing on a board that is also moving on an unpredictable surface. By contrast, skateboarders and snowboarders move on surfaces that are fixed, or at least predictable. The surfer has neither guarantee and must deal with conditions as they arise. It is with this in mind that I have approached our Chef-oriented continuous integration environment at Safari Books Online. As infrastructure testing tools emerge and test-driven development practices are applied more comprehensively to systems engineering, the most practical way to leverage these useful testing strategies and technologies is to accept that you are moving on a moving platform and that you will get more out of it if you learn it and love it.

Change is constant and inevitable. You must have strategies to deal with changes, or you will find yourself beset by what seem like inexplicable and inescapable regression bugs on workstations that worked just fine yesterday. Originally, this blog post was going to be a very quick and direct step-by-step tutorial describing how to get up and running with a test-kitchen workstation with chef-zero and Berkshelf, but between the time I originally documented the process and started writing the blog post, gems and cookbooks changed, resulting in bugs for my specific configuration.

Through some searches of Opscode forums and Github issues, I was able to find where the bugs were and how to pin the cookbook revisions in the Berksfile and the versions in the Gemfile in order to get new nodes up and running–but it doesn’t make for a very pretty (or reliable) tutorial. And so it seems worthwhile to share my experiences and point out that by loading community cookbooks from remote repositories, and by using particular test suites, you will likely encounter bugs, some of which may already have known solutions. The platform is moving, and accepting the inevitability of regressions is a step towards peace of mind.

Sometimes, though, you will find yourself with an error that appears to be otherwise unreported. Recently, we encountered this sort of scenario a few times and each time, I cautiously troubleshot the errors and tried different gem or cookbook versions, seeing if I could resolve it through version mix-and-match. If not, I reported the bugs via Github issues, and time after time, the developers of these tools quickly respond and graciously patch reported bugs, allowing us to remove version pinning in our Berksfile or Gemfile within days. While the platform is itself moving on a fluid surface, it’s refreshing to know that we can respond to it and help shape our course by providing feedback to the developers of the tools, providing greater future stability for ourselves and others.

Once you get the hang of working with the tools in the Chef ecosystem, you’ll develop a greater awareness of what’s breaking and why, and if you build a continuous integration system through which to deploy changes, as we have been doing and continue to do, you will be able to keep your test-kitchen workstation running longer without interruption and will be to recover more quickly when it gets gnarly.

Can Minecraft teach kids how to code?

In August, I attended O’Reilly’s FOO Camp, a conference like no other, located on our shared campus in Northern California.

One of the things that makes FOO so interesting is that there’s no explicit theme, agenda, or schedule – people are simply provided with the infrastructure and impetus to meet other interesting people and talk. One outcome is that given the opportunity to speak freely, people very rarely talk about their jobs or their work (although that may come into it); what they are really excited to talk about is their passion. 

I got talking with one interesting looking attendee after a session where the computer game Minecraft came up in conversation. The session took place just before a break, he was saying some interesting things, and I wanted to follow up.

At the time my 7 year-old son had just begun obsessing over Minecraft (see the daily sales stats to see that he’s far from alone). I didn’t know much about it as a parent other than it took all of his attention; that I had heard good things about it; and that if it’s a computer game, then it must be bad for him – worse than, say, homework and vegetables.

In the space of about 45 seconds this guy basically set me straight – that Minecraft was awesome; that it could teach my son incredible things (including some of the foundations for coding); and leaving me with the impression that if I in any way restricted my son’s access to the game I would be derelict as a parent. (See also the NYT on the same subject.)

Last month I signed up for the Hour of Code with my son, and we both had a blast. Remembering my conversation in the summer, and seeing my son’s ongoing fascination with Minecraft, I wanted to point you to some great new books about Minecraft in Flow.

This holiday, we all read The Minecraft Guide for Parents

“One of the ways teachers frequently use Minecraft is in demonstrating geometry concepts. For instance, the blocks can be placed to create various forms, and they can be filled with water to demonstrate volume. But Minecraft can also be used to teach basic numeracy skills. Crafting items can help with simple problem-solving and equations, and at the very least, kids will quickly pick up on their times tables for the number eight, because objects are typically stacked in groups of eight” The Minecraft Guide for Parents

and we did a little haggling over the parent / child contract.

I also spent some time with The Ultimate Player’s Guide to Minecraft, short-circuiting some of the learning time. We haven’t yet got onto Building Minecraft Server Modifications or even creating our own Raspberry Pi Minecraft Server, but I have learned more about Redstone Circuits and Mods.

I’m increasingly excited by how I can help direct my son’s enthusiasm for Minecraft into some related areas. We’ve already begun some basic electronics with a Bleep Labs Drum Machine that was a gift this Christmas, and we have some tips for next steps from the hour of code from a co-worker. We’re thinking about how some of the content in Safari Flow can be helpful for parents as well as professionals, and welcome any ideas, requests or experiences in the comments.

The Minecraft Guide For Parents

Building Minecraft Server Modifications

The Ultimate Player’s Guide to Minecraft

Scala Macros that won’t kill you

One of the many things that bothers me about Java is the lack of compile-time checking.  I don’t want to have to run my program to know if the URL is well-formed, if a file exists, or if an email is valid.

Scala offers a solution.  Scala macros allow essentially arbitrary computations to run at compile time.  Let’s walk through the simple email example:

Getting started

First let’s define a simple email class with the to string we are all expecting:

case class Email(val local: String, val domain: String) extends NotNull {
override def toString() = local + "@" + domain

case classes” are one of the best features of Scala.  They define immutable final classes with predictable default implementations for equality, hash values, and to string.  They also have pattern-matching support.

We can construct an Email like:

val email = Email("someone", "hotmail.com")

Adding readability

Scala also offers string interpolation so we can make these statements more readable:

val email = email"someone@hotmail.com"

Where at runtime Scala will essentially call an email function with the string.


We just need a little Scala magic for that to happen:

implicit class EmailHelper(val sc: StringContext) extends AnyVal {
def email(args: Any*) =  Email(args(0).before(“@”),args(0).after(“@”))

Now the magic happens

Now this may seem like adding a lot of complexity for a small improvement in readability.  The real win comes from adding compile time-validation.

First we need to add some more magic with the macro keyword:

implicit class EmailHelper(val sc: StringContext) extends AnyVal {
def email(args: Any*): Email = macro EmailHelperimpl

and then define the function that will be called at compile time

def EmailHelperimpl(c: Context)(args: c.Expr[Any]*): c.Expr[Email] = {
import c.universe._

args will be a sequence of abstract syntax trees.  Scala macros work on the level of the AST so it is effectively impossible to produce a syntax error (unlike C/C++ macros).  c.Expr[Email] says that we will return an abstract syntax tree with type Email:

c.prefix.tree match {
  // access data of string interpolation
  case Apply(_, List(Apply(_, rawParts))) =>
  case _ =>
  c.abort(c.enclosingPosition, "invalid")  // TODO: change this to a sensible default

We can pattern match on the AST with Apply(_, List(Apply(_, rawParts))), where the underscores act as wildcards.  We only care about the first specific case.  If somehow things are different, we register an error with the compiler.

You can register errors with c.abort and warnings with c.warning.

When we have what we want, we can build the String AST fragment into a list of strings and their positions:

val parts = rawParts map { case t @ Literal(Constant(const: String)) => (const, t.pos)

This step is necessary because there are some more complicated string interpolation use cases.  For now we only care when we have have the case of one string.

parts match {
  case List((raw, pos)) => {

  case _ =>
    c.abort(c.enclosingPosition, "invalid")

I hid the email validation logic in EmailParser (the details aren’t that interesting):

Email.EmailParser.parse(raw) match {
  case Errors(errors) => {
    for (error <- errors) {
      c.error(pos, error.msg)
    reify { Email("", "") } // not valid
  case Result(Email(local, domain), warnings) => {
    for (warning <- warnings) {
      c.warning(pos, warning.msg)
    reify {
        (c.Expr[String] { Literal(Constant(local)) }.splice),
        ((c.Expr[String] { Literal(Constant(domain)) }.splice)))

reify is a magic function that constructs an AST for literal Scala code.  And that’s it!

Getting the code and examples

Because of the quality of the Scala IDE, it is possible to develop this in real time.  You don’t even need to trigger a compile.

There are many cases where Java and other languages use strings as a proxy for distinctly non-string data (regular expressions are an obvious example).  So I built up some more validators for common Java types.

These examples and others are available in my source code.

Intro to Python Bootcamp – Session 5

Welcome to session 5 of our Introductory Python “Bootcamp,” our week-long blog series that explores the key concepts behind this popular and flexible programming language.

New to the bootcamp? Start with Session 1.

Open a Safari Flow trial account to access the Bootcamp books and videos.

Bootcamp header- Intro to Python Day 5

Welcome to the home stretch!

Over the past four sessions, you have learned the fundamental building blocks of Python. In Session five, you will synthesize what you have learned in order to solve different real-world problems. We will introduce ways of working with databases and effective debugging, and focus on exercises that apply all of the concepts taught in sessions 1-4.

Putting it all together

Start with these short videos.

From Python Guide for the Total Beginner LiveLessons

From Quickstart Python

Test your mettle

Now try your hand at these capstone exercises from Learn Python the Hard Way.

Screen Shot 2013-12-11 at 10.17.53 PM

Congrats! You have successfully completed the Safari Flow Introductory Python Bootcamp! Job well done!

We want to hear from you!

We’d love to hear your feedback about this bootcamp or other topics you’d like to learn. Tell us what you think in the comments below.