Detecting movement

Discussion in 'UDOO NEO' started by Maurice, Nov 16, 2016.

  1. Maurice

    Maurice Active Member

    Joined:
    Oct 13, 2015
    Messages:
    394
    Likes Received:
    87
    As I wrote in an other post, I want to detect movement of the device. As of now I'm not interested in the direction[*], just that the device is moving. I'm using the following code, and it seems to work. Is there a better way?

    Code:
    #include <Wire.h>
    #include <FXOS8700CQ.h>
    
    
    static FXOS8700CQ accMagSensor = FXOS8700CQ(0x1E);
    
    static float factor;
    
    void setup() {
      Serial.begin(115200);
      Wire1.begin();
      accMagSensor.init(); 
      factor = accMagSensor.getAres();
    }
    
    
    
    void loop() {
      static unsigned long nextDisplay = 0;
      const unsigned long now = millis();
    
    
      if (accMagSensor.isAccelDataRdy()) {
        accMagSensor.readAccelData();
    
        if (now >= nextDisplay) {
          float f = factor * sqrt(pow(accMagSensor.accelData.x,2) +
            pow(accMagSensor.accelData.y,2) +
            pow(accMagSensor.accelData.z,2));
    
          if (f < 0.995 || f > 1.015) {
            Serial.println(f);
          }
          nextDisplay = now + 500;
        }
      }
    }
    
    [*] I don't need it for my idea, but still.... I'd like to know how to do that
     
  2. Andrea Rovai

    Andrea Rovai Well-Known Member

    Joined:
    Oct 27, 2014
    Messages:
    1,703
    Likes Received:
    240
    I am in the know that @estebanSannin developed a similar demo with UDOO Neo some time ago.
    In this demo, UDOO Neo tweets whenever you move it.
    Esteban, can you point @Maurice in the right direction?
     
    Maurice likes this.
  3. Andrea Rovai

    Andrea Rovai Well-Known Member

    Joined:
    Oct 27, 2014
    Messages:
    1,703
    Likes Received:
    240
    Last edited: Nov 17, 2016
    waltervl and Maurice like this.

Share This Page