Working fine on Arduino Yun

119 views
Skip to first unread message

Pat O'Brien

unread,
Sep 18, 2014, 9:14:38 AM9/18/14
to arduino-pincha...@googlegroups.com
Just wanted to let you know I installed the library on the Arduino Yun last night and have been getting pin change interrupts on digital pins 8 and 9. 

Since your project page only mentioned the Uno/Duemilanove, I didn't see another way to let you know that it's working on the Yun and the ATmega 32u4. 

Thanks!

Michael Schwager

unread,
Sep 18, 2014, 5:33:28 PM9/18/14
to arduino-pincha...@googlegroups.com

Great, thanks! I'll mention it.

--
You received this message because you are subscribed to the Google Groups "arduino-pinchangeint-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to arduino-pinchangeint...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Geert Kroezinga

unread,
Dec 14, 2014, 12:53:22 PM12/14/14
to arduino-pincha...@googlegroups.com
Hello Pat,

Can you paste your code? I have tried to use this library on an Arduino Yun and I can't get it to work...
Maybe I am doing something wrong... Would help a lot to compare with your working code

Wit kind regards,
Geert

Pat O'Brien

unread,
Jan 1, 2015, 8:09:31 PM1/1/15
to arduino-pincha...@googlegroups.com
I've moved on to Raspberry Pi for this project, so the code I'm pasting is a bit old, and I'm only pasting the bits that make sense. Hopefully you can tweak it from here.

#include <PinChangeInt.h>


#define PIN_ANEMOMETER  8      // Digital 8 for Anemometer (Wind speed) - uses PinChangeInt library
#define PIN_RAINGAUGE   9      // Digital 9 for rain bucket - uses Pin ChangeInt library


void setup() {
 
Serial.begin(9600);
  pinMode
(PIN_ANEMOMETER, INPUT_PULLUP); // input from wind meters windspeed sensor
  pinMode
(PIN_RAINGAUGE, INPUT_PULLUP); // input from wind meters rain gauge sensor
  digitalWrite
(PIN_ANEMOMETER, HIGH);
  digitalWrite
(PIN_RAINGAUGE, HIGH);
 
PCintPort::attachInterrupt(PIN_ANEMOMETER, countAnemometer, FALLING);
 
PCintPort::attachInterrupt(PIN_RAINGAUGE, countRainGauge, FALLING);
}


//=======================================================
// Interrupt handler for anemometer. Called each time the
// reed switch triggers (one revolution).
//=======================================================
void countAnemometer() {
 
Serial.print("Anemometer Interrupt");
}


//=======================================================
// Interrupt handler for rain gauge. Called each time the
// reed switch triggers (one bucket tip).
//=======================================================
void countRainGauge() {
 
Serial.print("Rain Interrupt");
}

J Pinto

unread,
Apr 12, 2015, 8:34:57 AM4/12/15
to arduino-pincha...@googlegroups.com

Thanks Pat. Great library!

For reference, I tested this on an Yun and only the digital pins 8, 9, 10 and 11 work as interrupts.

Digital pins 0 to 8, 12 and 13 do not work.

Just for thought... shouldn't 12 and 13 work, since they are both PORTB?

Regards to all,

J

J Pinto

unread,
Apr 12, 2015, 8:54:10 AM4/12/15
to arduino-pincha...@googlegroups.com
Reply to myself:

Actually D12 and D13 are not PORTB. Check the following image:

http://brewpi.com/wp-content/uploads/2012/12/BrewPi-Shield-Pin-Mapping.png

Is there any interest to extend this library for the atmega 32u4 used on the Yun?

J

Michael Schwager

unread,
Apr 12, 2015, 10:01:26 AM4/12/15
to arduino-pincha...@googlegroups.com
Actually I am deprecating this library in favor of the EnableInterrupt library. See https://github.com/GreyGnome/EnableInterrupt . It has atmega 32u4 support. However, I don't have any 32u4-based chips so if you could give me a bug report that would be great.t

--
You received this message because you are subscribed to the Google Groups "arduino-pinchangeint-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to arduino-pinchangeint...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
-Mike Schwager

J Pinto

unread,
Apr 12, 2015, 12:48:23 PM4/12/15
to arduino-pincha...@googlegroups.com

Thanks for the link.

I have a Yun, If you nee to check something I can make it for you.

Regarding the bug report, tell me what you need. I am not an advanced user, but can try my best to help.

I think the problem is a pin reference issue. See this: http://brewpi.com/wp-content/uploads/2012/12/BrewPi-Shield-Pin-Mapping.png

I used the following code to check on my yun.

#include <PinChangeInt.h>

// 1. any pin can interrupt expect  pin 12
// 2. pin 10 resets counter
// 4. pin 12 is beeper

