Portable Instant Pi Camera
by Action-Script in Circuits > Cameras
10382 Views, 131 Favorites, 0 Comments
Portable Instant Pi Camera
I had in mind the idea of creating a series of photographs inspired by the golden age of polaroid and analog photography.
A big part of my creative process is defined by creating my own tools, so I was not really atracted by the idea of just buying a polaroid and start shooting.
This idea is not brand new, there are already several photo camera projects using Raspberry Pi and a thermal printer. But for this camera I wanted to do it on my own way. So I took inspiration from all those project and I made some changes.
All other similar projects I've seen before, they use a Raspberry Pi 2 and a wide lens (surveillance) camera module for the Pi.
For this camera I went for a Raspberry Pi Zero W and a medium-big focal length lens.
The Pi Zero W has the same footprint than the original Pi Zero, which is quite small and that is great. But the W version, includes the camera port and onboard Wifi along with many other features.
Most of the Pi camera modules comes with a wide angle lense. I chose a M12 lens, with a field of view of 40° which would be similar than a ~45 mm focal length in a full frame camera, because the image would be more natural not so distorted and similar to classic photography.
BTW, thanks to the wifi connectivity I can remote shooting.
Components and Materials
Components and parts
- 1x Raspberry Pi Zero W raspberrypi.org/raspberry-pi-zero-w
- 1x Mini TTL Thermal Printer dafruit.com/product/597
- 1x Raspberry Pi Camera Module
- 1x Mini Camera (CSI) 15 pin Cable shop.pimoroni.com/cable-raspberry-pi-zero-edition
- 1x M12 Camera Lens (any focal distance you want)
- 1x M12 Board Lens Holder m12lenses.com/M12-Lens-Holder-Plastic-p
- 1x Push botton
- 1x 5v / 3.5A Power bank (min 3A) amazon.de/RAVPower5v3A
- 1x 4700uF Electrolytic Capacitor
- 1x USB Adapter Right Angle A Male to A Female
- 1x 2.1mm Jack Adapter to USB
- 1x Adapter - 2.1mm jack to screw terminal block adafruit.com/368
Wiring up
- 1x Break-away strip MALE header
- 1x Break-away strip FEMALE header
- 3x 2 pin connector (I use Dupont Connector)
- Perfboard
- Electric wire
Assembly
- 2x Screw M3 x 6mm (6mm ~ 10mm)
- 2x Square Nuts (M3 1,8mmx5,5mm)
- 2x Screw M2 x 6mm (6mm ~ 10mm)
Printing
- Thermal paper Rolls (57mm)
Extras
- 8GB SD card (for the raspberrypi)
- Mini HDMI adapter (for connecting the Zero W to a monitor)
- Mini USB to USB (for connecting the Zero W to a keyboard)
- 5v USB Charger
Used Tools
- Software
- Fusion 360 autodesk.com/fusion-360
- Raspbian Jessie Lite raspberrypi.org/downloads/raspbian
- ImageMagick www.imagemagick.org
- zj-58 CUPS by adafruit github.com/adafruit/zj-58
- Hardware
- Prusa i3 mk3 prusa3d.com/original-prusa-i3-mk3
- Cable crimper (SN-28B)
- Wire Stripper tool
- Digital Caliper
- Multiple screwdrivers
Software Setup and Code
For this step you may require an USB keyboard and an HDMI monitor.
Would be also helpful to install the camera module into the Raspberry Pi so you can test and check everything works.
System Setup
Run the raspi-config utility:
$ sudo raspi-config
For this project this options are required:
- Interfacing Options -> Enable Camera
- Interfacing Options -> Disable Serial
- Advanced Options -> Expand Filesystem
Use raspi-config to set up the Wi-fi connection. You will need network connection to upgrade the system and download the required software.
- Network Options -> Wi-fi
You can also Enable SSH to access remotly to the system and do quick changes.
- Interfacing Options -> Enable SSH
Install Software
The process for this steps was based on this tutorial:
learn.adafruit.com/instant-camera-using-raspberry-pi-and-thermal-printer
$ sudo apt update
$ sudo apt install git cups wiringpi build-essential libcups2-dev libcupsimage2-dev
Install the raster filter for CUPS from the adafruit github
$ git clone https://github.com/adafruit/zj-58
$ cd zj-58 $ make $ sudo ./install
Install and set the printed as default at the CUPS system.
Change the “baud” value to 9600 or 19200 as required for your printer. (Mine was 19200)
$ sudo lpadmin -p ZJ-58 -E -v serial:/dev/ttyAMA0?baud=19200 -m zjiang/ZJ-58.ppd $ sudo lpoptions -d ZJ-58<br>
Camera script
$ sudo apt-get install imagemagick
Using imagemagick to improve the contrasts and setting the default contrast and brightness of the camera, the shooting order looks like:
raspistill -t 200 -co 30 -br 75 -w 512 -h 388 -n -o - | convert - -grayscale Rec709Luminance -contrast jpg:- | lp
This are the parameters I found works the best for my case, but you may like to modify those values.
I use the same press button for shooting aphot and and shoting down the system
The scripts sepatared a single press from a long press (+4 sseconds) action.
camera.sh
#!/bin/bash SHUTTER=20 # Initialize GPIO states gpio -g mode $SHUTTER up while : do # Check for shutter button if [ $(gpio -g read $SHUTTER) -eq 0 ]; then # Must be held for 4+ seconds before shutdown is run... starttime=$(date +%s) while [ $(gpio -g read $SHUTTER) -eq 0 ]; do if [ $(($(date +%s)-starttime)) -ge 5 ]; then shutdown -h now echo "power off" # Wait for user to release button before resuming while [ $(gpio -g read $SHUTTER) -eq 0 ]; do continue; done fi done if [ $(($(date +%s)-starttime)) -lt 2 ]; then echo "Click shut" raspistill -t 1800 -co 30 -br 75 -w 512 -h 388 -n -o - | convert --grayscale Rec709Luminance -contrast jpg:- | lp # date +"%d %b %Y %H:%M" | lp fi sleep 1 fi sleep 0.3 done <br>
Set automatically the script to start when the system boots.
Modify the file /etc/rc.local and the following command before the final “exit 0” line:
sh /home/pi/camera.sh
Use the path where you saved the script file.
Raspberry Pi Zero W enable serial compatibility
pi3-miniuart-bt switches the Raspberry Pi 3 and Raspberry Pi Zero W Bluetooth function to use the mini UART (ttyS0), and restores UART0/ttyAMA0 to GPIOs 14 and 15.
To disable onboard Bluetooth and restore UART0/ttyAMA0 over GPIOs 14 & 15, modify:
$ sudo vim /boot/config.txt
Add to the end of the file
dtoverlay=pi3-disable-bt
It is also necessary to disable the system service that initialises the modem so it doesn't use the UART:
$ sudo systemctl disable hciuart
You can find more info at: https://www.raspberrypi.org/documentation/configur...
3D Printed Case
The case of the camera is designed to keep a compact small footprint where the components fits and snaps each other so there not not much screw work on it.
The design is divided on 3 parts:
- The base, where the power bank is allocated.
- The main box, where the Pi board, the printer and most of the cabling takes place.
- The lens cone, that hosts the camera lens.
The main box and the lens cone are optimized for printing and does not require support structure. The base, instead, is printed on a single piece using internal support material. I wanted to create an strong piece to support the camera structure.
I included the stl files, so you can print it or modify the design.
Wire It Up
First thing to do is soldering the male pin headers to the IO ports of the Raspberry Pi.
Once you have it done you can go ahead and plug the pi into a breadboard and you would be ready to test the setup.
For wiring up the components, I splitted the connections using 2 pin crimp housings. So during the assembly process, the components can be individually attached to the case and connected afterwards without complication. Also helps to replace the parts in case of damage or for upgrading the hardware.
Take the barrel jack and connect the 4700uF capacitor to the + and - terminals. This will help keep the voltage stable when the thermal printer is operating. Make sure the negative (shorter) leg of the capacitor is attached to the negative pole of the terminal and not the other way.
Connect to the barrel jack and the capacitor, the cables for the printer power supply and the Raspberry Pi Zero W.
For feeding the Pi, I soldered the +5V to the PP1 and the ground from the power supply to the PP6 in the backside of the board, right below the power USB.
I took a piece of perfboard and solded on it 2 stripes of female pin headers so first the Pi IO pins. On that perftboard you can connect the pushbutton and the printer data wires.
Connect the push button to the ground GND (pin 34) and the BCM 20 (pin 38)
For the printer follow this order:
- Printer GND -> Raspberry Pi GND (pin 6)
- Printer RX -> Raspberry Pi TXD (pin 8, BCM 14, UART Transmit)
- Printer TX -> Raspberry Pi RXD (pin 10, BCM 15, UART Receive)
Check the Raspberry Pi IO for more information: https://pinout.xyz/pinout/pin10_gpio15
Assembly
The assembly process is straightforward.
The power bank fits on the base of the case and does not move. But can be easily removed to be charged or replaced.
I printed few pins to attach the Raspberry Pi board to the case and to connect the lens come to the rest of the case as well.
There is not much room for all the cables and components. You have to organize the space, but everything fits inside.
For closing the case, the base and the main box has two tabs on the rear part that fits each other. On the front, there is a screw pocket to secure fix the box.