MCPcopy Index your code
hub / github.com/bokito-studio/poetry-camera-rpi

github.com/bokito-studio/poetry-camera-rpi @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
74 symbols 242 edges 7 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Poetry Camera

A camera that prints poems of what it sees.

We started this project as newcomers to the world of hobby electronics. The following instructions are intended for complete beginners, as we were. We simplified some of the design to optimize for easily sourcing and assembling parts; as a result, it's less compact than our photographed versions. If you are comfortable with electronics and coding, we encourage you to experiment and remix even more.

⚠️ These instructions are still in progress. ⚠️ Try it out and let us know what's confusing, or doesn't work.

Hardware you'll need

1. Computer: Raspberry Pi Zero 2 W with headers

Raspberry Pis are simplified computers. They are lightweight, cheap, have limited processing power, and are more fragile than typical consumer electronic devices. It's very sensitive to the specific power sources you use — too much power and you'll fry the part, too little power and the software won't run. You also have to manually shut down the software before unplugging the power, to protect the software from being corrupted.

We chose the Pi Zero 2 for its balance of processing power (Pi Zeros are too slow) and compact size (most other Pis on the market are larger). The wire diagrams in this tutorial will apply to all Raspberry Pis, but there may be differences in software and camera compatibility, especially with older devices. We've tested this with a Pi 3b+ and it works fine, but a Pi 4 probably requires too much power to make it a viable portable solution.

Raspberry Pi Zero 2 is often sold without headers (those 2x20 black metal connectors). The headers let you easily connect the Pi to the printer and buttons with plug-in jumper wires. If you buy the Pi without headers, you'll need to separately buy a 2x20 header and solder them on yourself. If you don't want to solder, you can use hammer-on headers and this installation rig.

Raspberry Pis are also recovering from a supply shortage. Check rpilocator.com for live stock notifications on standalone parts (does not list accessory kits).

2. Accessories to connect the Raspberry Pi to stuff.

3. Camera: Raspberry Pi Camera Module 3

Mostly straightforward, but be careful of damaging the hardware. The Raspberry Pi camera is delicate and can be easily fried via static. We broke 3 cameras in the process of making this project. Just make sure to always store it in a static-shielding bag when you're not using it.

If you are connecting the camera to a Pi Zero 2, note that the Zero 2's camera connection collar is also very delicate. We broke a Pi Zero 2 camera collar in the process of making this as well and had to just get a new Pi 🥲

We have not tested these instructions with older models of Raspberry Pi cameras.

  • Camera accessories:
    • Camera case with tripod — Helps proteect the delicate camera hardware during development.
    • Camera cable sized specifically for Pi Zero & Zero 2 — If you are using a larger Pi, you only need default cable that comes with the camera. If you got your Zero 2 camera cable in a kit, it is likely the short ~2 inch cable. Make sure to get a long enough cable that gives you more flexibility in where you place your camera.
    • Optional: Tweezer for opening/closing the delicate camera collar on Pi Zero 2

4. Receipt printer: Mini Thermal Printer w/ TTL Serial connection

We used the Adafruit thermal printer line for this project, but they have subsequently been discontinued. Similar printers exist on Amazon and Aliexpress; the ones we've bought work with the same printer drivers (which are also no longer maintained by Adafruit, but still seem to work).

The Nano Thermal Printer or Tiny Thermal Printer are more compact, but have slightly different wiring.

The important thing is that the thermal printer has a TTL serial connection so you can easily connect it to the Pi. Search "TTL embedded thermal printer" on Amazon or Aliexpress to find your parts.

5. Batteries:

If you want your camera to be portable, you'll need some batteries! The Pi requires a steady 5V of power @ 1.2A, while the printer needs 5-9V and draws ~2A while printing.

Recommended power supply: 6xAA batteries

It's not the lightest solution, but it's a beginner-friendly starting point. - 6 x AA battery holder with DC plug - 6 x AA batteries — rechargeable NiMH batteries (e.g., Eneloop) provide 7.2V, non-rechargeable alkaline batteries (e.g., Duracell) provide 9V. Either works. Of course, don't mix batteries! - In-line power switch for DC barrel jack to control flow of power to circuit - DC wire terminal block to connect batteries to circuit - Step-down (buck) converter — 5V @ 3A output steps down the battery voltage to 5V for the Raspberry Pi - MicroUSB shell to power the Pi, or cut open a MicroUSB cable - Soldering iron