#define PIN_INTERRUPTA0 A0
#define PIN_INTERRUPTA1 A1
#define PIN_INTERRUPTA2 A2
#define PIN_INTERRUPTA3 A3
#define PIN_INTERRUPTA4 A4
#define PIN_INTERRUPTA5 A5

#define PIN_INTERRUPT0 0
#define PIN_INTERRUPT1 1
#define PIN_INTERRUPT2 2
#define PIN_INTERRUPT3 3
#define PIN_INTERRUPT4 4
#define PIN_INTERRUPT5 5
#define PIN_INTERRUPT6 6
#define PIN_INTERRUPT7 7
#define PIN_INTERRUPT8 8
#define PIN_INTERRUPT9 9
#define PIN_INTERRUPT10 10
#define PIN_INTERRUPT11 11 // for reset
//#define PIN_INTERRUPT12 12 // used for beeper or led
#define PIN_INTERRUPT13 13

#define PIN_PIEZO  12  // for piezo or led

//OK pins 8, 9, 10, 11
// not OK pins 12, 13

volatile uint16_t nbInterrupts=0;

void setup() {
 
Serial.begin(9600);

// ANALOG PINS

  pinMode
(PIN_INTERRUPTA0, INPUT_PULLUP);
  digitalWrite
(PIN_INTERRUPTA0, HIGH);

  pinMode
(PIN_INTERRUPTA1, INPUT_PULLUP);
  digitalWrite
(PIN_INTERRUPTA1, HIGH);
 
  pinMode
(PIN_INTERRUPTA2, INPUT_PULLUP);
  digitalWrite
(PIN_INTERRUPTA2, HIGH);
 
  pinMode
(PIN_INTERRUPTA3, INPUT_PULLUP);
  digitalWrite
(PIN_INTERRUPTA3, HIGH);

  pinMode
(PIN_INTERRUPTA4, INPUT_PULLUP);
  digitalWrite
(PIN_INTERRUPTA4, HIGH);

  pinMode
(PIN_INTERRUPTA5, INPUT_PULLUP);
  digitalWrite
(PIN_INTERRUPTA5, HIGH);

 
PCintPort::attachInterrupt(PIN_INTERRUPTA0, countInterrupts, FALLING);
 
PCintPort::attachInterrupt(PIN_INTERRUPTA1, countInterrupts, FALLING);
 
PCintPort::attachInterrupt(PIN_INTERRUPTA2, countInterrupts, FALLING);
 
PCintPort::attachInterrupt(PIN_INTERRUPTA3, countInterrupts, FALLING);
 
PCintPort::attachInterrupt(PIN_INTERRUPTA4, countInterrupts, FALLING);
 
PCintPort::attachInterrupt(PIN_INTERRUPTA5, countInterrupts, FALLING);


// DIGITAL PINS

  pinMode
(PIN_INTERRUPT0, INPUT_PULLUP);
  digitalWrite
(PIN_INTERRUPT0, HIGH);

  pinMode
(PIN_INTERRUPT1, INPUT_PULLUP);
  digitalWrite
(PIN_INTERRUPT1, HIGH);

  pinMode
(PIN_INTERRUPT2, INPUT_PULLUP);
  digitalWrite
(PIN_INTERRUPT2, HIGH);

  pinMode
(PIN_INTERRUPT3, INPUT_PULLUP);
  digitalWrite
(PIN_INTERRUPT3, HIGH);

  pinMode
(PIN_INTERRUPT4, INPUT_PULLUP);
  digitalWrite
(PIN_INTERRUPT4, HIGH);

  pinMode
(PIN_INTERRUPT5, INPUT_PULLUP);
  digitalWrite
(PIN_INTERRUPT5, HIGH);

  pinMode
(PIN_INTERRUPT6, INPUT_PULLUP);
  digitalWrite
(PIN_INTERRUPT6, HIGH);

  pinMode
(PIN_INTERRUPT7, INPUT_PULLUP);
  digitalWrite
(PIN_INTERRUPT7, HIGH);

  pinMode
(PIN_INTERRUPT8, INPUT_PULLUP);
  digitalWrite
(PIN_INTERRUPT8, HIGH);

  pinMode
(PIN_INTERRUPT9, INPUT_PULLUP);
  digitalWrite
(PIN_INTERRUPT9, HIGH);

  pinMode
(PIN_INTERRUPT10, INPUT_PULLUP);
  digitalWrite
(PIN_INTERRUPT10, HIGH);

  pinMode
(PIN_INTERRUPT11, INPUT_PULLUP);
  digitalWrite
(PIN_INTERRUPT11, HIGH);

  pinMode
(PIN_INTERRUPT13, INPUT_PULLUP);
  digitalWrite
(PIN_INTERRUPT13, HIGH);

 
PCintPort::attachInterrupt(PIN_INTERRUPT0, countInterrupts, FALLING);
 
PCintPort::attachInterrupt(PIN_INTERRUPT1, countInterrupts, FALLING);
 
PCintPort::attachInterrupt(PIN_INTERRUPT2, countInterrupts, FALLING);
 
PCintPort::attachInterrupt(PIN_INTERRUPT3, countInterrupts, FALLING);
 
PCintPort::attachInterrupt(PIN_INTERRUPT4, countInterrupts, FALLING);
 
PCintPort::attachInterrupt(PIN_INTERRUPT5, countInterrupts, FALLING);
 
PCintPort::attachInterrupt(PIN_INTERRUPT6, countInterrupts, FALLING);
 
PCintPort::attachInterrupt(PIN_INTERRUPT7, countInterrupts, FALLING);
 
PCintPort::attachInterrupt(PIN_INTERRUPT8, countInterrupts, FALLING);
 
PCintPort::attachInterrupt(PIN_INTERRUPT9, countInterrupts, FALLING);
 
PCintPort::attachInterrupt(PIN_INTERRUPT10, countInterrupts, FALLING);
 
PCintPort::attachInterrupt(PIN_INTERRUPT11, resetInterrupts, FALLING); // reset
 
PCintPort::attachInterrupt(PIN_INTERRUPT13, countInterrupts, FALLING);
 
  beep
(50,250);
}

