dark mode light mode Search Menu
Search

Mad Libs with BBC micro:bit

Did you know you can program a teensy computer to be a scrolling name badge, a motion-activated hot potato, a jumping jack counter, and even a voice-activated music player?

With some creativity, a BBC micro:bit can do all of that and more using the power of MicroPython, a pared-down version of Python built exclusively for small, embedded hardware like micro:bits and Raspberry Pi Picos.

To take advantage of the latest version of the micro:bit’s speaker, we are going to create a Mad Lib game that uses the micro:bit’s voice synthesizer to tell us a funny story. Micro:bit recently developed its own Python editor, designed to work exclusively with the micro:bit, so we will use that for our program.

The micro:bit Python editor can be found at https://python.microbit.org/v/3 Find the project code at https://github.com/fairydustandmore/Beanz. You will have to import the speech module, so the micro:bit can speak to you. You also need to use the say function to enable the speech synthesizer. (Fun fact: the synthesizer is based on an old text-to-speech program built for the Commodore 64.)

You will also notice the print function is used nearly every time the say function is used. That is because the speech synthesizer can be hard to understand, but thankfully the micro:bit’s editor has a serial terminal—a black screen that can be shown or hidden. (Keep it unhidden).

Serial is primarily used to display errors from a program but also shows the output from a program. We can use it to read what the synthesizer is saying. We also must use it to interact with our Mad Lib game to type in names, nouns, adjectives, and more.

When you open micro:bit’s editor for the first time, you will find code already there. It’s a working program you can test on your micro:bit. Delete it all and start fresh. You can use a split screen on your computer to type the code from GitHub into the Python editor. Review your code often by testing it using the editor’s on-screen simulator.

When you are done typing up your Mad Lib and testing it in the simulator, connect your micro:bit to your device to give it power. Press the button that says, “Send to micro:bit”. Follow the instructions to transfer the program via Bluetooth.

Try editing the Mad Lib game and make it your own. You can swap out built-in images from the display function as well. The speech synthesizer understands how hyphens, commas, periods, and question marks alter the way a sentence sounds. For example, it will pause, stop speech, and make pitch rise or fall at the end of a sentence. Experiment with the punctuation of a sentence to hear the differences.

To hear your Mad Lib loud and clear, connect alligator clips to pins 0 and GND on your micro:bit to your headphones plug. The voice synthesizer will never sound like a human (more like an old robot) but you can edit the pitch and speed to your liking.

Learn More

micro:bits are Mad for Mad Libs! Program on GitHub

https://github.com/fairydustandmore/Beanz

Micro:bit’s Python Editor

https://python.microbit.org/v/3

BBC micro:bit MicroPython documentation

https://microbit-micropython.readthedocs.io/en/v2-docs/

Make Some Noise Project (for headphone connection instructions)

https://microbit.org/projects/make-it-code-it/make-some-noise/