Table of Contents
Remember Big Mouth Billy Bass? We'll, we've given him a bit of an mbed brain transplant. Steve Ravet taught him some new tricks, and we've tweaked him some more so he can read out tweets too!
You can now:
- Press the red button and billy will play something from his new repertoire
- Twitter a message @mbedmicro and billy will read it out
Here is his original video:
How it Works¶
The Twittering Billy hack replaces his existing brain with an mbed Microcontroller, wiring it up to his motors so we have control of his movements, a USB Disk so he can store lots of audio files, and the mbed's Ethernet interface to the internet. What might be surprising is that Billy is not connected to a PC; everything is being done by the mbed Microcontroller and a connection to the internet!
Fishing for twitters...¶
The mbed's first job is to fetch a web page we've set up, which tells him whether there is anything on twitter. He uses the mbed's HTTPClient library so basically does:
// Set up a http client using the ethernet interface HTTPClient http; // fetch a url, and store the result http.get("http://billy-server.com/any-twitters.php", result);
Billy just keeps checking this, forever. Until the result tells him there is a new twitter!
Once there is a twitter, he then asks the web server to translate that twitter to a voice, and return it as an audio file. The code is something like:
// Open a file on the USB Disk to store the audio FILE *fp = fopen("/usb/voice.wav", "w"); // Fetch the voice, and store it in the file http.get("http://billy-server.com/twitter-2-audio.php?id=ID", fp);
The web server uses the iSpeech web API to convert the tweet to audio, then just returns a .wav file when Billy requests it. We also generate a movement file to tell bill how to move.
Now Billy has his audio and his movement commands on the USB Disk, he plays it out the mbed analog output to a speaker. At the same time, he flaps his tail and moves his mouth whenever the movement file tells him he should. And fun is had by all!
The code can be found here:
Twittering Billy Bass plays back samples and looks out for and reads twitters!
The hardware setup required is:
- An mbed Microcontroller and Billy Bass!
- Some of the PwmOut pins connected to the motors within Billy.
- The Ethernet interface connected to the internet via a RJ45 cable/socket
- The button on the front of Billy connected to a DigitalIn
- A speaker connected to the mbed AnalogOut
- A USB Disk connected to the mbed USB Host interface
The software is made up of some of the mbed official libraries (from the Handbook) and user contributed libraries (from the Cookbook):
- HTTP Client - Checks twitter status and downloads sound files
- Ethernet - Puts an mbed on the internet
- USBMSDHost - Stores the sound files on Billy
- PwmOut - controls Billy's motors
- DigitalIn - connected to the red button on Billy
- AnalogOut - provides Billy's voice
- Ticker - provides timing signals
- Timer - allows us to schedule Billy's twitter checks
With special help from:
- Steve Ravet for his original Big Mouth Billy Bass hack. See Big Mouth Billy Bass
- Gemmy Industries, for giving the world Big Mouth Billy Bass in the first place!
- iSpeech, for giving us Billy's voice!