Hyperrhiz 18 »Bookbot poet
My Poet, My Poem & I: The NCSU Libraries bookBot Poet
North Carolina State University
Implementation: the Poem Dispenser
The Poem Dispenser application itself was written in Python. This language was chosen since I had prior experience writing small applications with Graphical User Interfaces using Python's tkinter library and Adafruit, from where we obtained the thermal printer, provided a Python library that was relatively easy to work with. The code would be run on a Raspberry Pi running Raspbian, a popular light-weight operating system for the Pi. The specific model chosen for the Poem Dispenser was the Pi 3 Model B. Older versions should also work, although newer generations have some advantages over the original model:
- The earliest models only provided a single USB port. This would be sufficient for normal operations where the port would be used to connect the touch screen controller to the Pi. However, troubleshooting becomes easier if one can also attach a mouse and keyboard which is possible due to the newer versions' four ports.
- The Pi 3 has an integrated wi-fi module, whereas older models require a wi-fi adapter.
- Although the application does not use many system resources, the faster CPU and larger memory in the latest version ensures that the projects runs more smoothly.
Another new feature of the Pi 3 required a system modification before the printer would work. The Pi 3 has Bluetooth capability; however, the module is implemented in a way that occupies the GPIO pins which would normally be used by the printer. By turning off Bluetooth – which is not required anyways – printing from those pins is re-enabled.
While there were the usual small issues when coding and testing the application, I encountered one problem that forced a change in how the content was prepared for printing. The initial plan was to generate a basic HTML file that would contain both images and all the text, using CSS to add some styling. The Dispenser would then use PhantomJS, a headless browser, to convert the HTML markup into an image file that could be sent to the printer. While PhantomJS worked very well and the text shown in the file it generated was clearly legible, the quality of the image when printed was not sufficient. I had to eventually abandon this approach and instead copied the method used by the “Vandal Poem” project, which was to print each section separately, putting out the text line by line and use Python's textwrap library to adjust line lengths to the printer's maximum print width. Still, it was necessary to experiment with printer warm-up, print, and feed times to achieve an acceptable print quality.
A second problem that came up was that, in order to fit the display inside the case, I had to invert it so that the HDMI input pointed in the right direction. Raspbian allows for display inversion through a change to the boot/config.txt file which basically turns the display content by 180 degrees. However, this does not affect the input data collected by the touch screen controller, which means that if a user touches the top left corner of the display, the cursor on the screen moves to the bottom right corner. In order to rectify the situation, the script includes an operating system call to change the controller's coordinate transformation matrix as soon as the script is started; a mathematically more gifted colleague provided invaluable assistance at this point.
The case was cut from two sheets of birch plywood using the laser cutter in the D. H. Hill Library's Makerspace. The initial design was done with a hand drawing which was then transformed into an Adobe Illustrator document since that was the format required by the laser cutter. The document contained a large amount of smaller parts which were used as reinforcements (see the accompanying files in the repository for this project). As I did not know how many items were needed I added as many as could fit on the two sheets; several pieces ended up left over. Once all parts were cut, they were glued together and the electronic components were installed.
- Raspberry Pi 3 + Power Supply (https://www.adafruit.com/product/3055)
- Memory Card (8GB or larger, OS: Raspbian)
- Thermal Printer + Power Supply (min. 2 A) (https://www.adafruit.com/product/597)
- 7" Display + Power Supply (https://www.adafruit.com/product/2395)
- 2 12" x 24" sheets of birch plywood