Raspberry GPIO email script

This is the place for queries that don't fit in any of the other categories.

Raspberry GPIO email script

Postby kawa_j » Sat Jan 11, 2014 11:24 pm


I made a simple script that sends me an email when the raspberry detects a rising signal on a gpio input
Between the switch and the gpio i have mounted a resistor (1K ohm all connections are soldered) to prevent the gpio from flaoting
Script works well but when it is up and running for about 15min the RPI detects a rising signal?

Can someone help me out?

greets kawa

Code: Select all
import smtplib
import time

def sendemail(from_addr, to_addr_list, cc_addr_list,
subject, message,
login, password,
header = 'From: %s\n' % from_addr
header += 'To: %s\n' % ','.join(to_addr_list)
header += 'Cc: %s\n' % ','.join(cc_addr_list)
header += 'Subject: %s\n\n' % subject
message = header + message

server = smtplib.SMTP(smtpserver)
problems = server.sendmail(from_addr, to_addr_list, message)

import RPi.GPIO as GPIO
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(24, GPIO.OUT, initial=False) #Siren pin setup
GPIO.wait_for_edge(23, GPIO.RISING)
print "\nRising edge ALARM"
sendemail(from_addr = '@gmail.com',
to_addr_list = ['@gmail.coml'],
cc_addr_list = [''],
subject = 'ALARM',
message = 'alarm',
login = '@gmail.com',
password = '****')

GPIO.output(24, True)
except KeyboardInterrupt:
GPIO.cleanup() # clean up GPIO on CTRL+C exit
GPIO.cleanup() # clean up GPIO on normal exit
Last edited by micseydel on Sat Jan 11, 2014 11:26 pm, edited 1 time in total.
Reason: Code tags, locked OP.
Posts: 1
Joined: Sat Jan 11, 2014 11:21 pm

Re: Raspberry GPIO email script

Postby micseydel » Sat Jan 11, 2014 11:30 pm

I edited your post to include code tags, and afterward realized there isn't any indentation.

You need to repost your code in code tags with indentation. You should actually read this whole post.
Join the #python-forum IRC channel on irc.freenode.net!
User avatar
Posts: 1179
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Raspberry GPIO email script

Postby Marbelous » Tue Jan 14, 2014 5:12 pm

I would need to see your circuit but my first suggestion in any case would be to reverse your logic. Traditionally, logic circuits are active low due to the potential (Ha) for floating you mentioned. Use a 10K (or so) to pull your pin high and then your sensor or switch can ground it and you'll have a more reliable response. Your way should work fine as well though... Have you measured the line with a voltmeter?

BTW, do be careful if you're using the GPIO pins directly. They are 3.3V and since they're connected directly to the BroadCom IC you can smoke it if you wire thing wrong.
Posts: 110
Joined: Fri May 31, 2013 8:12 pm

Return to General Coding Help

Who is online

Users browsing this forum: snippsat and 3 guests