Go Down

Topic: How to make adxl345 activity interrupt (INT2) work on D3 of arduino uno? (Read 1 time) previous topic - next topic

adrianwong

This is the code :

#include <ADXL345.h>
#include "Wire.h"

inline void IMU_sensing(void);

//Object Declaration
ADXL345 adxl;                                                        // variable adxl is an instance of the ADXL345 library

int rawSixDof[6];

void setup()
{
  Serial.begin(9600);                                            // initialize serial communications

 
  pinMode(3, INPUT);                                              // make digital 3 an input for ADXL345 interrupt
  //pinMode(A0, INPUT);                                           // make digital pin A0 in nrf51822 an input for ADXL345 interrupt

   adxl.powerOn();
 
 
  //setting all interupts to take place on int pin 1
  //set activity/ inactivity thresholds (0-255)
  adxl.setActivityThreshold(4);                                    // 62.5mg per increment
  adxl.setInactivityThreshold(75);                                 // 62.5mg per increment
  adxl.setTimeInactivity(1);                                       // 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(0);

  //ADXL345 interrupt mapping
  adxl.setInterruptMapping(ADXL345_INT_ACTIVITY_BIT, ADXL345_INT2_PIN);

  Wire.begin();                                                    // initialize I2C communications
  delay(5);

}


void loop()
{
 
  //ADXL345 interrupt setting
  adxl.setInterrupt(ADXL345_INT_ACTIVITY_BIT, 0);                       // register interupt actions - 1 == on; 0 == off
 
 
  IMU_sensing(); 

}

inline void IMU_sensing(void)
{

  //sixDOF.getRawValues(rawSixDof);                              // obtain raw data from accelerometer and gyrometer from sensors
  int x, y, z;
  adxl.readAccel(&x, &y, &z);
  rawSixDof[0] = x;
  rawSixDof[1] = y;
  rawSixDof[2] = z;

  Serial.print("X : ");
  Serial.println(rawSixDof[0]);
  Serial.print("Y : ");
  Serial.println(rawSixDof[1]);
  Serial.print("Z : ");
  Serial.println(rawSixDof[2]);

  Serial.println("");
  delay(1000);
 
  sleepNow();
}


void sleepNow()                                                                       // here we put the arduino to sleep
{

  //set_sleep_mode(SLEEP_MODE_PWR_SAVE);                                                // sleep mode is set here
  //sleep_enable();
  adxl.getInterruptSource();
  attachInterrupt(1, wakeUp, CHANGE);
  adxl.setInterrupt(ADXL345_INT_ACTIVITY_BIT, 1);
  //sleep_mode();
  //sleep_disable();                                                                    // first thing after waking from sleep:
  detachInterrupt(1);
}

void wakeUp()                                                                         // wake up
{
  Serial.println("Activity");
}

MorganS

Read the sticky post at the top of the forum and edit your post accordingly.
"The problem is in the code you didn't post."


Go Up