embeded/raspberry pi2015. 7. 18. 22:16

초음파 관련 루틴을 while로 처리해서

오차가 있을것으로 생각되다 보니..

인터럽트 처리방식 검색...


gpio 유틸에도 존재는 한다.

gpio edge <pin> rising/falling/both/none

This enables the given pin for edge interrupt triggering on the rising, falling or both edges. (Or none which disables it)

[링크 : http://wiringpi.com/the-gpio-utility/] 


python 버전

GPIO.add_event_detect(17, GPIO.FALLING, callback=my_callback, bouncetime=300)  GPIO.add_event_detect(23, GPIO.FALLING, callback=my_callback2, bouncetime=300)  

[링크 : http://raspi.tv/2013/how-to-use-interrupts-with-python-on-the-raspberry-pi-and-rpi-gpio-part-3] 


c 버전

void myInterrupt(void) {

   eventCounter++;

}


int main(void) {

  if (wiringPiSetup () < 0) {

      fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno));

      return 1;

  }


  // set Pin 17/0 generate an interrupt on high-to-low transitions

  // and attach myInterrupt() to the interrupt

  if ( wiringPiISR (BUTTON_PIN, INT_EDGE_FALLING, &myInterrupt) < 0 ) {

      fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno));

      return 1;

  }


  // display counter value every second.

  while ( 1 ) {

    printf( "%d\n", eventCounter );

    eventCounter = 0;

    delay( 1000 ); // wait 1 second

  }


  return 0;

}

[링크 : http://cs.smith.edu/dftwiki/index.php/Tutorial:_Interrupt-Driven_Event-Counter_on_the_Raspberry_Pi] 



Posted by 구차니