Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 3 months ago.
BLE Nano and LSM9DS1s
Hey guys, I'm trying to use two LSM9DS1 IMUs with a BLE Nano, using the sparkfun's module for changing the address of one of them. Still I can't establish communication with the BLE Nano - I've gone through most of the similar issues, and still didn't find a solution for the problem - from changing SDA and SCL pinnames to p6, p7, p10, p8 etc. to testing the sensors themselves.
Thanks in advance! Here's the whole code:
angles detector
#include "LSM9DS1.h"
#include "mbed.h"
#include "ble/BLE.h"
#include "ble/services/UARTService.h"
BLEDevice ble;
DigitalOut led1(LED1);
DigitalOut i2cchange(P0_9);
UARTService *uartServicePtr;
Ticker ticker;
#define ACal 0.0005987715
#define GCal 0.00747680664
#define PI 3.14159
#define DEG 180/PI
LSM9DS1 imuT(p7,p6,0x6B, 0x1E);
LSM9DS1 imuF(p7,p6,0x6A, 0 x1C);
float axT = 0;
float ayT = 0;
float azT = 0;
float magAccelT = 0;
float axF, ayF, azF, magAccelF; // acceleration components
float gxT, gyT, gzT, magGyroT, gxF, gyF, gzF, magGyroF; // rotational components
float internal_array[10] = {0,0,0,0,0,0,0,0,0,0};
float flexion_array[10] = {0,0,0,0,0,0,0,0,0,0};
float valrus_array[10] = {0,0,0,0,0,0,0,0,0,0};
// Callibrating Accelerometers // Made Manually
float del_axT = -0.178;
float del_ayT = -0.200;
float del_azT = 0.071;
float del_axF = -0.219;
float del_ayF = -0.136;
float del_azF = -0.756;
// Callibrating Gyros // Made Manually
float del_gxT = -0.16;
float del_gyT = 14.59;
float del_gzT = 91.66;
float del_gxF = -110.08;
float del_gyF = 239.90;
float del_gzF = -526.83;
uint8_t accel[15] = {'f',0,0,0,0,'v',0,0,0,0,'i',0,0,0,0};
char angles[15];
void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
{
ble.startAdvertising();
}
void periodicCallback(void)
{
led1 = !led1;
sprintf(angles, "f%04dv%04di%04d", axT, ayT, azT);
for (int i = 0; i < 15; i++) {
accel[i]= angles[i];
}
ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), accel, sizeof(accel));
}
int main()
{
led1 = 1;
led1 = !led1;
i2cchange = 1;
imuT.begin();
imuF.begin();
if( !imuT.begin() || !imuF.begin() ) {
wait(10);
}
led1 = !led1;
ticker.attach(periodicCallback, 1);
ble.init();
ble.onDisconnection(disconnectionCallback);
/* setup advertising */
ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
(const uint8_t *)"BLE UART", sizeof("BLE UART") - 1);
ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
(const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));
ble.setAdvertisingInterval(1000); /* 1000ms; in multiples of 0.625ms. */
ble.startAdvertising();
UARTService uartService(ble);
uartServicePtr = &uartService;
while(1) {
if( imuT.begin() || imuF.begin() ) {
imuT.readAccel();
axT = (imuT.ax)*ACal-del_axT;
azT = (imuT.az)*ACal-del_azT;
ayT = (imuT.ay)*ACal-del_ayT;
wait_ms(20);
imuF.readAccel();
axF = (imuF.ax)*ACal-del_axF;
azF = (imuF.az)*ACal-del_azF;
ayF = (imuF.ay)*ACal-del_ayF;
wait_ms(20);
imuT.readGyro();
gxT = (imuT.gx-del_gxT)*GCal;
gzT = (imuT.gz-del_gzT)*GCal;
gyT = (imuT.gy-del_gyT)*GCal;
wait_ms(20);
imuF.readGyro();
gxF = (imuF.gx-del_gxF)*GCal;
gzF = (imuF.gz-del_gzF)*GCal;
gyF = (imuF.gy-del_gyF)*GCal;
}
ble.waitForEvent();
}
}