0

I am trying to create code that should initiate an interrupt when gpio 21 is high, to take the binary data from the other two gpios and store it in a text file. The problem is that it doesn't take the interruption...

import time
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM) # formato para utilizar los pines de la rasberry

Clock = 21
Data1=23
Yb=24

flag=False
GPIO.setup(Clock,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(Data1,GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.setup(Yb,GPIO.IN,pull_up_down=GPIO.PUD_UP)

archivo = open("datos.txt", "a")  

contador=0

def captura (channel):
    flag=True
    contador=1
    
GPIO.add_event_detect(Clock, GPIO.RISING,callback=captura)

t=time.time()
while (time.time()-t<5):
    
    
    if flag==True:
      salida=str(int(GPIO.input(Data1)))
      salida=salida+' '+str(int(GPIO.input(Yb)))+'\n'
      flag=False
      archivo.write(salida)  #inte


archivo.close()
print(contador)

I add in method captura a counter to check if it works

contador=0

def captura (channel):
    flag=True
    contador=1
  • Is your question why `contador` is still 0 despite `captura` being called? – mkrieger1 May 22 '22 at 19:17
  • no, my question is why not there is no data stored in the text file. the counter is just to check that it works, sorry for my english i'm new – michael espin May 22 '22 at 19:34
  • `captura` is called but is not happen nothing – michael espin May 22 '22 at 19:35
  • Okay, alternatively, instead of `contator` we can also look at `flag`. The reason why no data is stored in the text file is that `flag` is `False`. So your question is why `flag` is `False` despite `captura` being called. – mkrieger1 May 22 '22 at 19:35
  • mmm, maybe i change value of ` flag= ()` empty variable and declare two varible global – michael espin May 22 '22 at 20:07

0 Answers0