O, Miami Poem-O-Matic (Poem Printer)

What

Poem-o-matic is a friendly “bot-in-a-box” that prints out a keepsake poem just for you when you press the button. We hope you’ll snap an Instagram of your poem and share it with your social network.

The very first (and at this time, only) Poem-o-matic was created for the 2016 O, Miami Poetry Festival at the Moonlighter Makerspace, where fine Miami nerds come together to make cool things.

Why

Poem-o-matic was created for the 2016 O, Miami Poetry Festival. The mission of the festival is for every single person in Miami-Dade County to encounter a poem during the month of April. O, Miami is a Knight Foundation-funded organization that expands and advances literary culture in Greater Miami, FL.

Who

Poem-o-matic is a project by Mario Cruz, with negligible spiritual support from Cristina Solana and Rebekah Monson. Ernie Hsiung assisted with the documentation.

Additional inspiration, research and some code lifted and referenced from these two sites:

How

Note: This document assumes you can get a Raspberry Pi up and running. If not, try this link.

SSH into your Raspbery Pi or — via monitor and keyboard — open a terminal. We will need to install the required files by typing the following into a terminal window on your Pi:

sudo apt-get update
sudo apt-get upgrade

Install the needed packages:

sudo apt-get install python-dev
sudo apt-get install python-rpi.gpio
sudo apt-get install python-serial
sudo apt-get install python-imaging-tk
sudo apt-get install python-unidecode
sudo apt-get install gcc

Next give the serial port permission to be used:

sudo usermod -a -G dialout pi

Now reboot, to make sure everything is okay:

sudo shutdown -r now

If everything boots correctly please make an image backup of your SD / Raspberry PI with Apple Pi-Baker Mac or an app of your choice like Win32 Disk Imager (Note: I have not used this.)

Changes to your cmdline.txt could render your Pi useless until you re-image your SD.

Then we need to change the Pi serial port. These changes keep the printer from spewing garbage when you first set it up. The serial port is set up for terminal use, so we need to turn that off.

sudo nano /boot/cmdline.txt

In the file, change: console=ttyAMA0,115200 to console=tty1

Reboot to make sure it’s all working:

sudo shutdown -r now

Install the printer

Take the green/yellow/black cable and cut the green cable. You don’t need it and it can it can short out your Pi.

Now connect it to the TTL socket in the back of the printer: the black cable goes into the GND, and the yellow into the RX, and the green wire should just be a stub.

To connect the printer we make use of the pin #6 (Ground) and the pin #8 (GPIO14).

Now, let’s connect the power. Attach the printer’s red/black wires to the 2.1mm jack adapter:

Power up the printer

Plug the 5V 2A power supply into the 2.1 mm DC jack adapter provided with the kit.

Reboot:

sudo shutdown -r now

If your printer starts spewing gibberish when it reboots, check /boot/cmdline.txt files to make sure the changes were saved from above.

Next, we need to download the python files needed to print and Poem-O-Matic files to run from github.

First, you will need to install git-core onto your pi using:

sudo apt-get install git-core
git clone git://github.com/MarioCruz/PoemOMatic

Now we are ready for a test print:

python test.pyTestIMAGE

This a poem to verify this works:

Python PoemMain.py

You should get a random poem.

On the PI3 the Serial Port is named “ttyS0” and not “ttyAMA0” If you are using a Raspberry Pi 3

Comment p = printer.ThermalPrinter(serialport=”/dev/ttyAMA0")

and uncomment p = printer.ThermalPrinter(serialport=”/dev/ttyS0")

Connect one side of the push button to pin 14 GND on the Raspberry Pi. Connect the other side of the button to pin 16 on the Pi (GPIO 23). You also need to connect the same side of the switch that’s connected to GPIO 23 via a 10k ohm resistor to pin 1 of the Raspberry Pi (which supplies 3.3 volts of electricity).

Finally, we want the PoemOMatic program to run whenever the Pi is started and the button is pushed. Therefore we need to modify the /etc/rc.local file to reflect this by using a terminal window:

sudo nano /etc/rc.local# Change to the Poem Directory
cd /home/pi/PoemOMatic
# Tell me the system is up and the IP (if connected)
python upip.py
# Listening for the Switch to be pressed
python GPIORUN.py
exit 0

Save and Reboot

Once you have tested that it all works, transfer your Pi, printer, and breadboard into the custom box and make sure everything is plugged in and sits well. Power it all up, give a few minutes, if it all works the printer should say it is ready with an IP if connected.

Press the button and receive a poem:

I modified the box to be screwless and added the O’ Miami logo using Adafruit IOT Printer box /via Thingiverse as my starting source and cut it on Moonlighters Wood CNC .

{"title": "Fire and Ice",
"author": "Robert Frost",
"text": ["Some say the world will end in fire,",
"Some say in ice.",
"From what I've tasted of desire,",
"I hold with those who favor fire.",
"But if I had to perish twice,",
"I think I know enough of hate",
"To say that for destruction ice",
"Is also great",
"And would suffice."]}

The poems themselves are in the PoemJson directory in a JSON structure. Make any changes or add poems and use a SFTP program i.e. Transit, Cyberduck, etc to upload into the Raspberry Pi.

Plug an ethernet cable into the Raspberry Pi, power the Pi and if ethernet settings are correct the IP address will be shown at the top of the ready print slip:

If you get no IP reboot and try again.

SFTP into the PI using the IP User: PI Password:raspberry

Add new poems into the /PoemOMatic/PoemJson/ with a .json extension. You may want to validate your JSON files using a validator before uploading i.e. https://jsonformatter.curiousconcept.com

Things to make better

  1. Use textwrap.fill Json data
  2. Use escape for ‘ issues in JSON data. “‘“ crashes when printing

Mario The Maker : Mario Cruz is a Hacker, Maker, and inventor from Miami. Working out of Moonlighter Makerspace. @MarioCruz twtr. http://bit.ly/2r0Jcy3 Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store