Help! Designing a 3 push button circuit that sends emails.

The Raspberry Pi is a series of credit card-sized single-board computers developed in the United Kingdom by the Raspberry Pi Foundation to promote the teaching of basic computer science in schools and developing countries.

Post Reply
User avatar
/RaspberryPi
Corporate
Posts: 2449
Joined: Wed Jun 05, 2019 1:29 am

Help! Designing a 3 push button circuit that sends emails.

Post by /RaspberryPi »

Hi guys! First time posting here.
I'm in a bit of panic mode because I need to deliver a project this Wednesday and I'm having issues with my coding. As the title says, I'm using a circuit of three push buttons and my intention is that when they are pressed, they send a preconfigured email. I am completely new to Python so had to learn on my own, and the code that I have is a mix of the knowledge I got + code I saw on the Internet. I tested that the circuit works fine with the aid of another code I created, so I'm positive the error is in the coding. This is what I came up with
import RPi.GPIO as GPIO from time import sleep GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) import smtplib def send_mail(subject): gmail_user = 'x' gmail_password = 'x' send_to = 'x' try: server = smtplib.SMTP_SSL(' smtp.gmail.com', 465) server.login(gmail_user, gmail_password) server.sendmail(gmail_user,send_to,subject ) server.quit() except: print('Error sending email') # emails mylist = [ "M1", "M2", "M3", ] # GPIO numbers buttons = [8,15,23] def buttonPressed(channel): print(mylist[channel-5], " (GPIO" + str(channel)+")"); send_mail(mylist[channel-5]) print("set inputs and event detection") for x in buttons: GPIO.setup(x, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.add_event_detect(x, GPIO.FALLING, callback=buttonPressed, bouncetime=300) print("wait for a button to be pressed...") while True: sleep(0.5)
I'm positive my issue is with the second part, since whenever I push a button it either doesn't even recognize I did it, or says there's a problem with this line (
print(mylist[channel-5], " (GPIO" + str(channel)+")"); )
Can anyone help? Thank you again!

submitted by /u/Fenryla
[link] [comments]

More...
Post Reply

Return to “Raspberry Pi Forum”