I have a Pi hooked up to the output and reset nodes of an NOR gate S-R latch. For those of you who don't know what that is, basically I have an input in GPIO pin 11 that goes high (3.2V) whenever the latch is triggered. I then have an output in pin 12 (standard numbering not broadcom) that is supposed to go high once the Pi has detected the latch, which causes the latch to reset and the cycle can start again.
The whole point of this is to detect when the camera takes an image, use the pi to extract the time when the image was taken and write it to a text file. The problem is my program seems to be having difficulties detecting when the latch is high
using namespace std;
void interrupt(void);
struct timeval curTime;
char dateiname[256] = "";
int i=0;
int milli;
int seconds_in_day;
char buf[255];
ofstream myfile;
int main(int argc, char *argv[]){
wiringPiSetup();
time_t t = time(0);
struct tm * now = localtime(&t);
//Create and open file
sprintf(dateiname, "/home/raspbian/Desktop/%02d%02d%02d_%02d_%02d.txt",
now -> tm_year+1900,
now -> tm_mon+1,
now -> tm_mday,
now -> tm_hour,
now -> tm_min);
myfile.open(dateiname);
//write heading to file before loop
myfile << "picture, System Time" << endl;
//Set 11 & 12 as input/ output
pinMode(11, INPUT);
pullUpDnControl(11, PUD_DOWN);
pinMode(12, OUTPUT);
pullUpDnControl(12, PUD_DOWN);
//make sure 12 is low
digitalWrite(12, LOW);
digitalWrite(12, HIGH);
digitalWrite(12, LOW);
while(1){
wiringPiISR(11, INT_EDGE_RISING, &interrupt);
}
fclose(f);
return(0);
}
void interrupt(void){
i=i+1;
gettimeofday(&curTime, NULL);
milli = curTime.tv_usec / 1000; //Get time in milliseconds
seconds_in_day = curTime.tv_sec % 86400; //Get seconds since midnight
sprint(buf, "%d %d.%d", i, seconds_in_day, milli); //Write to file
myfile << buf << endl;
//send out reset signal
digitalWrite(12, LOW);
digitalWrite(12, HIGH);
digitalWrite(12, LOW);
}
Does anyone know what could be causing my program not to be detecting the input? My suspicion is that it has something to do with the interrupt but i'm not sure. Any help would be appreciated.
gpio readall
to check that the inputs change as expected.