hey guys I'm having a bit of difficulty was hoping you might be able to help me correct the problem with the sketch.
Thanks
Zack
#include <RFduinoBLE.h>
#include <math.h>
#include "Adafruit_Sensor.h"
#include "Adafruit_LSM9DS0.h"
#include "stdio.h"
#include "String.h"
/*
* http://forum.rfduino.com/index.php?topic=289.0
* The maximum packet size is 20 bytes, and you can send a maximum
* of up to 6 packets per interval. For a total of 120 bytes per connection interval.
*/
/*
* [x,y,z] Accel (3) Byte
* [x,y,z] Gyro (3) Byte
* [x,y,z] Mag (3) Byte
* [TimeStamp] (1) Byte
* 10 Bytes Total....
*
*/
typedef struct box_imu_t{
struct accel{
byte x;
byte y;
byte z;
};
struct gyro{
byte x;
byte y;
byte z;
};
struct mag{
byte x;
byte y;
byte z;
};
/*TimeStamp */
byte timestamp; //8 Bits
} box_imu_t;
/* Global Varibles Initilization */
Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0(1000);
int BLEState = 0;
void setupSensor(){
/* 1.) Set the accelerometer range */
//lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_2G);
//lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_4G);
//lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_6G);
//lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_8G);
lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_16G);
/* 2.) Set the magnetometer sensitivity */
//lsm.setupMag(lsm.LSM9DS0_MAGGAIN_2GAUSS);
//lsm.setupMag(lsm.LSM9DS0_MAGGAIN_4GAUSS);
//lsm.setupMag(lsm.LSM9DS0_MAGGAIN_8GAUSS);
lsm.setupMag(lsm.LSM9DS0_MAGGAIN_12GAUSS);
/* 3.) Setup the gyroscope */
//lsm.setupGyro(lsm.LSM9DS0_GYROSCALE_245DPS);
//lsm.setupGyro(lsm.LSM9DS0_GYROSCALE_500DPS);
lsm.setupGyro(lsm.LSM9DS0_GYROSCALE_2000DPS);
}
void setup() {
#ifdef DEBUG
#endif
// this is the data we want to appear in the advertisement
RFduinoBLE.advertisementData = "IMU";
// start the BLE stack
RFduinoBLE.begin();
if (!lsm.begin());
#ifdef DEBUG
#endif
}
void loop() {
// put your main code here, to run repeatedly:
lsm.read();
// code here
#ifdef DEBUG
// code here
#endif
// saving to data structor
box_imu_t packit;
packit.accel.x = {lsm.accelData.x;
lsm.accelData.y;
lsm.accelData.z;
};
packit.gyro = {lsm.gyroData.x;
lsm.gyroData.y;
lsm.gyroData.z;
};
packit.mag = {lsm.magData.x;
lsm.magData.y;
lsm.magData.z;
};
packit.timestamp = 0;
if(BLEState == 1){
#ifdef XYZ
#else
RFduinoBLE.send(packit, 10);
#endif
}
}
void RFduinoBLE_onConnect(){
BLEState = 1;
#ifdef DEBUG
//Serial.println("Connect");
#endif
}
void RFduinoBLE_onDisconnect(){
#ifdef DEBUG
//Serial.println("Disconnect");
#endif
BLEState = 0;
}
void RFduinoBLE_onReceive(char *data, int len) {
(void)data;
(void)len;
}