Yun pin 7 won't interrupt

I have a problem in a new Yun that wasn't there in an older version. I have been using the Yun to control my DAC in a sound system for over a year. I replaced the old Yun with a new Arduino.org version from Sparkfun. Now the rotary encoder that used pin 7 interrupts (together with pin 5) is no longer working. I've researched the forum and pin 7 problems are not new but a solution has not surfaced in my addled mind.

#define VOLDOWNPIN 7 // Button to decrease volume or RotEnc B terminal

// Rotary encoder interrupt service routine
static boolean rotating=false;
void rotEncoder()
{
rotating=true; // If motion is detected in the rotary encoder, set the flag to true
}

// Attach Interrupts
attachInterrupt(digitalPinToInterrupt(VOLDOWNPIN), rotEncoder, CHANGE);// ISR for rotary encoder

pinMode(VOLDOWNPIN, INPUT); // Button switch or Encoder pin for volume down
digitalWrite(VOLDOWNPIN, HIGH); // If H/W debouncing is implemented, set to LOW

if (digitalRead(5) == digitalRead(7)) // CCW
Do things...

The encoder checks out with a multimeter. An ideas?

Thanks in advance,
Ron

I have 2 questions:

  1. Has the assignment of pin 7 of the Yun changed on newer Yuns? Pin 7 worked great as an interrupt on my early version of the Yun board but does not appear to work on a new Yun.

  2. Should I use the PinChangeInterrupt approach instead and move my LCD pins from D8-D13 over to A0-A5?

I am leaving D0 and D1 (both designated interrupts) open for communication between Arduino and Linux. Also D2 and D3 are I2C pins for controlling the DAC. This leaves pin 7 as the only remaining external interrupt (4). The earlier Yun proved to be a nice implementation. Apparently the new Yun requires some finesse.

Please share your thoughts. Any suggestions?

Thanks and Happy Holidays,
Ron

Are there any Yun programmers that have successfully used SoftI2C to reassign the SDA/SCL to the analog pins to free up D2 and D3? If so do incoming I2C signals still interrupt? I have been looking at this link http://playground.arduino.cc/Main/SoftwareI2CLibrary to see if a solution lies there.

I use pin 7 interrupts on one of the .org boards successfully to get keystrokes from a PS/2 keyboard.

#include <PS2Keyboard.h> //int_pins.h had to be modified to enable pin 7 on the Leonard/Yun
....
const int DataPin = 12; //declares the data pin for the keyboard
const int IRQpin =  7;  //declares the IRQ pin for the keyboard, which lets the arduino watch for keystrokes
char keychar; //the char that will hold keyboard entries
PS2Keyboard keyboard; //names the keyboard

I have no idea why it isn't working in your situation.

Thanks Dark,

Do you think that the PS2Keyboard.h library helps to condition pin 7 to serve as interrupt? I have spent consider time trying to get pin 7 interrupts to work but did not succeed.

So I solved the problem with a work around. I had the LCD(13, 12, 11, 10, 9, 8) before so I moved 8 over to A1. Now pin 8 was available as PCInt4. I downloaded the EnbleInterrupt.h library and selected it under Sketch.
So now the rotary encoder code looks like this:

#include <EnableInterrupt.h>

#define VOLUPPIN 5 // Button to increase volume or RotEnc A terminal
#define VOLDOWNPIN 8 // Button to decrease volume or RotEnc B terminal

// Rotary encoder interrupt service routine
static boolean rotating=false;
void rotEncoder()
{
rotating=true; // If motion is detected in the rotary encoder, set the flag to true
}

void setup() {
Serial.begin(9600); // This is here for enableInterrupt

pinMode(VOLDOWNPIN, INPUT); // Button switch or Encoder pin for volume down
digitalWrite(VOLDOWNPIN, HIGH); // If H/W debouncing is implemented, set to LOW

// Attach Interrupt
enableInterrupt(VOLDOWNPIN, rotEncoder, CHANGE); // ISR for rotary encoder on VOLDOWNPIN
}

void loop() {

if (digitalRead(VOLUPPIN) == digitalRead(VOLDOWNPIN)) // CCW
Do things....
}

Instead of using the External Interrupts I used the Pin Change Interrupt built in the EnableInterrupt.h library. This is not the only or necessarily the best solution but it worked for me. If you are faced with a similar problem, there are a couple of issues to be aware of. The order in which to code is presented above is important to make this solution work. Also EnableInterrupt does not like digitalPinToInterrupt() in enableInterrupt().

Now I that found a solution to this problem I can move on to writing an interactive web page to control my music library and streaming sound system!

Thanks,
Ron

The only possibly relevant sections I see from the keyboard library are:

 // initialize the pins
#ifdef INPUT_PULLUP
  pinMode(irq_pin, INPUT_PULLUP);
#else
  pinMode(irq_pin, INPUT);
  digitalWrite(irq_pin, HIGH);
#endif

But you already have similar items in your sketch.

Glad you ended up finding another solution.

Pin 7 interrupt 4 is now a real head scratcher for me. I am not sure why it didn't work for me on the Arduino.org Yun board. Thanks for your input Dark. My implementation does not require rapid computation cycles so the PCInt is good enough. And it does work well....