PiLaroid Camera—a Retro Polaroid Updated for Modern Times.

by vpiella28 in Circuits > Raspberry Pi

846 Views, 4 Favorites, 0 Comments

PiLaroid Camera—a Retro Polaroid Updated for Modern Times.

20240331_150243.jpg
20240331_150653.jpg
20240331_150543.jpg

Introducing my PiLaroid camera—a retro Polaroid updated for modern times. In the past, print prices were more affordable, and photos only garnered likes from those holding them. Why not upgrade it to directly upload to Instagram?

Supplies

Preparare Hardware

First, let's start with the hardware and software. I recommend connecting the Raspberry Pi to a screen with a keyboard and mouse for comfortable working.



Connect the camera and activate it. You have two options:

Go to Start > Preferences > Raspberry Pi Configuration > Interfaces > Camera.

Or use in terminal

sudo raspi-config > Interface > Legacy camera.


It's important to restart the Raspberry Pi for the changes to take effect.

In my case, I used a Raspberry Pi Zero W, which was not ideal—I realized this too late. Consequently, I had to handle hardware functions with Python and Instagram functionalities with Node.js. With the Pi Zero 2W, you should be able to do everything with Python, improving speed and simplicity.

Code for the Hardware

Open a terminal and run

sudo apt update
sudo apt install python3-pip python3-rpi.gpio

Create the hardware.py file on the Desktop.

import RPi.GPIO as GPIO
import subprocess
import time


# Set up GPIO pin for button
BUTTON_PIN = 19
GPIO.setmode(GPIO.BCM)
GPIO.setup(BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)


# Define debounce interval in seconds
DEBOUNCE_INTERVAL = 45  # Adjust as needed


# Variable to track last button press time
last_button_press_time = 0


# Function to capture photo and call Node.js script for uploading
def capture_and_upload():
    timestamp = time.strftime("%Y%m%d-%H%M%S")
    image_path = f"captured_image_{timestamp}.jpg"


    # Capture photo using Raspberry Pi camera module
    subprocess.run(["raspistill", "-o", image_path, "-rot", "90"])


    # Call Node.js script to upload image
    subprocess.run(["node", "upload_to_instagram.js", image_path])


# Callback function for button press
def button_callback(channel):
    global last_button_press_time


    # Get current time
    current_time = time.time()


    # Check if debounce interval has passed since last button press
    if current_time - last_button_press_time > DEBOUNCE_INTERVAL:
        print("Button pressed")
        capture_and_upload()
        last_button_press_time = current_time  # Update last button press time


# Set up event detection for button press
GPIO.add_event_detect(BUTTON_PIN, GPIO.FALLING, callback=button_callback, bouncetime=300)


print("Waiting for button press to capture photo...")


# Keep the script running
try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    GPIO.cleanup()

Install Node.js ( if not already installed)

you can check with (node --version) in terminal if not run:

sudo apt update
sudo apt install nodejs
sudo apt install npm
node --version
npm --version

We will need a instragram private library to upload the images

npm install instagram-private-api

Create the upload_to_instagram.js file on the Desktop.

const { IgApiClient } = require("instagram-private-api");
const fs = require("fs");
const util = require("util");


const IG_USERNAME = "--- YOUR INSTAGRAM USER ----";
const IG_PASSWORD = "--- YOUR INSTAGRAM PASSWORD----";


const readFileAsync = util.promisify(fs.readFile);


async function login() {
  const ig = new IgApiClient();
  ig.state.generateDevice(IG_USERNAME);
  await ig.account.login(IG_USERNAME, IG_PASSWORD);
  return ig;
}


async function uploadPhoto(ig, imagePath) {
  const imageBuffer = await readFileAsync(imagePath);


  const timestamp = new Date().toLocaleString();
  const caption = `Posted with PiLaroid #piladoid #raspberrypi at ${timestamp}`;


  const publishResult = await ig.publish.photo({
    file: imageBuffer,
    caption: caption,
  });
  console.log(publishResult);
}


// Main function to execute the login and upload process
(async () => {
  try {
    // Login to Instagram
    const ig = await login();
    // Upload a photo
    await uploadPhoto(ig, process.argv[2]);
  } catch (error) {
    console.error(error);
  }
})();

Let's Warm Up the Solder

vectors.jpg

Now, let's grab the soldering iron and start with the easy part. Solder the endstop switch with two wires as indicated in the Pin 19 and GND scheme.

Once done, you can test if everything is functioning correctly.

Let's Print Some Plastic

20240219_120359.jpg
20240219_120507.jpg
20240330_194923.jpg
20240330_194931.jpg
20240414_115146.jpg

Battery Holder

Raspberry Pi Case (sorry i lost the model that i used but i pick a generic one and i remove some part of the bottom to give the camera some extra space)

Pilaroid_Lense adaptor

Pilaroid_endstop Trigger


Now that everything is printed, let's begin the assembly. Use some instant glue to attach the lens adapter to the lens and let it dry. Also, affix the endstop to the case as shown in the image, and attach the endstop trigger to the button. Finally, secure the Raspberry Pi case to the lens adapter. Arrange the electronics to fit into the right positions.

Power Up

02_Mesa de trabajo 1.jpg
20240330_195154.jpg
20240330_195206.jpg

For the battery, solder according to the following diagram. BUT, it's crucial to check with a multimeter and adjust the power going to the Raspberry Pi to 5V. It's very important to do this with the Raspberry Pi disconnected to avoid damaging it.


Carefully drill two holes in the Polaroid case to accommodate the USB-C port and the switch. Take your time and mark the positions from the exterior using a pencil. 

Use a hot glue gun to glue the switch, battery charger, and battery holder into place, securing the electronics. You can fasten the camera and Raspberry Pi with a bit of tape.

Be attentive to the details and ensure everything is secure and well-positioned before proceeding. Good luck with the rest of your project! If you have more steps or need further guidance, feel free to ask.

Final Touches

Let's run our code when we start the Raspberry no?

sudo nano /etc/systemd/system/button_script.service

*Please check if the routes are correct in your case (pi, can be different in your case)

[Unit]
Description=Button Script Service
After=multi-user.target


[Service]
ExecStart=/usr/bin/python3 /home/pi/Desktop/hardware.py
WorkingDirectory=/home/pi/Desktop
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi


[Install]
WantedBy=multi-user.target

Reload systemd:

sudo systemctl daemon-reload

Enable the service to run at boot:

sudo systemctl enable button_script.service


Let's create some script to check multiple networks and connect by Wi-Fi automatically

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf


network={
  ssid="Network1SSID"
  psk="Network1Password"
}

network={
  ssid="Network2SSID"
  psk="Network2Password"
}


Configure wpa_supplicant to Automatically Connect:

Ensure that the wpa_supplicant service is enabled and running:

sudo systemctl enable wpa_supplicant
sudo systemctl start wpa_supplicant


And let's restart all

sudo systemctl restart networking


sudo reboot



What's Next?

First and foremost, I hope you've enjoyed the project! If you'd like to check out the Instagram account associated with this project, you can follow it here.

Next Steps:

I'm planning to incorporate a speaker to provide sound feedback after users take a photo and upload it to Instagram. I was thinking of using the nostalgic sound of old internet modems—what do you think about that idea?

Additionally, I want to repurpose the flash module. I have two options in mind:

  1. Replace it with LEDs so that every time a photo is taken, the LEDs simulate a flash effect.
  2. Attempt to reverse engineer the original electronics of the flash module and integrate them back into the project for an authentic experience.

Let me know your thoughts on these next steps!