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
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.
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
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/.
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] ]; } }
Hello
For MPD OUT what server did you use? Thanks
LikeLike
Hi Mark,
When I installed the Node-Red MPD component it took care of loading the MPD server. At the time everything worked well, but I’ve had some issues with mpd/mpc especially with Python.
If you have any problems let me know, i still have my Pi test system.
Cheers
Pete
LikeLike