The Raspberry Pi 3, Model B is a successor to the Raspberry Pi 2, Model B, part of the exceptionally-popular Raspberry Pi lineup of tiny computers. Pis are just that: computers. And they are the all-time best-selling personal computer in the UK—over 8 million have been sold.

Raspberry Pi 3, Model B

Above: Raspberry Pi 3, Model B

SparkFun Raspberry Pi 3 Starter Kit

Above: SparkFun’s Raspberry Pi 3 Starter Kit

How it Works

It’s a computer, so you can do what you want with it, assuming what you want to do can run on the type of ARM processors used in the Pis’ Broadcom SOCs (System on a Chip). Pi-using folks commonly run raspbian, the Debian-based Linux OS recommended and supported by the Raspberry Pi Foundation.

What’s Different About it

Many single-board computers (SBCs) run simplified OSes and have limited interfaces for getting into them and seeing what’s up. Even those that do have “real” OSes, like the ARTIK5, lack the “desktop computery” bits one might associate with a day-to-day multi-purpose computer.

Several of the Pi models, on the other hand, are like mini, case-less desktop computers—they’re all ready for you to plug in a monitor, keyboard and mouse (HDMI, USB and USB respectively—there are four USB ports on the Pi 3) and fire it up. The Pi 3 makes things that much more easy-peasy computer-like by adding on-board WiFi capability (there’s also Ethernet).

Raspberry Pis have been around a while, at least in the context of IoT timelines, and that big number of customers quoted above—8 million—means lots of people from neophytes to rocket scientists have been hammering on the hardware and supported OSes for years now. That translates (potentially, at least) to better experiences with software setup, overall stability and a huge community of people to bother when you can’t get it to go right.

These aren’t supercomputers (tinkerers do, however, build supercomputers out of collections of Raspberry Pis, but of course), but the combination of the Pi 3’s quad-core, 64-bit ARMv8 CPU and a graphics processor mean the 3 can capably run, say, a browser as long as you don’t expect blistering repaints and scrolling.

Pis, especially the ones with a larger form factor, are multi-purpose machines. All Pis expose GPIO pins, but GPIO is not necessarily the bread and butter of Raspberry Pi projects.

Terminology

  • NOOBS: “New Out-of-Box Software”: OS installation manager that makes installing raspbian on a Pi ridiculously easy.
  • raspbian: A Debian-based Linux that is the Raspberry Pi Foundation’s “official”, supported OS on Raspberry Pis.
  • raspi-io: (npm package) Raspberry I/O plugin for johnny-five. Use raspi-io with Johnny-Five to make J5 work on various models of Pis.
  • sysfs: A Linux virtual filesystem that exposes what’s going on with GPIO pins as files that your code can read and write.

Getting started

My Raspberry Pi 3 was part of SparkFun’s Raspberry Pi 3 Starter Kit ($89.95). It was a matter of a few minutes to snap the board into the provided case and connect up some of the basic things. Extra convenient: the provided SD Card with NOOBS (“New Out-of-Box Software”) already on it.

But you do probably want a mouse, at least for getting the Pi set up. It took me twenty minutes or so to track down available peripherals: a monitor with HDMI out, USB keyboard and USB mouse. It also caught me off guard that plugging the Pi into 5V power will boot it (there’s no hardware power switch). Also, it can be tricky to see the red power LED on the board when it’s in the SparkFun case—it’s literally a black box!

Unboxing and setup

I popped the micro SD into the slot on the Pi 3, turned it on, and, bam, it walked me right through installing Raspbian in just a few mouse clicks.

But you do probably want a mouse, at least for getting the Pi set up. It took me twenty minutes or so to track down available peripherals: a monitor with HDMI out, USB keyboard and USB mouse. It also caught me off guard that plugging the Pi into 5V power will boot it (there’s no hardware power switch). Also, it can be tricky to see the red power LED on the board when it’s in the SparkFun case—it’s literally a black box!

Despite the slightly-condescending name, NOOBS does what it promises and getting Raspbian up and going with a fairly intuitive GUI took only a few mouse clicks (and about 20 minutes of installation downtime).

Getting on the WiFi network (yay, built-in WiFi!) was easy through the GUI. One fewer thing to worry about and deal with. Once it was on the network—and it did well at reconnecting after reboots—I pulled away the various peripherals, reattached them to computers that needed them, and used SSH to communicate with the Pi from my laptop on the same network.

Using instructions from the raspi-io repository’s wiki, I installed Node.js. It was a breeze.

Developing for the Raspberry Pi 3

The world’s your proverbial oyster when it comes to developing on the Raspberry Pi. However, because the Pi is so general purpose and has so much flexibility, sometimes GPIO feels like it’s forgotten in all the excitement. One of the hardest things to untangle with Pis is the eye-crossing array of different pinouts, exacerbated by third-party adapters, different Pi models and software packages that re-map pin numbers. There’s no one main way to develop with the Pi.

Representative Tasks and Applications

The following three representative tasks demonstrate typical hardware capabilities for IoT platforms:

  1. Button-controlled LED: Pressing a pushbutton (momentary switch) toggles an LED on and off. Uses digital input and digital output.
  2. Photoresistor and Fading LED: A “nightlight” that grows brighter as ambient light decreases (and vice versa). Uses analog input and PWD output.
  3. I2C magnetometer (compass) and websockets: A websockets-driven real-time display of compass headings. Uses serial (I2C) and software integration (websockets).

