sending data through BLE

Hello guys

I am using Arduino 101 to accelerometer data using BLE to app created in MIT AppInventor. The issue is that the accelerometer reading stops after 4-6 seconds in the app.

I am not sure how do I extend this time? Is there a time limit for how long the data can be sent? Is there a specific function for this?

I am a novice and really stuck.

Any help will be really appreciated.

Amrit_rai:
Any help will be really appreciated.

I'm sure it will be, but how can you seriously expect anybody to help you when you refuse to post your code? You might as well ask the fairies at the bottom of your garden.
Have you tried sending the data to the serial monitor instead of Bluetooth? At least that might give some suggestion about which forum you should be on.

Oh yeah

Should have thought of that!

Please have a look at my code and suggest how I could increase the timing of the sensor.

1st sketch

#define NAME “Detect BLE” // no more than 11 characters
#define DEBUGGING DISABLED

#define ACCELEROMETER DISABLED

/ frequency to read sensor values in µs
const unsigned long SENSOR_UPDATE_FREQ = 60000;
const unsigned long IMU_READ_FREQ = 50000;
const double IMU_FILTER_ALPHA = 0.5; //Alpha for accelerometer low pass filter

unsigned long nextSensorUpdate;
unsigned long nextIMURead;
double dt;

const uint8_t BITS[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
const uint8_t MASK[8] = { 0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF, 0xBF, 0x7F };

#include “common.h”

bool connected = false;
BLEPeripheral blePeripheral;
BLEService appinventorService(“E95DFFFF-251D-470A-A062-FA1922DFA9A7”);

#define MODE PREAMBLE
#include “sensors.h”
#undef MODE
#define MODE DEFINITIONS
#include “sensors.h”
#undef MODE
#define MODE FUNCTIONS
#include “sensors.h”
#undef MODE

void setup() {
Serial.begin(9600);
#if DEBUGGING == ENABLED
while (!Serial);
#endif
LOGLN(“Starting App Inventor…”);

blePeripheral.setDeviceName(NAME);
blePeripheral.setLocalName(NAME);
blePeripheral.setAppearance(128);
blePeripheral.setAdvertisedServiceUuid(appinventorService.uuid());

blePeripheral.addAttribute(appinventorService);

#define MODE SETUP
#include “sensors.h”
#undef MODE

LOGLN(“Setting connection interval”);
blePeripheral.setConnectionInterval(0x0006, 0x0010);
LOGLN(“Begin peripheral”);
blePeripheral.begin();

Serial.println(“App Inventor started.”);
}

void loop() {
BLECentral bleCentral = blePeripheral.central();
if (bleCentral && !connected) {
Serial.print("Connected to ");
Serial.println(bleCentral.address());
connected = true;
} else if (connected && !bleCentral) {
Serial.println(“Disconnected”);
connected = false;
}

if (connected) {
if ((long)(micros() - nextSensorUpdate) >= 0) {
updateSensorValues();
nextSensorUpdate += SENSOR_UPDATE_FREQ;
}
#if ACCELEROMETER == ENABLED || GYROSCOPE == ENABLED
if ((long)(micros() - nextIMURead) >= 0) {
updateIMUValues();
}
#endif
}
}

void updateSensorValues() {
#define MODE UPDATE
#include “sensors.h”
#undef MODE
}

#if ACCELEROMETER == ENABLED || GYROSCOPE == ENABLED
#include “imu.hh”
#endif

2nd sketch

#if ACCELEROMETER == ENABLED
#if MODE == PREAMBLE

#include <CurieIMU.h>

#define ACCELEROMETER_SETUP setupAccelerometer
#define ACCELEROMETER_UPDATE updateAccelerometer

#elif MODE == DEFINITIONS

struct AccelerometerData {
float x;
float y;
float z;
};

volatile struct AccelerometerData accel;

BLEService accelerometerService(“E95D0100-251D-470A-A062-FA1922DFA9A7”);
BLECharacteristic accelerometerReadChar(“E95D0101-251D-470A-A062-FA1922DFA9A7”, BLERead | BLENotify, sizeof(AccelerometerData));

void setupAccelerometer();
void updateAccelerometer();
float convertRawAcceleration(int aRaw);
float convertRawGyro(int gRaw);

#elif MODE == FUNCTIONS

void updateAccelerometer() {
// accel is computed in updateIMUValues in imu.hh
accelerometerReadChar.setValue((byte *)&accel, sizeof(accel));
}

void setupAccelerometer() {
CurieIMU.begin();
CurieIMU.setAccelerometerRange(4);
CurieIMU.setGyroRange(250);

// Configure initial values for characteristics
LOGLN(“Calibrate sensors”);
calibrateIMU();
updateAccelerometer();
updateIMUValues();

#if !ONE_SERVICE
Serial.println(“Configuring Accelerometer Service…”);
blePeripheral.addAttribute(accelerometerService);
#endif
blePeripheral.addAttribute(accelerometerReadChar);

}

#elif MODE == SETUP

setupAccelerometer();

#elif MODE == UPDATE

updateAccelerometer();

#endif
#endif

Please provide some suggestions.

Thank you