void loop() {
   
for( int a = 0; a < nbInterrupts; a = a + 1 ) {
      beep
(50,250);
   
}
   
   delay
(5000);
   beep
(500,250);
}
 
//=======================================================
// Sound or led
//=======================================================
void beep(unsigned char delayms, unsigned int freq){
    analogWrite
(PIN_PIEZO, freq);      // Almost any value can be used except 0 and 255
                           
// experiment to get the best tone
    delay
(delayms);          // wait for a delayms ms
    analogWrite
(PIN_PIEZO, 0);       // 0 turns it off
    delay
(delayms);          // wait for a delayms ms  
}

//=======================================================
// Interrupt handler for anemometer. Called each time the
// reed switch triggers (one revolution).
//=======================================================
void countInterrupts() {
  nbInterrupts
++;
}

void resetInterrupts() {
  nbInterrupts
=0;
}


Regards,

J
To unsubscribe from this group and stop receiving emails from it, send an email to arduino-pinchangeint-discuss+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
-Mike Schwager

J Pinto

unread,
Apr 12, 2015, 2:11:20 PM4/12/15
to arduino-pincha...@googlegroups.com
Hello again,

I tried your suggestion for the new lib. However, i noticed that digital pins 12, 13 and all analog pins are not working with the 32u4 of the yun.

Is this a known issue?

J



domingo, 12 de Abril de 2015 às 15:01:26 UTC+1, GreyGnome escreveu:
To unsubscribe from this group and stop receiving emails from it, send an email to arduino-pinchangeint-discuss+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
-Mike Schwager

Michael Schwager

unread,
Apr 12, 2015, 5:23:35 PM4/12/15
to arduino-pincha...@googlegroups.com
Pin 13 won't work because it's not a PCINT pin. From the pinout of the BrewPi you sent me, it looks like the only available Pin Change Interrupt pin is Pin 11.

Regarding the Yun, only a small number of pins will work with your script. Those pins are listed here: https://github.com/GreyGnome/EnableInterrupt/wiki/Usage#leonardo . The Yun should be the same as the Leonardo. None of the Analog pins, for example, work as interrupts of any time (external or pin change).

If you don't mind, could you grab the EnableInterrupt code and try it out on your Yun? Use the "Simple" sketch, and try a few of the pins that are given on that website. I made an update to EnableInterrupt.h that may make a difference on the Leonardo, too. Once you install the library, grab the updated file from https://raw.githubusercontent.com/GreyGnome/EnableInterrupt/master/EnableInterrupt.h and just replace the one from the zip file.

Thanks!



To unsubscribe from this group and stop receiving emails from it, send an email to arduino-pinchangeint...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
-Mike Schwager

Michael Schwager

unread,
Apr 12, 2015, 5:28:08 PM4/12/15
to arduino-pincha...@googlegroups.com
The Arduino pin numbers on the Yun are the same as the Arduino pin numbers on the Leonardo; I compare http://pighixxx.tumblr.com/post/64361707693/arduino-yun-pinout to my above wiki link. I don't know if the Yun has 14, 15, 16 but it does have MISO, MOSI, and SCK just like the Leonardo. And none of the Analog pins support any interrupts at all.

These are all design limitations of the CPUs themselves so there's no way to create a library that supports those pins as interrupt pins.

To unsubscribe from this group and stop receiving emails from it, send an email to arduino-pinchangeint...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
-Mike Schwager
Reply all
Reply to author
Forward
0 new messages