Pages: [1]   Go Down
Author Topic: Acelerómetro adxl345  (Read 712 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hola, estoy usando el adxl345. Consigo leer los datos y conectarlo al micro por interrupción. El problema es cuando el micro lo tengo en modo powerDown, el acelerómetro deja de funcionar, nunca entra en la interrupción. Sin embargo, si en lugar de conectar el acelerómetro a la interrupción conecto un cable entre la interrupción y gnd el micro se despierta y entra en la interrupción. Estoy usando la interrupción número 5, pin 18. El código es el siguiente:
Code:
#include <Wire.h>
#include <ADXL345.h>
 #include <Enerlib.h>
Energy energy;
ADXL345 adxl;

unsigned long init_int_time = 0;
unsigned long last_int_time = 0;
int activo=LOW;
void setup(){
  Serial.begin(9600);

 attachInterrupt(5,adx,RISING);
 
configuraradx();
}
  int x,y,z;
  byte interrupts;
void loop(){
 
  //Boring accelerometer stuff   
 
  adxl.readAccel(&x, &y, &z); //read the accelerometer values and store them in variables  x,y,z
 
  // Output x,y,z values - Commented out
  Serial.print(x);
  Serial.print('\t');
  Serial.print(y);
  Serial.print('\t');
  Serial.println(z);
  delay(500);

 
 
    interrupts = adxl.getInterruptSource();

 if(activo)
 {
   activo=LOW;
   Serial.println("Acelerometro");
   delay(10);
 }
//  // freefall
//  if(adxl.triggered(interrupts, ADXL345_FREE_FALL)){
//    Serial.println("freefall");
//    //add code here to do when freefall is sensed
//  }
//
//  //inactivity
//  if(adxl.triggered(interrupts, ADXL345_INACTIVITY)){
//    Serial.println("inactivity");
//     //add code here to do when inactivity is sensed
//  }
//
//  //activity
//  if(adxl.triggered(interrupts, ADXL345_ACTIVITY)){
//    Serial.println("activity");
//     //add code here to do when activity is sensed
//  }
//
//  //double tap
//  if(adxl.triggered(interrupts, ADXL345_DOUBLE_TAP)){
//    Serial.println("double tap");
//     //add code here to do when a 2X tap is sensed
//  }
//
//  //tap
//  if(adxl.triggered(interrupts, ADXL345_SINGLE_TAP)){
//    Serial.println("tap");
//     //add code here to do when a tap is sensed
//  }
energy.PowerDown();
}



void adx()
{
  init_int_time = millis();
   
  if (init_int_time - last_int_time > 200) {
   
        activo = HIGH;
   
  last_int_time = init_int_time;
  }
}
void configuraradx()
{
     adxl.powerOn();
  //set activity/ inactivity thresholds (0-255)
  adxl.setActivityThreshold(75); //62.5mg per increment
  adxl.setInactivityThreshold(75); //62.5mg per increment
  adxl.setTimeInactivity(10); // how many seconds of no activity is inactive?
 
  //look of activity movement on this axes - 1 == on; 0 == off
  adxl.setActivityX(1);
  adxl.setActivityY(1);
  adxl.setActivityZ(1);
 
  //look of inactivity movement on this axes - 1 == on; 0 == off
  adxl.setInactivityX(1);
  adxl.setInactivityY(1);
  adxl.setInactivityZ(1);
 
  //look of tap movement on this axes - 1 == on; 0 == off
  adxl.setTapDetectionOnX(1);
  adxl.setTapDetectionOnY(1);
  adxl.setTapDetectionOnZ(1);
 
  //set values for what is a tap, and what is a double tap (0-255)
  adxl.setTapThreshold(10); //62.5mg per increment
  adxl.setTapDuration(15); //625μs per increment
  adxl.setDoubleTapLatency(10); //1.25ms per increment
  adxl.setDoubleTapWindow(80); //1.25ms per increment
 
  //set values for what is considered freefall (0-255)
  adxl.setFreeFallThreshold(7); //(5 - 9) recommended - 62.5mg per increment
  adxl.setFreeFallDuration(45); //(20 - 70) recommended - 5ms per increment
 
  //setting all interupts to take place on int pin 1
  //I had issues with int pin 2, was unable to reset it
  adxl.setInterruptMapping( ADXL345_INT_SINGLE_TAP_BIT,   ADXL345_INT1_PIN );
  adxl.setInterruptMapping( ADXL345_INT_DOUBLE_TAP_BIT,   ADXL345_INT1_PIN );
  adxl.setInterruptMapping( ADXL345_INT_FREE_FALL_BIT,    ADXL345_INT1_PIN );
  adxl.setInterruptMapping( ADXL345_INT_ACTIVITY_BIT,     ADXL345_INT1_PIN );
  adxl.setInterruptMapping( ADXL345_INT_INACTIVITY_BIT,   ADXL345_INT1_PIN );
 
  //register interupt actions - 1 == on; 0 == off 
  adxl.setInterrupt( ADXL345_INT_SINGLE_TAP_BIT, 1);
  adxl.setInterrupt( ADXL345_INT_DOUBLE_TAP_BIT, 1);
  adxl.setInterrupt( ADXL345_INT_FREE_FALL_BIT,  0);
  adxl.setInterrupt( ADXL345_INT_ACTIVITY_BIT,   0);
  adxl.setInterrupt( ADXL345_INT_INACTIVITY_BIT, 0);
}

Gracias,
Saludos.
Logged

Pages: [1]   Go Up
Jump to: