Arduino101 «зависает» при встряхивании

Я вижу случайное странное поведение Arduino101. Если я не двигаю доску, все работает нормально, но когда я начинаю трясти и постоянно двигать доску, она случайно застревает. Это означает, что вы больше не видите устройство BLE Arduino при сканировании, и единственный способ снова с ним работать — это перезагрузить плату. Когда сталкиваешься с этой проблемой, власть на arduino все еще в порядке. Еще раз повторяю, похоже, что-то связано с тряской доски на некоторое время.

Вот мой набросок, в надежде, что вы поможете мне понять возможные причины этого (возможно, некоторая проблема с производительностью или способом обработки прерываний).

#include "CurieIMU.h"#include "CurieBLE.h"#include <stdio.h>      /* puts, printf */

bool motion;
int aix, aiy, aiz;    // raw accelerometer values
int gix, giy, giz;    // raw gyro values

BLEPeripheral blePeripheral;
BLEService sensorService("19B10010-E8F2-537E-4F6C-D104768A1214");
BLEUnsignedLongCharacteristic stepCharacteristic("19B10011-E8F2-537E-4F6C-D104768A1214", BLERead);  // stepcount
BLEFloatCharacteristic axCharacteristic("19B10012-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify); // acc.in x in g
BLEFloatCharacteristic ayCharacteristic("19B10013-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify); // acc.in y in g
BLEFloatCharacteristic azCharacteristic("19B10014-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify); // acc.in z in g
BLEFloatCharacteristic gxCharacteristic("19B10015-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify); // rot.in x in deg/s
BLEFloatCharacteristic gyCharacteristic("19B10016-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify); // rot.in y in deg/s
BLEFloatCharacteristic gzCharacteristic("19B10017-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify); // rot.in z in deg/s
BLEIntCharacteristic shockCharacteristic("19B10018-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify);  // true if shock sensed
BLEIntCharacteristic modeCharacteristic("19B10019-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);  // sensing mode
BLEIntCharacteristic srangeCharacteristic("19B10020-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);  // shock range
BLEIntCharacteristic arangeCharacteristic("19B10021-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);  // acc. range
BLEIntCharacteristic grangeCharacteristic("19B100122-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); // gyro range
BLEIntCharacteristic calibCharacteristic("19B100123-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);  // 1 if calibration is on, otherwise 0void setup()
{

CurieIMU.begin();
blePeripheral.setLocalName("MOOVBIT");
blePeripheral.setAdvertisedServiceUuid(sensorService.uuid());
blePeripheral.addAttribute(sensorService);
blePeripheral.addAttribute(stepCharacteristic);
blePeripheral.addAttribute(axCharacteristic);
blePeripheral.addAttribute(ayCharacteristic);
blePeripheral.addAttribute(azCharacteristic);
blePeripheral.addAttribute(gxCharacteristic);
blePeripheral.addAttribute(gyCharacteristic);
blePeripheral.addAttribute(gzCharacteristic);
blePeripheral.addAttribute(shockCharacteristic);
blePeripheral.addAttribute(modeCharacteristic);
blePeripheral.addAttribute(arangeCharacteristic);
blePeripheral.addAttribute(srangeCharacteristic);
blePeripheral.addAttribute(grangeCharacteristic);
blePeripheral.addAttribute(calibCharacteristic);
// set initial characteristics values
stepCharacteristic.setValue(0);
shockCharacteristic.setValue(0);
modeCharacteristic.setValue(0);
arangeCharacteristic.setValue(4);
srangeCharacteristic.setValue(4);
grangeCharacteristic.setValue(250);
calibCharacteristic.setValue(1);
initPeriph();

CurieIMU.setAccelerometerRange(arangeCharacteristic.value());
CurieIMU.setGyroRange(grangeCharacteristic.value());
CurieIMU.setStepDetectionMode(CURIE_IMU_STEP_MODE_SENSITIVE);
CurieIMU.setStepCountEnabled(true);

CurieIMU.setDetectionThreshold(CURIE_IMU_SHOCK, srangeCharacteristic.value() * 500); // 1g = 1000 mg
CurieIMU.setDetectionDuration(CURIE_IMU_SHOCK, 50); // 50ms or 75ms
CurieIMU.interrupts(CURIE_IMU_SHOCK);
CurieIMU.interrupts(CURIE_IMU_MOTION);
CurieIMU.attachInterrupt(eventCallback);
motion = false;

}

void loop()
{
if (motion) {
if (!axCharacteristic.setValue(convertRawAcceleration(aix)) || !ayCharacteristic.setValue(convertRawAcceleration(aiy)) ||
!azCharacteristic.setValue(convertRawAcceleration(aiz)) || !gxCharacteristic.setValue(convertRawGyro(gix)) ||
!gyCharacteristic.setValue(convertRawGyro(giy)) || !gzCharacteristic.setValue(convertRawGyro(giz))) {
//Serial.println("Erorr BLE");
}
stepCharacteristic.setValue(CurieIMU.getStepCount());
motion = false;
}
delay(2000);
shockCharacteristic.setValue(0);
}

void eventCallback() {
if (CurieIMU.getInterruptStatus(CURIE_IMU_SHOCK)) {
if (shockCharacteristic.value() == 0) {
//Serial.println("Shock sensed");
shockCharacteristic.setValue(1);
}
//CurieIMU.readMotionSensor(aix, aiy, aiz, gix, giy, giz);
//motion = true;
}
else if (CurieIMU.getInterruptStatus(CURIE_IMU_MOTION)) {
CurieIMU.readMotionSensor(aix, aiy, aiz, gix, giy, giz);
motion = true;
}
}

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector