This project started last summer when I was sniffing traffic from the NPR One iOS app with wireshark. After logging a bunch of requests, I thought it might be possible to create a simple radio using a Raspberry Pi, since I'm unable to get a decent FM signal from WYPR or WAMU.

While testing out the endpoints, I spotted a link to NPR One public API docs in the error response. The project was pushed forward by the availibily of great API docs, and a bunch of application development and design documentation at the NPR One Developer Center. Since the NPR One API docs were written using swagger, it didn't take much work to develop a full Node.js API client for NPR One by using swagger-client to connect to the API.

From there, I used the Node.js API client to create a simple NPR One command line interface that supports both keyboard and MPR121 touch controls with the new adafruit-mpr121 Node.js package. This was all integrated into a hand carved enclosure, which can be seen below.

We will not be covering enclosure design in this tutorial, but the Ruiz Brothers created an amazing 3D printed enclosure for this project.

The NPR logo is a registered trademark of NPR used with permission from NPR. All rights reserved.

Raspberry Pi Zero

This project was designed for the Raspberry Pi Zero, but any Raspberry Pi model will work if you are unable to get your hands on the elusive Pi Zero.

Raspberry Pi Zero

PRODUCT ID: 2818
Note: Due to popular demand, there might be some delay in shipping products containing Pi Zero!At first glance, the Pi Zero isn't much.  It just looks like a slimmed...
OUT OF STOCK

The Raspberry Pi A+ is a great alternative if the Pi Zero is out of stock.

Raspberry Pi Model A+ 512MB RAM

PRODUCT ID: 2266
Note: As of August 10th, 2016 the Raspberry Pi A+ now includes 512 MB of RAM!The Raspberry Pi Model A+ is the perfect board for the minimalist Pi fan. This...
OUT OF STOCK

WiFi Dongle

The WiFi dongle below can be used with a USB OTG adapter, or you can attach the dongle directly to the Zero using the WiFi piggyback hack.

Miniature WiFi (802.11b/g/n) Module: For Raspberry Pi and more

PRODUCT ID: 814
Make your Internet of Things device cable-free by adding WiFi. Take advantage of the Raspberry Pi and Beagle Bone's USB port to add a low cost, but high-reliability wireless link....
OUT OF STOCK

Here is a closeup of the WiFi Piggyback hack. Make sure to keep the two yellow wires equal length so that there aren't issues with the USB connection. The WiFi configuration will be covered in the next section.

MAX98357 I2S Amp

For audio, this project uses the MAX98357 I2S breakout.

Adafruit I2S 3W Class D Amplifier Breakout - MAX98357A

PRODUCT ID: 3006
Listen to this good news - we now have an all in one digital audio amp breakout board that works incredibly well with the 
$5.95
IN STOCK

You will need to connect it to the Pi Zero using the following pins:

  • Amp Vin to Raspbery Pi 5V
  • Amp GND to Raspbery Pi GND
  • Amp DIN to Raspbery Pi #21
  • Amp BCLK to Raspbery Pi #18
  • Amp LRCLK to Raspbery Pi #19

For more information about connecting the I2S amp, please visit the Adafruit MAX98357 I2S Class-D Mono Amp guide. You will not need to do any of the software configuration mentioned in that guide. That is handled for you in the next section.

MPR121

This project will use 6 electrodes on the MPR121, and they are configured as follows:

  • Pin 0 -> Rewind 15 seconds
  • Pin 1 -> Play/Pause toggle
  • Pin 2 -> Skip to the next story
  • Pin 3 -> Mark story as interesting
  • Pin 4 -> Volume down
  • Pin 5 -> Volume up

Adafruit 12-Key Capacitive Touch Sensor Breakout - MPR121

PRODUCT ID: 1982
Add lots of touch sensors to your next microcontroller project with this easy-to-use 12-channel capacitive touch sensor breakout board, starring the MPR121. This chip can handle up to...
$7.95
IN STOCK

