Close

Run Script with Button Press

A project log for CardToCloud: The Quick Photo Uploader

A device that will automatically upload photos and videos from a SD card directly into connect cloud storage.

brettbuildsBrettBuilds 01/13/2017 at 00:270 Comments

This function is crucial in order for the user to determine when the program is run. Followed this schematic minus the LED portion:

Here is the code, I put the function in the root directory:

import mraa
import time
import os
button = mraa.Gpio(20)
#set GPIO 20 to input mode
button.dir(mraa.DIR_IN)
while True:
	print "P8 state:", button.read()
	if (button.read() == 1):
		os.system("python root/uploadersd.py")
		break
	time.sleep(1)

Currently running script in the top level with python root/button.py

Successfully monitors button with 1 sec scans then runs the upload script when the button is pressed. The plan is to now make this program run at start up so the device is automatically looking for that button press to start the upload.

Discussions