Genuino101CurieIMUStepCount

Bu öğretici ile IMU'nun adım sayma özelliğini kullanmayı öğreneceksiniz. Ayrıca adım algılama modunu ve kesme tabanlı adım saymayı ayarlamayı da öğrenirsiniz. Alternatif olarak, Seri monitörde daha rahat bir çıkış için zamanlanmış bir okuma döngüsü (yoklama) kullanabilirsiniz.

Gerekli Donanım

Devre


Bu öğreticiyi kullanmak için ek donanıma gerek yoktur.

Yazılım Temelleri

Kütüphaneler

CurieIMU .h, 101 anakartın IMU yongasının tüm parametrelerine, özelliklerine ve okumalarına erişim sağlayan kütüphanedir. Bu ünite üç eksenli ivmeölçer ve üç eksenli jiroskop içerir. Bu kütüphane 101 pano çekirdeğinin bir parçasıdır ve Arduino veya Genuino 101 için çekirdek dosyalarla birlikte yüklenir. Bu öğreticide Adım algılama özelliğini ayarladık ve kesme veya yoklama ile adımları okuyoruz.

Fonksiyonlar

updateStepCount () - Bu işlev çağrıldığında, IMU sensörünün başlatılmasından bu yana sayılan adım sayısını okur. Sayı son okuma ile aynıysa, hiçbir şey olmaz, aksi takdirde yeni değer Seri monitörde yazdırılır ve saklanır.

Kod

Bu çizim hem kesinti tahrikli hem de yoklama adımı sayımını destekler. Çizim olay güdümlü (kesme) okuma için ayarlanmıştır, ancak bu satırı boolean stepEventsEnabeled = true; değiştirerek 1s yoklamaya gidebilirsiniz boolean stepEventsEnabeled = true; to boolean stepEventsEnabeled = false; . Kesmeyi yöneten geri çağırma işlevi, her adımda updateStepCount () işlevini çağırır. Bu çözüm Seri monitörde daha duyarlı bir rapor sunar.

/*
 * Copyright (c) 2016 Intel Corporation.  All rights reserved.
 * See the bottom of this file for the license terms.
 */


/*
   This sketch example demonstrates how the BMI160 accelerometer on the
   Intel(R) Curie(TM) module can be used as a Step Counter (pedometer)
*/


#include "CurieIMU.h"

/* To get an interrupt notification for every step detected,
    set stepEventsEnabeled to true. Otherwise, the main loop will
    poll for the current step count.

   By design, the step counter does not immediately update on every step detected.
   Please refer to Section 2.7 of the BMI160 IMU SensorData Sheet
   for more information on this feature.
*/

const int ledPin = 13;

bool stepEventsEnabeled = true;   // whether you're polling or using events
long lastStepCount = 0;              // step count on previous polling check
bool blinkState = false;          // state of the LED

void setup() {
  Serial.begin(9600); // initialize Serial communication
  while(!Serial) ;    // wait for serial port to connect.
  // pinMode(13, OUTPUT);
  // intialize the sensor:
  CurieIMU.begin();
  // turn on step detection mode:
  CurieIMU.setStepDetectionMode(CURIE_IMU_STEP_MODE_NORMAL);
  // enable step counting:
  CurieIMU.setStepCountEnabled(true);

  if (stepEventsEnabeled) {
    // attach the eventCallback function as the
    // step event handler:
    CurieIMU.attachInterrupt(eventCallback);
    CurieIMU.interrupts(CURIE_IMU_STEP);  // turn on step detection

    Serial.println("IMU initialisation complete, waiting for events...");
  }
}

void loop() {
  /* Instead of using step detection event notifications,
     we can check the step count periodically */

  if (!stepEventsEnabeled) {
    updateStepCount();
  }
  digitalWrite(13, blinkState);
  blinkState = !blinkState;
  delay(1000);
}

static void updateStepCount() {
  // get the step count:
  int stepCount = CurieIMU.getStepCount();

  // if the step count has changed, print it:
  if (stepCount != lastStepCount) {
    Serial.print("Step count: ");
    Serial.println(stepCount);
    // save the current count for comparison next check:
    lastStepCount = stepCount;
  }
}

static void eventCallback(void) {
  if (CurieIMU.stepsDetected())
    updateStepCount();
}

/*
   Copyright (c) 2016 Intel Corporation.  All rights reserved.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

*/
[Kodu Al]

See Also