Button-Controlled LED

Part I: Using sysfs to control an LED

As proof-of-concept, I had written a simple LED-blinking script that used hamfisted file IO via sysfs for the ARTIK5—it worked both on the ARTIK’s stock (arcane) Fedora 22 OS and within the resin.io Docker container I used later.

Like on the ARTIK 5, Raspbian on the Pi also exposes GPIO pins via sysfs. I used a SparkFun 40-pin Pi Wedge included in my starter set, connected to a breadboard. All I had to change from the ARTIK’s code was a pin number.

In this circuit, the LED’s anode is connected to one of the GPIO pins on the Pi, obviously. But, which one? Figuring that out can be a headache. I’ve removed the SparkFun Pi Wedge from this diagram to make it less confusing (if that’s even possible).

Wiring Diagram of LED controlled by sysfs on a R Pi 3

A brief aside on Pi Pins

3.3V power (red jumper wire) is connected between the breadboard and the Pi’s physical pin 1 (top left pin), which happens to be 3.3V. Pin numbers increase top-to-bottom, with odd pins on the left (the GND connection is from physical pin 39) and even pins on the right. All good so far, except that nearly no one uses Pi physical pin numbers directly. There are a number of different pin-numbering conventions.

The LED in this case has its anode connected to the Pi’s physical pin 11. Pin 11 is also known as:

  • P1-11 (Physical Pin 11 on header 1; all 40 pins of the Pi 3 are on “header 1”)
  • BCM (“Broadcom SOC Channel”) pin 17
  • GPIO pin 17
  • WiringPi pin 0

In the sysfs-controlled example, the pin is used by its GPIO name (gpio17).

Sysfs-controlled LED: Source

Part II: Using johnny-five with raspi-io

Then I decided to try to see if Johnny-Five would run on the Pi 3 via the raspi-io IO plugin (it’s not yet listed as a supported platform but I could tell that at least some of the constituent parts were in place in the dependencies). Using translated WiringPi pin numbers, I was able to create a button-controlled LED script with little fuss (once I got the pin numbers right).

Note: If you use raspi-io and WiringPi pin numbers in your node scripts, you’ll have to run them with root/sudo privileges.

This example uses Wiring Pi numbering for pins.

Wiring Diagram of Button-Controlled LED on a Raspberry Pi 3

Button-controlled LED with raspi-io: Source

Analog Sensor and PWM (“Nightlight”)

Not so fast! Raspberry Pis don’t have any analog inputs—they don’t have any Analog-to-Digital Converter (ADC) hardware. You can get an external ADC or build a special timed circuit, but no thanks for now.

Here’s where I got either clever or lazy depending on your vantage. The Pi’s GPIO is…a…bit of a muddle. But you know what hardware has extremely reliable and simple GPIO? Arduino Uno, that’s who. And the Pi 3 absolutely has the oomph to control an Arduino of its very own.

As a quick test, I made the button-controlled LED work on an Arduino Uno connected to one of the Pi’s USB ports. I connected the breadboard and components to the Uno’s pins (instead of directly into the Pi via the Pi Wedge). Then, all I had to change in the script were:

  • The board initialization (remove reference to raspi-io)
  • Pin numbers

Convinced that the Pi 3 was happy and solid with its own Uno in tow, I whipped up a quick “nightlight” example with a photoresistor and PWM-driven LED. It only took about two minutes to get this going.

To run this, I plugged an Arduino into one of the Pi 3’s four USB ports and ran the command node main.js. No configuration was necessary—it just worked.

Wiring Diagram of Arduino-powered Nightlight Powered From Raspberry Pi 3

Source

Yay for abstraction layers!

I2C Sensor with Websockets

I was able to adapt some baseline code already written to whip up a websockets-capable web server on the Pi which can update a compass heading in a client browser in realtime.

You’ll note that the source of this example doesn’t pass pin numbers at all. Johnny-Five abstracts that away for us when a Compass object is constructed with the HMC5883L controller. As shown in the wiring diagram, the breakout board’s SCL is connected to physical pin 3 on the Pi 3—which is SCL0; SDA is connected to physical pin 5 (SDA0). How did I know that? I used the handy raspi-io Wiki page about pin numbering.

Wiring Diagram of HMC5833L on Raspberry Pi 3

Source

Pomlet

The trickiest part about getting Pomlet to run on the Raspberry Pi 3 was the pin-number conventions. But, run it it does!

Source and more information

The Verdict

The Raspberry Pi 3 was easy to use and reliable. The NOOBS installer and rasbian OS are less intimidating to non-Linux-experts than other Linux distributions and builds for other platforms.

GPIO pinouts and support are confusing enough that at times it felt easier to use the Pi as a host computer controlling an attached development board. While GPIO isn’t an afterthought for Pis, exactly, it isn’t the core focus as with other boards. The lack of analog input support (ADCs) might be surprising to unexpecting developers.

The Raspberry Pi 3 is Good For…

  • Those looking for a well-tested, well-used and established platform with consumer-friendly OSes available.
  • Multi-purpose systems.
  • Easy WiFi connectivity right out of the box.
  • Full-stack applications.
  • Basic IO.
  • Controlling other development boards or SBCs.