Go Down

Topic: Can't get to work I2C and INT Rotary encoder on Arduino Yun (Read 392 times) previous topic - next topic



Here is my prototyping setup

Arduino Yun connected by WiFi
- server to send/receive updates via GET/POST (Bridge library)
- LCD 1602 with keybuttons
- rotary encoder with interrupt code on digital pins 2-3 (INT 0 & 1) 
- analog temp sensor
- few relays

In this setup everything is working as expected.

LCD screen that I'm using is taking all the digital pins and I needed few more, I decided to use the same 1602 LCD with I2C controller, that requires only 2 digital pins, instead of 5.

Here is the problem with new setup:

- I2C has to be connected to SDA/SCL which is pin 2/3 on Arduino Yun (pins are also duplicated)

- Encoder was using interrupts on pin 2/3, I have tried to move it somewhere else but it seems I have no options on Yun (pins 0 & 1 (INT 0 & 1) and pin 7 reserved/used by the board) when I'm using those pins nothing works.

- i tried EnableInterrupt library to change pin interrupt but it didn't help

Please confirm that I'm out of luck with this setup.


The Yún pins are the same as the Leonardo board.

Pin 0 and 1 are indeed used by the Bridge, and pin 2 and 3 are the I2C bus.
So there goes all the normal interrupts. Pin 7 interrupt is reserved for future use.

I think the EnableInterrupt library can use the PCINT interrupt on pin 8, 9, 10, 11.
Pins: http://www.pighixxx.com/test/portfolio-items/yun/

I suggest to try the EnableInterrupt library once more.

If you can't make it work, perhaps a software I2C for the display will help.


Thank you for your response, Koepel. Your post gives me hope :)

This is what I've tried before (LCD is not connected)

// default arduino
attachInterrupt(digitalPinToInterrupt(3), myfunction, LOW); // Encoder works

// 3rd party library
enableInterrupt(3, myfunction, LOW); //Encoder works

// now with LCD i2c on 2/3
enableInterrupt(7, myfunction, LOW); // app starts, but when encoder is moved, it crashes, perhaps because of "handshake"
enableInterrupt(8, myfunction, LOW); // Encoder is not working 
enableInterrupt(9, myfunction, LOW); // Encoder is not working
enableInterrupt(10, myfunction, LOW); // Encoder is not working
enableInterrupt(11, myfunction, LOW); // Encoder is not working

Please tell me what I am doing wrong. I can try it out tonight.


The EnableInterrupt library works with pin 8, 9, 10 and 11 :D

I used Arduino IDE 1.8.5 and installed the EnableInterrupt library with the Library Manager. With a normal Arduino Leonardo board.

I ignored the message: "*** EnableInterrupt library version pre-0.9.6. This is not a problem. Keep calm, and carry on. ***".

Pin 7 is connected to the wifi module for future use. Let's not use that pin.

Read the documentation: https://github.com/GreyGnome/EnableInterrupt/wiki/Usage#enableInterrupt.
Don't use the 'LOW'. I have tested the 'CHANGE' and the 'FALLING' and those work.

Code: [Select]

// Test with Arduino Leonardo and EnableInterrupt with pin 8, 9, 10, 11
// https://github.com/GreyGnome/EnableInterrupt

#include <EnableInterrupt.h>

const int pcintPin = 8;  // test with 8, 9, 10, 11

volatile uint16_t interruptCount=0;  // The count will go back to 0 after hitting 65535.

void interruptFunction()

void setup()
  Serial.begin( 9600);
  while( !Serial);   // wait for for serial monitor to open

  pinMode( pcintPin, INPUT_PULLUP);
  enableInterrupt( pcintPin, interruptFunction, CHANGE);

void loop()
  Serial.print( "Pin was interrupted: ");
  Serial.print( interruptCount, DEC);
  Serial.println( " times so far.");


Go Up