May-22-2019, 02:26 PM
hello ,
can someone explain why my code is stuck on loop?
even if I don't press the button it run the button_callback function (like I press the button)
I use the configuration from here (very simple one)
and this is the code :
I replace the resistor\cables - the same resualt .
want to make sure the problem is not in the code
Thanks ,
can someone explain why my code is stuck on loop?
even if I don't press the button it run the button_callback function (like I press the button)
I use the configuration from here (very simple one)
1 |
https: / / raspberrypihq.com / use - a - push - button - with - raspberry - pi - gpio / |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
from twilio.rest import Client import socket #Import udp import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library import json # import json read\write import time import logging def button_callback(channel): print ( "Button was pushed!" ) CurrentTime = str (time.ctime()) MESSAGE = (CurrentTime + " Test" ) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP sock.sendto(MESSAGE.encode(), (UDP_IP, UDP_PORT)) print (MESSAGE) whatsupp() logging.basicConfig(filename = '/home/pi/Desktop/message.log' ,level = logging.DEBUG) logging.debug(MESSAGE) time.sleep( 1 ) def whatsupp(): account_sid = "********" auth_token = "********" client = Client(account_sid, auth_token) message = client.messages.create( to = "whatsapp:+12346578912329" , from_ = "whatsapp:+14155299999" , body = "test" ) print (message.sid) UDP_IP = "10.0.0.51" UDP_PORT = 9051 GPIO.setwarnings( False ) # Ignore warning for now GPIO.setmode(GPIO.BOARD) # Use physical pin numbering GPIO.setup( 10 , GPIO.IN, pull_up_down = GPIO.PUD_DOWN) # pin 10 to be an input pin and set initial value to be pulled low (off) GPIO.add_event_detect( 10 ,GPIO.RISING,callback = button_callback) # Setup event on pin 10 rising edge message = input ( "Press enter to quit\n\n" ) # Run until someone presses enter GPIO.cleanup() # Clean up |
want to make sure the problem is not in the code
Thanks ,