Other solutions that could work: - Put the above circuit on a PCB so you just need to plug in the connectors instead of soldering — we did this for our project! Will upload gerber files in the future. - 7.2V lithium batteries, e.g. 2x 18650s - 7.4V NiMH batteries for RC cars - If you don't need it to be super portable, get a portable power station to plug in the Pi and printer - If you don't want to solder, you could power the Pi and printer through two separate batteries. However, we've run into overheating issues with the commonly-recommended PiSugar 3 battery.

Power supplies that DON'T work: - Typical 9V alkaline batteries do not work as they do not provide enough current - Standard phone banks don't provide continuous power to the Raspberry Pi, causing it to shut down after a few minutes - Just plugging both devices in to a single 5V power bank — it can't handle the current draw while printing. Either the Pi shuts down during printing, or the printer doesn't have enough power to print.

6. Shutter button & LED

Any LED + momentary pushbutton will work for the shutter button. We use the LED as a status indicator for things like ready, loading, etc.

7. Miscellaneous equipment

  • Wire cutter & stripper
  • Soldering iron & accessories
  • Jumper cables

Software

This code currently uses OpenAI's models to turn the image into a poem. It also uses thermal printer drivers from Adafruit's thermal printer Python library.

You'll need to get your own OpenAI account & API key. Each request costs a couple of cents.

Currently, the main.py script running on the Pi: - Takes a photo when you click the shutter button - Sends the photo to GPT-4 Vision to caption the photo - When we receive the caption, we ask GPT-4 to turn the caption into a poem - When we receive the poem, print the poem out on thermal receipt printer

Putting it all together

This was adapted from the following tutorials: - Instant Camera using Raspberry Pi and Thermal Printer - Networked Thermal Printer using Raspberry Pi and CUPS

Part 1. Check that your Raspberry Pi & camera works

  1. Connect your Raspberry Pi to your Camera module.

  2. Insert your SD card with a fresh install of any Raspberry Pi OS onto the Pi.

  3. Connect your Pi to a monitor via mini HDMI.

  4. Plug in power. You should see a green light on the Pi, and a start-up screen on the monitor.

  5. Once the Pi is on, open up the Terminal on your Pi to start making changes.

  6. Set up Raspberry Pi hardware to take Camera & Serial inputs:

sudo raspi-config
  1. You'll want to adjust the following settings:

    • Glamor: ON (for Camera setup on newer versions of Raspbian OS)
    • Serial Port ON (lets you access receipt printer inputs)
    • Serial Console OFF (idk what this does)

    Restart the system as needed.

[Tutorial TODO: include a basic camera test script & show desired behavior]

Part 2. Check that your printer works

  1. Update the system and install requirements. I'm not sure you even need all of these; I can go over these again later and trim out the unnecessary ones.
$ sudo apt-get update
$ sudo apt-get install git cups build-essential libcups2-dev libcupsimage2-dev python3-serial python-pil python-unidecode
  1. Install some software required to make the Adafruit Thermal Printer work.
$ cd
$ git clone https://github.com/adafruit/zj-58
$ cd zj-58
$ make
$ sudo ./install
  1. Clone this repo, which contains our Poetry Camera software:
$ cd
$ git clone https://github.com/carolynz/poetry-camera-rpi.git
  1. Set up your thermal printer, connecting it to power and your Pi. See diagram and instructions in this tutorial. Test that it works. Pay attention to your printer's baud rate (e.g. 19200). We will use this later on.

  2. Open our `poetry-camera-rpi

Core symbols most depended-on inside this repo

println
called by 45
Adafruit_Thermal.py
writeBytes
called by 35
Adafruit_Thermal.py
write
called by 15
Adafruit_Thermal.py
timeoutSet
called by 10
Adafruit_Thermal.py
justify
called by 10
Adafruit_Thermal.py
setLineHeight
called by 7
Adafruit_Thermal.py
setPrintMode
called by 6
Adafruit_Thermal.py
unsetPrintMode
called by 6
Adafruit_Thermal.py

Shape

Method 52
Function 21
Class 1

Languages

Python100%

Modules by API surface

Adafruit_Thermal.py53 symbols
main.py9 symbols
testbutton.py4 symbols
main-knob.py4 symbols
main-cardboard.py3 symbols
wraptext.py1 symbols

For agents

$ claude mcp add poetry-camera-rpi \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page