Fubarino SD -attachInterrupt( )-help-please

Post Reply
Omnimusha
Posts: 22
Joined: Thu May 23, 2013 3:30 am

Fubarino SD -attachInterrupt( )-help-please

Post by Omnimusha » Sun Jul 28, 2013 2:45 am

Hi, I have connected in this way and with this code, but does not work,
I'm doing wrong?

attachInterrupt function (interrupt, function, mode), the interrupt, numbers 0 (pin 2) or, interrupt, numbers 0 (pin 0)?

Code: Select all

volatile uint8_t state = LOW;


void setup()
{
  Serial.begin(9600);
  attachInterrupt(0, rpm, RISING );
}

void loop()
{
  
}

void rpm()
{
  state = !state;
  Serial.println(state);
}
http://sia1.subirimagenes.net/img/2013/ ... 375227.png
Image

jmlynesjr
Posts: 149
Joined: Sun May 27, 2012 5:49 pm
Location: Lakeland, Florida USA

Re: Fubarino SD -attachInterrupt( )-help-please

Post by jmlynesjr » Sun Jul 28, 2013 3:06 am

The manual says Pin 0 is INT1, so try...
attachInterrupt(1, rpm, RISING );

Also, connect to Pin 0 not Pin2.

James

Omnimusha
Posts: 22
Joined: Thu May 23, 2013 3:30 am

Re: Fubarino SD -attachInterrupt( )-help-please

Post by Omnimusha » Sun Jul 28, 2013 4:01 am

jmlynesjr wrote:The manual says Pin 0 is INT1, so try...
attachInterrupt(1, rpm, RISING );

Also, connect to Pin 0 not Pin2.

James
not working :?

jmlynesjr
Posts: 149
Joined: Sun May 27, 2012 5:49 pm
Location: Lakeland, Florida USA

Re: Fubarino SD -attachInterrupt( )-help-please

Post by jmlynesjr » Mon Jul 29, 2013 2:55 am

Try this example from the SD wiki.

James


Code: Select all

// This sketch shows one way to use an external interrupt pin on
// the FubarinoSD board. (There are 5 external interrupts on PIC32:
// INT0 = Pin4, INT1 = Pin0, INT2 = Pin1, INT3 = Pin2, INT4 = Pin3)
// To run this test, you must take a wire and connect pin 12 to
// pin 0 (INT1). We then toggle pin 12 as an output to stimulate
// an external interrupt occuring on pin 0 (INT1).
// When a RISING edge is detected on INT1 (pin0), the attached
// function (intButton()) will get called. In that function we
// toggle the LED. So if you have the wire from pin 12 to pin 0,
// and you run this sketch, you should see the LED blinking.

#define pinSrc 12 // used as external interrupt stimulator
#define pinInt PIN_INT1  // The extern interrupt we choose to use (pin0)

void intHandle();

void setup() 
{
  digitalWrite(PIN_LED1, LOW);      // Start of with LED off
  pinMode(PIN_LED1, OUTPUT);        // Make LED pin an output
  pinMode(pinInt, INPUT);           // Interrupt pin must be an input
  digitalWrite(pinSrc, LOW);        // Simulator pin must start low
  pinMode(pinSrc, OUTPUT);          // And stim pin must be output too
  attachInterrupt(1, intHandle, RISING); // Register interrupt function on Int1
}

void loop() 
{
   digitalWrite(pinSrc, HIGH);      // Set stim pin high (triggers interrupt)
   delay(500);                      // wait half a second
   digitalWrite(pinSrc, LOW);       // Set stim pin low
   delay(500);                      // wait another half second
}

// This function gets called when an external interrupt occurs
void intHandle() 
{
  digitalWrite(PIN_LED1, !digitalRead(PIN_LED1));
}

Omnimusha
Posts: 22
Joined: Thu May 23, 2013 3:30 am

Re: Fubarino SD -attachInterrupt( )-help-please

Post by Omnimusha » Mon Jul 29, 2013 8:10 pm

now it works, thanks for your help James

jmlynesjr
Posts: 149
Joined: Sun May 27, 2012 5:49 pm
Location: Lakeland, Florida USA

Re: Fubarino SD -attachInterrupt( )-help-please

Post by jmlynesjr » Tue Jul 30, 2013 12:47 am

Great!

I'm guessing it was setting the interrupt pin as an input, which wasn't in your test code.

Glad you have it working now.

James

User avatar
Jacob Christ
Posts: 723
Joined: Sat May 28, 2011 6:34 am
Location: Southern California
Contact:

Re: Fubarino SD -attachInterrupt( )-help-please

Post by Jacob Christ » Tue Jun 14, 2016 7:26 pm

Be careful not to do what I did and use LOW or HIGH instead of FALLING or RISING!

Jacob

From Brian Schmalz:

The line:
attachInterrupt(COIN_COUNTER, intHandle, LOW);
needs to be changed to
attachInterrupt(1, intHandle, RISING);
and then it will work.

The reason for the two changes:

1) Even though you call "pinMode(COIN_COUNTER, INPUT);" with COIN_COUNTER being 0 (a pin number), you need to use the "interrupt number" (i.e. INT1, or "1") as an argument to attachInterrupt(). I don't know why, that's just the way it is. :-)

2) We don't have code right now to do LOW or HIGH level interrupts, we only support RISING or FALLING as edge types (second parameter).

If you make that change, it will work as you expect. If RISING is not the right value for your coin mech, use FALLING.
PONTECH Quick240 an industrial form factor platform for chipKIT and Arduino users.

Post Reply