littleBits/Pi Internet Radio

The littleBits Proto bit allows littleBits components to be directly to connected to a Raspberry Pi (or Arduino).

The Goal

The goal of this project was to play Internet Radio and use littleBits to:

  • start the music, (and possibily change the music)
  • control the volume
  • use the littleBits speaker

For this project we used:

  • 2 Proto Bits
  • 1 Fork Bit
  • 1 Button Bit
  • 1 Slide Dimmer Bit
  • 1 Speaker Bit
  • 1 Bargraph Bit (optional)
  • 1 Wire Bit (optional)

The Wiring

music_setup

For the littleBits to Pi wiring, the input to the Fork Bit needs to have 5V on both the power and data pins, the GND pin of the Proto Bit is wired to GND on the Pi.

music_circuit

The output on the littleBits Button bit is wired into GPIO 23 on the Pi.

The Logic

For the logic we used Node-Red, Python would have probably been a better choice, but we wanted to see if it could improve our Node-Red skills.

To play Internet music we need to load the Node-Red mpd node:

cd $HOME/.node-red
npm install node-red-contrib-mpd

The Node-Red logic used only 3 nodes:

  • 1 – Raspberry Pi input node, to read button push
  • 1 – Function node, to do some action on the button push
  • 1 – MPD Output node, to play Internet Radio

radio_logic

There are a lot of possible options for what the littleBits button could do. For this example we simply wanted to load an Internet Radio URL, and then start playing. To find Internet Radio stations go to: https://www.internet-radio.com/.

music_func

The function node had a context variable, issetup,  that was used to load the music for the first time and then start playing.

// create an "is setup" variable
var issetup = context.get('issetup')||0;

if (msg.payload == "1") {
// if the setup hasn't been run, add a radio station playlist
if (issetup === 0) {
context.set('issetup',1);
var msg0 = { payload:"clear"};
var msg1 = { payload:"add http://185.33.21.112:11029" };
var msg2 = { payload:"play" };
return [ [ msg0, msg1, msg2] ];
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s