The Code

Plug in and connect your pi to a display. Once it has started up, open terminal and run this command:

sudo raspi-config

camera_2018-02-17-113210_1920x1200_scrot.png

A window like this should pop up in your terminal window.

camera_2018-02-17-113225_1920x1200_scrot.png

Use your arrow keys to move the selector to 'Interfacing Options' and press Enter. This should show up.

camera_2018-02-17-113235_1920x1200_scrot.png

Press Enter to select Camera. A Yes or No screen should show up. Press Yes. You will be directed to the first page.

camera_2018-02-17-113246_1920x1200_scrot.png

Use the left and right arrow keys to select 'Finish'

Great! you have now enabled the camera function! Now let's setup the Dropbox uploader so we can receive our files. In terminal, run the following commands:

sudo apt-get update
sudo apt-get install -y curl
cd ~
git clone https://github.com/andreafabrizi/Dropbox-Uploader.git
cd Dropbox-Uploader
chmod a+x dropbox_uploader.sh
sudo cp dropbox_uploader.sh /usr/local/bin/dropbox_uploader

Once you have that all installed, you should be able to run the script. Try it out:

dropbox_uploader

After you run that command, you should see the following:

Dropbox Uploader v1.0
Andrea Fabrizi - [email protected]

Usage: /usr/local/bin/dropbox_uploader [PARAMETERS] COMMAND...

Commands:
	 upload   <LOCAL_FILE/DIR ...>  <REMOTE_FILE/DIR>
	 download <REMOTE_FILE/DIR> [LOCAL_FILE/DIR]
	 delete   <REMOTE_FILE/DIR>
	 move     <REMOTE_FILE/DIR> <REMOTE_FILE/DIR>
	 copy     <REMOTE_FILE/DIR> <REMOTE_FILE/DIR>
	 mkdir    <REMOTE_DIR>
	 list     [REMOTE_DIR]
	 monitor  [REMOTE_DIR] [TIMEOUT]
	 share    <REMOTE_FILE>
	 saveurl  <URL> <REMOTE_DIR>
	 search   <QUERY>
	 info
	 space
	 unlink

Optional parameters:
	-f <FILENAME> Load the configuration file from a specific file
	-s            Skip already existing files when download/upload. Default: Overwrite
	-d            Enable DEBUG mode
	-q            Quiet mode. Don't show messages
	-h            Show file sizes in human readable format
	-p            Show cURL progress meter
	-k            Doesn't check for SSL certificates (insecure)
	-x            Ignores/excludes directories or files from syncing. -x filename -x directoryname. example: -x .git

For more info and examples, please see the README file.

If you don't get this message, please check that you have followed the steps before carefully.

Now that you have the command set up, it's time to connect your dropbox account. Run the following command to set it up.

dropbox_uploader upload

It will realize that there isn't an account associated with it, and it will start the setup. You should see somthing like this:

This is the first time you run this script.

1) Open the following URL in your Browser, and log in using your account: https
://www.dropbox.com/developers/apps
2) Click on "Create App”, then select "Dropbox API app”
3) Now go on with the configuration, choosing the app permissions and access re
strictions to your DropBox folder
4) Enter the "App Name” that you prefer (e.g. MyUploader6293443213380)
Now, click on the "Create App” button.

when your new App is successfully created, please type the
App Key, App Secret and the Permission type shown in the confirmation page:

# App key: 

Follow the instructions and open to the https://www.dropbox.com/developers/apps URL. To make it easier, open the URL on your Pi. Sign in if you haven't already. The page should look like this:

Click 'Create app' and choose the following options:

Choose API: Dropbox API

Choose the type of access you need: App folder

Name your app: Anything you want!

Press 'Create app' again.

You should be directed to a page like this:

Please Note: These Keys are fake.

On this page, you will need the App Key and the App Secret. First, copy the app key and paste it into the terminal running the setup. Press Enter. Then, click show on the App Secret and copy that code. Paste it in and press enter again. This is what you should see:

[email protected] ~/Dropbox—Uploader $ dropbox_uploader upload
This is the first time you run this script.

1) Open the following URL in your Browser, and log in using your account: https://www.dro
pbox.com/developers/apps

2) Click on "Create App", then select "Dropbox API app"

3) Now go on with the configuration, choosing the app permissions and access restrictions

to your DropBox folder
4) Enter the "App Name" that you prefer (e.g. MyUploader6293443213380)

Now, click on the "Create App" button.

when your new App is successfully created, please type the
App Key, App Secret and the Permission type shown in the confirmation page:

# App key: qckrvrx07ng5tax
# App secret: mkqlyir6djpclib

Permission type:
App folder [a]: If you choose that the app only needs access to files it creates
Full Dropbox [f]: If you choose that the app needs access to files already on Dropbox

# Permission type [a/f]: f

> App key is qckrvrx07ng5tax, App secret is mkqlyir6djpclib and Access level is Full Dro
box. Looks ok? [y/n]: y

If the key looks ok, press and then press enter. It will ask you to go to a URL. Copy the URL and paste them into your browser. It may ask you which dropbox to connect to if you have multiple, and then say Success! Press enter in terminal and you have now connected your account! 

Now let's get the python code running! On the Pi, make a folder on the desktop called mcselfie. It must be the exact name so that the code can run. Open a new tab in your Pi's web browser and go to this shortlink: adafru.it/selfiecode. Extract the .zip file and drag the .py file into the mcselfie folder on your desktop.

Open up the python file in Thonny. You should see the following code:

from picamera import PiCamera
from gpiozero import Button
from time import sleep
import time, os
button = Button(4, pull_up=False,)
while True:
    button.wait_for_press()
    name = (time.strftime("%y-%b-%d_%H:%M:%S"))
    fname = "/home/pi/Desktop/mcselfie/" + "Selfie " + name + ".jpg"
    cmd = "/home/pi/Dropbox-Uploader/dropbox_uploader.sh upload /home/pi/Desktop/mcselfie " + "/Selfie_" + name
    command = "/home/pi/Dropbox-Uploader/dropbox_uploader.sh upload" + fname + "/mcselfie"

    with PiCamera() as camera:
        camera.resolution = (1500,1080)
        camera.start_preview()
        sleep(3)
        camera.stop_preview()
        camera.capture(fname)
        sleep(1)
        os.system(cmd)

Press the green 'Play' button to run the code. You should see the following in the console:

>>> %Run mcselfie.py

Press the button to take a picture. The red light on the camera should turn on, and then turn off once it has finished uploading. You have 3 seconds to pose for the picture. Go to your dropbox, click apps, and click the app name. Inside the app files should be a folder called Selfies. Open it up and your selfies should show up.

If the camera light doesn't turn on, check that the button is connected correctly. If you get an error in the console when you press the button, make sure that the camera is connected, and restart the Pi and run the file again. If you still get the error, ping me in the discord server. 

To make the camera porible, unplug the power and connect a portible battery to the Pi. Note that every time to restart the Pi, you have to open and run the mcselfie.py file again.

This guide was first published on Feb 18, 2018. It was last updated on Dec 09, 2018. This page (The Code) was last updated on Feb 17, 2018.