You will need to connect the Raspberry Pi to the following pins on the MPR121:

  • Connect Raspberry Pi 3.3V to MPR121 VIN.
  • Connect Raspberry Pi GND to MPR121 GND.
  • Connect Raspberry Pi SCL to MPR121 SCL.
  • Connect Raspberry Pi SDA to MPR121 SDA.

Once the hardware is connected to your Raspberry Pi Zero, continue on to learn how to install the software for this project.

We will need to create or use an existing NPR account in order to get access to the NPR One API. First, visit the NPR One Developer Center, and click the login button.

Use your existing NPR, Facebook, or Google account to sign in, or register for a new NPR account.

Click the Allow button to give the NPR Dev Center access to your NPR account.

Updating Account Info

If you haven't set your first and last name in your NPR account profile, you may be required to do so before accessing the NPR Dev Center. 

Enter your first and last name, and then save changes.

Requesting API Access

Navigate back to the NPR One Developer Center, and select the Request API Access menu item from the account menu.

Next, you will need to register for personal access to the NPR One API.

Creating Your First Application

We now need to create the NPR One for Raspberry Pi application. Click the Create New Application button to start the process.

Enter the name of your application. In this example, we used NPR One for Raspberry Pi.

After the application has been created, save the Application ID and Application Secret in a safe place, or leave the window open so that you can easily access them in the next section.

NPR One Raspbian Image

First, you will need to download a copy of the NPR One Radio Raspbian image, and transfer it to a 8GB SD card. If this is your first time making a SD card for a Raspberry Pi, you can head over to our tutorial for more info about the process.

WiFi Config

Before inserting the SD card into the Pi Zero, you will need to edit the occidentalis.txt file using your favorite text editor on your computer. You can find the occidentalis.txt file on the boot partition of the SD card.

It should look something like this:

Download: file
# hostname for your Raspberry Pi:
hostname=nprone

# basic wireless networking options:
wifi_ssid=your network here
wifi_password=your password or passphrase here

Update the SSID and password with the appropriate values for your network, and save the file.

Connecting to the Pi Zero

Once you have the WiFi config saved, you are now ready to insert the SD card into the Raspberry Pi Zero, and power it on. You can connect to it over SSH as the pi user with the default password raspberry using the following command.

If you are unfamiliar with SSH, you can use the Terminal feature of our Pi Finder to connect to your pi.

Expanding the Filesystem

You will need to expand the filesystem to fill your SD card. You can do this by running raspi-config, and selecting the first option. You will need to reboot for this to take effect.

Download: file
sudo raspi-config

Authenticating with NPR One

Next, you will need to use the Application ID and Secret from the NPR One Dev Center to authorize your Pi. Enter the ID and Secret when prompted, and visit http://www.npr.org/device when the CLI presents your device code.

Do not select the complete option until you have authorized the app at http://www.npr.org/device.

Enter your activation code on the NPR website, and press the Next button.

Grant access to the Pi by pressing the Allow button.

You should see a success message on the NPR site. Once you see this, you are ready to move back to the Pi.

Press return to select the complete option on the Pi, and you should see the stories start to load and play.

Starting the Radio on Boot

If you would like to start the radio on boot, you can do that by running the following command.

Download: file
$ pm2 start npr-one && pm2 save

That will start the radio, and keep it running until you pause it or stop it using the play/pause button. You can also force quit the radio by running this command.

Download: file
$ pm2 stop npr-one

Thanks for all of the help and support from the NPR One team. They were very helpful with adding support to their NPR One dev center so that individuals could easily sign up for API access, which is what made this tutorial possible. If you are a developer, you should check out their new developer blog at npr.codes.

Also, a very big thanks to the Ruiz Brothers for the great work on their 3D printed enclosure, and for their help testing the radio. Again, if you missed it, check out the Ruiz Brothers' videos for their 3D printed enclosure:

The NPR logo is a registered trademark of NPR used with permission from NPR. All rights reserved.

This guide was first published on Jun 08, 2016. It was last updated on Jun 08, 2016.