Accelerometer Interrupt problems

Discussion in 'UDOO NEO' started by Lothar, Aug 16, 2016.

  1. Lothar

    Lothar New Member

    Joined:
    Aug 8, 2016
    Messages:
    13
    Likes Received:
    5
    Hi,

    I'm sure it's a PEBKAC but am blind to the solution. I want to activate the interrupt-functionality of the accelerometer that is on the NEO board.

    Here is my code I created by copying the example from AN4070.pdf that describes that functionality:

    Code:
    #include <Wire.h>
    #include <FXOS8700CQ.h>
    
    FXOS8700CQ accMagSensor = FXOS8700CQ(0x1E);
    volatile boolean infreefall = false;
    
    void setup() {
     
      // initialize serial port at a baud rate of 115200 bps
      Serial.begin(115200);
      Wire1.begin();
      delay(100);
      initializeAccelerometer();
      attachInterrupt(0, freefall, RISING);
      attachInterrupt(1, freefall, RISING);
    }
    
    void loop() {
      if (infreefall) {
        Serial.println("in motion");
        infreefall = false;
      }
          accMagSensor.readAccelData();
        // Print out the data
        // Accelerometer
        Serial.print("Accel ");
        Serial.print("  ");
        Serial.print((int)accMagSensor.accelData.x);
        Serial.print("  ");
        Serial.print((int)accMagSensor.accelData.y);
        Serial.print("  ");
        Serial.println((int)accMagSensor.accelData.z);
      delay(1000);
    }
    
    
    void initializeAccelerometer() {
      // Put the device into Standby Mode: Register 0x2A CTRL_REG1
      accMagSensor.writeReg(0x2a, 0x18);
      // Set Configuration Register for Motion Detection by setting
      // the “OR” condition OAE = 1, enabling X, Y, and the latch
      accMagSensor.writeReg(0x15, 0xd8);
      // Threshold Setting Value for the Motion detection of > 3g
      accMagSensor.writeReg(0x17, 0x30);
      // Set the debounce counter to eliminate false readings for
      // 100 Hz sample rate with a requirement of 100 ms timer.
      accMagSensor.writeReg(0x18, 0x0a);
      // Enable Motion/Freefall Interrupt Function in the System (CTRL_REG4)
      accMagSensor.writeReg(0x2d, 0x04);
      // Route the Motion/Freefall Interrupt Function to INT1
      // hardware pin (CTRL_REG5)
      accMagSensor.writeReg(0x2e, 0x04);
      // Put the device in Active Mode
      accMagSensor.writeReg(0x2a, 0x19);
    }
    
    void freefall() {
      infreefall = true;
    }
    
    In the end I want an interrupt when a freefall is detected (hence the naming) but for testing I changed the notification to motion-detection. The sketch produces the expected output every second but "in motion" never appears, so no interrupt seems to be triggered. Can anybody point me to the part of the code where I'm doing wrong? One of the outputs was "Accel -8192 5364 -8192" which is clearly beyond the 3g I set up when setting 0x17 to value 0x30.
     
  2. jas-mx

    jas-mx Active Member

    Joined:
    Dec 31, 2013
    Messages:
    407
    Likes Received:
    118
    I'm no arduino expert so can't comment on your code, however to use the FXOS8700CQ with an interrupt the hardware pin needs to be assigned to a GPIO pin on the M4 side. From the schematics INT1 is assigned to MX6SX_PAD_NAND_CE0_B__GPIO4_IO_1 therefore on the arduino you need to ensure this pin is mapped for a GPIO interrupt using something like digitalPinToInterrupt if that's possible or not I don't know.
     
  3. Lothar

    Lothar New Member

    Joined:
    Aug 8, 2016
    Messages:
    13
    Likes Received:
    5
    Thanks for that. I tried it with digitalPinToInterrupt but no budge. So I think to get further with my project, I will calculate motion- and freefall-conditions myself.
     

Share This Page