Surreal random micro:bit story printer

This is a slight twist on my original Little Box of Poems I originally made back in 2012. It mashes that up with Papert-inspired random poetry to create surreal haiku-like poems or story starters.

This project uses a BBC micro:bit and a serial thermal printer. Wiring it up is very simple: connect the black data wire on the printer to GND on the micro:bit, and the printer’s yellow data RX wire to pin 8 on the micro:bit (you could use another pin, I just happened to use pin 8). The printer needs 5 volts to power it, so it needs a separate power supply. Luckily USB sockets give 5v, and thanks to this tutorial from the awesome Tanya Fish I chopped up an old unwanted USB lead to make my own source of printer power.

How to wire a serial printer to a micro:bit

Parts list:

  • micro:bit with power source, battery or USB.
  • Some way of connecting pins – edge connector and jumper wires or crocodile clip leads.
  • A serial thermal till-roll printer like this one and some thermal paper.
  • A 5v power source for the printer – an old USB lead chopped up and a USB power source will do nicely.
  • Python program below and here – you can flash it onto the micro:bit using the online micro:bit Python editor or Mu.

The Python program is in two parts – the first part is all the functions to send control codes for different styles of printing – most of these aren’t used in this project but you might have fun playing with them – you can also print different kinds of barcode if you look here.

The second part creates lists of different kinds of words: animal / people nouns, verbs, adverbs, prepositions, adjectives and place nouns. Each time you press button A, it picks a random word from each category and prints them out. You could use this as a story starter, use it as a passphrase or just enjoy the surreal haiku-like poems. Add your own words. How long a story can you get a machine to write? Let me know what you do with this idea, using a printer, 2-line LCD or just the built-in LED display.

Download Python program here.

import microbit
import random
microbit.uart.init(baudrate=19200, bits=8, parity=None, stop=1, tx=microbit.pin8, rx=None)

# Print lines of text in buffer
def thermal_print_ln(msg):

# Send text but don't print - you need to send a
# newline (\n) character to empty buffer & print.
# This enables mixed print modes on same line.
def thermal_print(msg):

def doubleHeightOn():

def doubleHeightOff():
    global print_mode

def smallFontOn():

def smallFontOff():

def boldOn():

def boldOff():

def wideOn():

def wideOff():

def inverseOn():

def inverseOff():

def upsideDownOn():

def upsideDownOff():

def underlineOn():

def underlineOff():

def largeFontOn():

def largeFontOff():

def leftAlign():

def centreAlign():

def rightAlign():

# prints test page
def printerTest():

# resets the printer to default values
def printerReset():

# press button A to activate demo
# increase printing temperature and time

noun_list = ["fish ", "dog ", "cat ", "girl ", "boy ", "duck ", "teacher ", "snake ", "kitten ", "puppy ", "bird ", "bee ", "spider ", "ant "]

verb_list = ["walks ", "runs ", "eats ", "sings ", "smiles ", "waves ", "swims ", "talks ", "stands ", "looks ", "nods ", "sleeps ", "flies ", "floats "]

adverb_list = ["quickly ", "slowly ", "happily ", "sadly ", "gracefully ", "hungrily ", "well ", "badly ", "bravely ", "lazily ", "joyfully ", "crossly ", "loudly ", "quietly "]

preposition_list = ["under ", "over ", "beneath ", "through ", "into ", "above "]

adjective_list = ["dark ", "spooky ", "lonely ", "ancient "]

place_list = ["sky ", "pond ", "forest ", "ocean ", "lake ", "city ", "village "]

while True:
    if microbit.button_a.was_pressed():
        poem = noun_list[random.randint(0, len(noun_list)-1)] \
        + verb_list[random.randint(0, len(verb_list)-1)] \
        + adverb_list[random.randint(0, len(adverb_list)-1)] \
        + preposition_list[random.randint(0, len(preposition_list)-1)] \
        + "the " + adjective_list[random.randint(0, len(adjective_list)-1)] \
        + place_list[random.randint(0, len(place_list)-1)]
        thermal_print_ln("micro:bit poem or story")
        thermal_print_ln("specially made for you!")
        thermal_print_ln(noun_list[random.randint(0, len(noun_list)-1)] + verb_list[random.randint(0, len(verb_list)-1)])
        thermal_print_ln(adverb_list[random.randint(0, len(adverb_list)-1)] + preposition_list[random.randint(0, len(preposition_list)-1)])
        thermal_print_ln('the ' + place_list[random.randint(0, len(place_list)-1)])
        thermal_print_ln(" ")
        thermal_print_ln(" ")

p.s. I’ve tried printing bitmaps from the micro:bit with no luck, but this article may offer a clue.

This entry was posted in microbit and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>