So I got a Raspberry pi and I've been playing around with it for a couple days now. I'm making a "camera" program where you press a button on a breadboard, it takes a picture using fswebcam, and it saves it to a flash drive. I am on Raspbian. This is my code:
import os
import random
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(2, GPIO.IN)
#I know this next part looks a little weird, but in Raspbian every time you take out a flash drive it keeps a folder, then when you put the drive back in it calls it a slightly renamed version which messes up my code, and this next part will erase all the weird folders that have no use so that the flash drive will still be called FLASHDRIVE.
os.system("cd /")
os.system("cd /media")
#I hope the previous line worked,
os.system("sudo rm -rf *")
#The following function will wait until the buton is pressed:
def waitforbutton():
if(GPIO.input(2) == False):
return True
temp = waitforButton()
#The program will save the image as a random number.jpg
imgname = str(random.random) + ".jpg"
os.system("fswebcam /media/FLASHDRIVE/" + imgname)
print("Picture taken")
But, when I type:
sudo python camera.py
into the terminal, it prints a GPIO warning message and then this:
sh: 1: cannot open built-in: No such file
picture taken
And then if I run the program again, it says:
python: can't open file 'camera.py': [Errno 2] No such file or directory
Please help!!!!!