Change Interrupt Port


i have found code on mpu6050 dedicated arduino uno r3 (328-based)
but dont know change interrupt pin.

in code, interrupt pin on port 2 arduino micro(32u4-based)
sdl , scl on port 2, 3
interrupt ports on port 0, 1, 2, 3, 7

how replace interrupt 2 7?

code: [select]
#include <helper_3dmath.h>
#include <mpu6050_6axis_motionapps20.h>

///////////////////////////////////////////////////////////////////////////////////////
//this demo software experiment purpoer in noncomertial activity
//version: 1.0 (aug, 2016)

//gyro - arduino uno r3
//vcc  -  5v
//gnd  -  gnd
//sda  -  a4
//scl  -  a5
//int - port-2

#include <wire.h>
//declaring global variables
int gyro_x, gyro_y, gyro_z;
long gyro_x_cal, gyro_y_cal, gyro_z_cal;
boolean set_gyro_angles;

long acc_x, acc_y, acc_z, acc_total_vector;
float angle_roll_acc, angle_pitch_acc;

float angle_pitch, angle_roll;
int angle_pitch_buffer, angle_roll_buffer;
float angle_pitch_output, angle_roll_output;

long loop_timer;
int temp;

void setup() {
  wire.begin();                                                        //start i2c master
  setup_mpu_6050_registers();                                          //setup registers of mpu-6050
  (int cal_int = 0; cal_int < 1000 ; cal_int ++){                  //read raw acc , gyro data mpu-6050 1000 times
    read_mpu_6050_data();                                             
    gyro_x_cal += gyro_x;                                              //add gyro x offset gyro_x_cal variable
    gyro_y_cal += gyro_y;                                              //add gyro y offset gyro_y_cal variable
    gyro_z_cal += gyro_z;                                              //add gyro z offset gyro_z_cal variable
    delay(3);                                                          //delay 3us have 250hz for-loop
  }

  // divide 1000 avarage offset
  gyro_x_cal /= 1000;                                                 
  gyro_y_cal /= 1000;                                                 
  gyro_z_cal /= 1000;                                                 
  serial.begin(115200);
  loop_timer = micros();                                               //reset loop timer
}

void loop(){

  read_mpu_6050_data();   
 //subtract offset values raw gyro values
  gyro_x -= gyro_x_cal;                                               
  gyro_y -= gyro_y_cal;                                               
  gyro_z -= gyro_z_cal;                                               
         
  //gyro angle calculations . note 0.0000611 = 1 / (250hz x 65.5)
  angle_pitch += gyro_x * 0.0000611;                                   //calculate traveled pitch angle , add angle_pitch variable
  angle_roll += gyro_y * 0.0000611;                                    //calculate traveled roll angle , add angle_roll variable
  //0.000001066 = 0.0000611 * (3.142(pi) / 180degr) arduino sin function in radians
  angle_pitch += angle_roll * sin(gyro_z * 0.000001066);               //if imu has yawed transfer roll angle pitch angel
  angle_roll -= angle_pitch * sin(gyro_z * 0.000001066);               //if imu has yawed transfer pitch angle roll angel
 
  //accelerometer angle calculations
  acc_total_vector = sqrt((acc_x*acc_x)+(acc_y*acc_y)+(acc_z*acc_z));  //calculate total accelerometer vector
  //57.296 = 1 / (3.142 / 180) arduino asin function in radians
  angle_pitch_acc = asin((float)acc_y/acc_total_vector)* 57.296;       //calculate pitch angle
  angle_roll_acc = asin((float)acc_x/acc_total_vector)* -57.296;       //calculate roll angle
 
  angle_pitch_acc -= 0.0;                                              //accelerometer calibration value pitch
  angle_roll_acc -= 0.0;                                               //accelerometer calibration value roll

  if(set_gyro_angles){                                                 //if imu started
    angle_pitch = angle_pitch * 0.9996 + angle_pitch_acc * 0.0004;     //correct drift of gyro pitch angle accelerometer pitch angle
    angle_roll = angle_roll * 0.9996 + angle_roll_acc * 0.0004;        //correct drift of gyro roll angle accelerometer roll angle
  }
  else{                                                                //at first start
    angle_pitch = angle_pitch_acc;                                     //set gyro pitch angle equal accelerometer pitch angle
    angle_roll = angle_roll_acc;                                       //set gyro roll angle equal accelerometer roll angle
    set_gyro_angles = true;                                            //set imu started flag
  }
 
  //to dampen pitch , roll angles complementary filter used
  angle_pitch_output = angle_pitch_output * 0.9 + angle_pitch * 0.1;   //take 90% of output pitch value , add 10% of raw pitch value
  angle_roll_output = angle_roll_output * 0.9 + angle_roll * 0.1;      //take 90% of output roll value , add 10% of raw roll value
  serial.print(" | angle  = "); serial.println(angle_pitch_output);

 while(micros() - loop_timer < 4000);                                 //wait until loop_timer reaches 4000us (250hz) before starting next loop
 loop_timer = micros();//reset loop timer
 
}




void setup_mpu_6050_registers(){
  //activate mpu-6050
  wire.begintransmission(0x68);                                        //start communicating mpu-6050
  wire.write(0x6b);                                                    //send requested starting register
  wire.write(0x00);                                                    //set requested starting register
  wire.endtransmission();                                             
  //configure accelerometer (+/-8g)
  wire.begintransmission(0x68);                                        //start communicating mpu-6050
  wire.write(0x1c);                                                    //send requested starting register
  wire.write(0x10);                                                    //set requested starting register
  wire.endtransmission();                                             
  //configure gyro (500dps full scale)
  wire.begintransmission(0x68);                                        //start communicating mpu-6050
  wire.write(0x1b);                                                    //send requested starting register
  wire.write(0x08);                                                    //set requested starting register
  wire.endtransmission();             

                                  attachinterrupt(digitalpintointerrupt(7), dmpdataready, rising); //pin 7 on micro
}


void read_mpu_6050_data(){                                             //subroutine reading raw gyro , accelerometer data
  wire.begintransmission(0x68);                                        //start communicating mpu-6050
  wire.write(0x3b);                                                    //send requested starting register
  wire.endtransmission();                                              //end transmission
  wire.requestfrom(0x68,14);                                           //request 14 bytes mpu-6050
  while(wire.available() < 14);                                        //wait until bytes received
  acc_x = wire.read()<<8|wire.read();                                 
  acc_y = wire.read()<<8|wire.read();                                 
  acc_z = wire.read()<<8|wire.read();                                 
  temp = wire.read()<<8|wire.read();                                   
  gyro_x = wire.read()<<8|wire.read();                                 
  gyro_y = wire.read()<<8|wire.read();                                 
  gyro_z = wire.read()<<8|wire.read();                                 
}

quote
how replace interrupt 2 7?
just this:
code: [select]
              attachinterrupt(digitalpintointerrupt(7), dmpdataready, rising); //pin 7 on micro

what problem having?


Arduino Forum > Using Arduino > Programming Questions > Change Interrupt Port


arduino

Comments

Popular posts from this blog

DHT11 Time out error using v0.4.1library

Sketch upload fails with Java error (___REMOVE___/bin/avrdude)!

Arduino Uno + KTY81/210 temperature sensor