i am trying to create a doorbell with raspberry pi zero. When you press the doorbell pygame will play the doorbell sound, And picamera will take a picture and will send it to telegram.
At the first place it looks like it's working but after a few minutes it crash/freeze. i cannot communicate with my other computer to the pi anymore with SSH,
does anyone have idea what i am doing wrong? thanks!
what i have try: Reinstalled rasbian lite (fresh install) searching google.
import telepot
import pygame
from picamera import PiCamera
import RPi.GPIO as GPIO
camera = PiCamera()
bot = telepot.Bot('THIS IS MY TOKEN')
ring = 'tones/Apartment-ding-dong-sound.mp3'
_chatid = -00000000
pygame.mixer.init()
pygame.mixer.music.load(ring)
bot.sendMessage(_chatid,'Hello, i am online now.')
def sendpic():
try:
camera.resolution = (1024, 768)
camera.capture('snapshots/snapshot.jpg')
photo = open('snapshots/snapshot.jpg', 'rb')
bot.sendPhoto(_chatid, photo)
del photo
except:
print('Unknow error')
GPIO.setmode(GPIO.BCM)
GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
def buttonPressed(value):
if GPIO.input(22) == GPIO.LOW:
pygame.mixer.music.play()
sendpic()
GPIO.add_event_detect(22, GPIO.FALLING, callback=lambda x: buttonPressed(150), bouncetime=1000)
while True:
pass