1

I have built a custom Arduino Micro PCB, but I have made a mistake, I accidentally attached an interrupt pin for a Gyro sensor to pin 12 of the Micro, not realizing it wasn't an external interrupt pin.

I tried using the interrupt pin change command found on the Arduino website, but I am having some trouble getting it working. If there is a way to make pin 12 on the Arduino Micro an Interrupt pin, how would I go about doing that in the simplest way.

6
  • You can use a pin change interrupt - or you can probably just poll, especially if you do so with knowledge of how often the sensor usually is ready. To get an actual answer, you'll need to post the code of your attempt and explain the specific problem. Nov 17, 2017 at 4:48
  • This is the pinmapping: pighixxx.com/test/portfolio-items/micro You mean pin 12 which is PD6 ? There is no PCINT on that pin. For PCINT I prefer the EnableInterrupt library: github.com/GreyGnome/EnableInterrupt How old is that gyro sensor ? because today the sensors are accelerometer + gyro + magnetometer in a single chip.
    – Jot
    Nov 17, 2017 at 10:05
  • The MPU6050's INT pin is not very mandatory, from what I can read on the various pages. You can try to modify the library you are using so that it does not have to have an interrupt
    – frarugi87
    Nov 17, 2017 at 15:31
  • I can add to @frarugi87 that some code poll the interrupt bit in the sensor. I also advise to use the newer MPU-9250. And if you use the AHRS code by Kris Winer then you don't need an interrupt: github.com/kriswiner/MPU9250 Tell us what your project is, perhaps you don't need to sample data at a high speed (100 samples per second is high speed for these sensors). The I2Cdev library has too much overhead anyway, I hope you did not plan to use that library, did you?
    – Jot
    Nov 17, 2017 at 16:59
  • I am using a MPU-6050, which is a gyro + accelerometer. I am using it for a drone, so I need a very high refresh rate for the drone to fly. I used to have it not using the interrupt pin, put that data was coming in too slow and too delayed for it to fly correctly. Using the interrupt pin solved that issue. Nov 17, 2017 at 18:04

2 Answers 2

1

If there is a way to make pin 12 on the Arduino Micro an Interrupt pin

you should take a look at the device datasheet and see what other functionalities pin 12 has.

if it is a pcint pin, you are golden; if it is a timer input pin or an input capture pin, they can be programmed to act like an interrupt pin as well.

all begins with reading the datasheet.

0

this library will let you attach a function to a pin using pin-change-interrupt, api is quite simple

https://github.com/neu-rah/PCINT#api

Arduino pin change interrupt library compatible with AVR and SAM with consistent interface.

Allows handlers to be called with a predefined cargo (void*) for user data or just regular void returning functions with no params.

This library use meta-programing to achieve consistency.

Example

#include <pcint.h>

#define led 13
#define btn 12

void setled() {
  digitalWrite(led,digitalRead(btn));
}

void setup() {
  pinMode(led,OUTPUT);
  pinMode(btn,INPUT_PULLUP);
  PCattachInterrupt<btn>(setled,CHANGE);
  setled();//initial led status
}

void loop() {}

API

Just two methods:

void PCattachInterrupt<pin>(userFunc,mode);
void PCdetachInterrupt<pin>();
2
  • Unfortunately I have tried this and it will not compile for the Arduino Micro. Nov 17, 2017 at 7:12
  • its good to know it doesn't, i might check that.. but i wont bother to post the results, or risk yet another minus. still i've been using it on Uno and Nano
    – neu-rah
    Nov 19, 2017 at 23:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.