- Thu Feb 06, 2014 9:57 am
#168102
Hi,
I'm using this library for the ADXL345: http://bildr.org/2011/03/adxl345-arduino/
My code is quite simple. The bluetooth part of this gives no trouble, if I replace it by flashing lights I get the exact same problem. After a few minutes (about 3), sometimes less, the free fall stops giving off any interrupts (also not any tap interrupts if I add those to the code, or xyz info) and the only way to get it to work again is a restart. I've tested if it's alive when this happens (yes), asleep (no), in low power mode(no). If I recreate this with only tap instead of free fall I seem to have no problems so it seems free fall specific that it gets blocked. Does anyone have a clue what's happening here?
I'm using this library for the ADXL345: http://bildr.org/2011/03/adxl345-arduino/
My code is quite simple. The bluetooth part of this gives no trouble, if I replace it by flashing lights I get the exact same problem. After a few minutes (about 3), sometimes less, the free fall stops giving off any interrupts (also not any tap interrupts if I add those to the code, or xyz info) and the only way to get it to work again is a restart. I've tested if it's alive when this happens (yes), asleep (no), in low power mode(no). If I recreate this with only tap instead of free fall I seem to have no problems so it seems free fall specific that it gets blocked. Does anyone have a clue what's happening here?
Code: Select all
#include <ADXL345.h>
#include <Wire.h>
#include <SoftwareSerial.h>
const byte PIN_BLUETOOTH_RX = 2;
const byte PIN_BLUETOOTH_TX = 5;
SoftwareSerial* bluetooth;
ADXL345 adxl;
void setup(){
bluetooth = new SoftwareSerial(PIN_BLUETOOTH_RX, PIN_BLUETOOTH_TX);
bluetooth->begin(9600);
adxl.powerOn();
//The FREE_FALL bit is set when acceleration of less than the value stored in the THRESH_FF register (Address 0x28)
// is experienced for more time than is specified in the TIME_FF register (Address 0x29) on all axes (logical AND).
adxl.setFreeFallThreshold(9); //(5 - 9) recommended - 62.5mg per increment
adxl.setFreeFallDuration(20); //(20 - 70) recommended - 5ms per increment
adxl.setInterruptMapping(ADXL345_INT_FREE_FALL_BIT, ADXL345_INT1_PIN);
//register interupt actions - 1 == on; 0 == off
adxl.setInterrupt(ADXL345_INT_FREE_FALL_BIT, 1);
}
void loop(){
byte interrupts = adxl.getInterruptSource();
if(adxl.triggered(interrupts, ADXL345_FREE_FALL))
{
sendBluetoothMessage(6, 1);
}
}
void sendBluetoothMessage(byte messageType, int message){
for(int i = 0; i< 11; i++){
bluetooth->write(byte(0));
}
bluetooth->write(messageType);
byte b[4];
IntegerToBytes(message, b);
for (int i = 0; i < 4; i++) {
bluetooth->write(b[i]);
}
}
void IntegerToBytes(long val, byte b[4]) {
b[0] = (byte )((val >> 24) & 0xff);
b[1] = (byte )((val >> 16) & 0xff);
b[2] = (byte )((val >> 8) & 0xff);
b[3] = (byte )(val & 0xff);
}