Skip to content

Commit 97a49ac

Browse files
committed
ISM330 improvements
1 parent 7ac7857 commit 97a49ac

File tree

5 files changed

+207
-13
lines changed

5 files changed

+207
-13
lines changed

Firmware/OpenLog_Artemis/Sensors.ino

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,10 +1098,12 @@ void gatherDeviceValues(char * sdOutputData, size_t lenData)
10981098
// Structs for X,Y,Z data
10991099
static sfe_ism_data_t accelData;
11001100
static sfe_ism_data_t gyroData;
1101+
static bool dataReady;
11011102
if ((nodeSetting->logAccel) || (nodeSetting->logGyro))
11021103
{
11031104
// Check if both gyroscope and accelerometer data is available.
1104-
if( nodeDevice->checkStatus() )
1105+
dataReady = nodeDevice->checkStatus();
1106+
if( dataReady )
11051107
{
11061108
nodeDevice->getAccel(&accelData);
11071109
nodeDevice->getGyro(&gyroData);
@@ -1123,6 +1125,11 @@ void gatherDeviceValues(char * sdOutputData, size_t lenData)
11231125
sprintf(tempData, "%s,%s,%s,", tempData1, tempData2, tempData3);
11241126
strlcat(sdOutputData, tempData, lenData);
11251127
}
1128+
if (nodeSetting->logDataReady)
1129+
{
1130+
sprintf(tempData, "%d,", dataReady);
1131+
strlcat(sdOutputData, tempData, lenData);
1132+
}
11261133
}
11271134
}
11281135
break;
@@ -1142,7 +1149,6 @@ void gatherDeviceValues(char * sdOutputData, size_t lenData)
11421149
if (nodeSetting->logMag)
11431150
{
11441151

1145-
// Check if accel data is available.
11461152
nodeDevice->getMeasurementXYZ(&rawValueX, &rawValueY, &rawValueZ);
11471153

11481154
// The magnetic field values are 18-bit unsigned. The zero (mid) point is 2^17 (131072).
@@ -1733,6 +1739,8 @@ static void getHelperText(char* helperText, size_t lenText)
17331739
strlcat(helperText, "aX,aY,aZ,", lenText);
17341740
if (nodeSetting->logGyro)
17351741
strlcat(helperText, "gX,gY,gZ,", lenText);
1742+
if (nodeSetting->logDataReady)
1743+
strlcat(helperText, "dataRdy,", lenText);
17361744
}
17371745
}
17381746
break;

Firmware/OpenLog_Artemis/autoDetect.ino

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -914,20 +914,20 @@ void configureDevice(node * temp)
914914
sensor->setBlockDataUpdate();
915915

916916
// Set the output data rate and precision of the accelerometer
917-
sensor->setAccelDataRate(ISM_XL_ODR_104Hz);
918-
sensor->setAccelFullScale(ISM_4g);
919-
920-
// Set the output data rate and precision of the gyroscope
921-
sensor->setGyroDataRate(ISM_GY_ODR_104Hz);
922-
sensor->setGyroFullScale(ISM_500dps);
917+
sensor->setAccelDataRate(sensorSetting->accelRate);
918+
sensor->setAccelFullScale(sensorSetting->accelScale);
923919

924920
// Turn on the accelerometer's filter and apply settings.
925-
sensor->setAccelFilterLP2();
926-
sensor->setAccelSlopeFilter(ISM_LP_ODR_DIV_100);
921+
sensor->setAccelFilterLP2(sensorSetting->accelFilterLP2);
922+
sensor->setAccelSlopeFilter(sensorSetting->accelSlopeFilter);
923+
924+
// Set the output data rate and precision of the gyroscope
925+
sensor->setGyroDataRate(sensorSetting->gyroRate);
926+
sensor->setGyroFullScale(sensorSetting->gyroScale);
927927

928928
// Turn on the gyroscope's filter and apply settings.
929-
sensor->setGyroFilterLP1();
930-
sensor->setGyroLP1Bandwidth(ISM_MEDIUM);
929+
sensor->setGyroFilterLP1(sensorSetting->gyroFilterLP1);
930+
sensor->setGyroLP1Bandwidth(sensorSetting->gyroLP1BW);
931931
}
932932
break;
933933
case DEVICE_MMC5983MA:
@@ -936,6 +936,8 @@ void configureDevice(node * temp)
936936
struct_MMC5983MA *sensorSetting = (struct_MMC5983MA *)temp->configPtr;
937937

938938
sensor->softReset();
939+
940+
sensor->enableAutomaticSetReset();
939941
}
940942
break;
941943
case DEVICE_KX134:

Firmware/OpenLog_Artemis/menuAttachedDevices.ino

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2694,6 +2694,7 @@ void menuConfigure_ISM330DHCX(void *configPtr)
26942694
{
26952695
SerialPrintln(F(""));
26962696
SerialPrintln(F("Menu: Configure ISM330DHCX IMU"));
2697+
SerialPrintln(F("Consult the datasheet for the accel and gyro settings"));
26972698

26982699
SerialPrint(F("1) Sensor Logging: "));
26992700
if (sensorSetting->log == true) SerialPrintln(F("Enabled"));
@@ -2708,6 +2709,23 @@ void menuConfigure_ISM330DHCX(void *configPtr)
27082709
SerialPrint(F("3) Log Gyro: "));
27092710
if (sensorSetting->logGyro == true) SerialPrintln(F("Enabled"));
27102711
else SerialPrintln(F("Disabled"));
2712+
2713+
SerialPrint(F("4) Log Data Ready: "));
2714+
if (sensorSetting->logDataReady == true) SerialPrintln(F("Enabled"));
2715+
else SerialPrintln(F("Disabled"));
2716+
2717+
SerialPrintf2("5) Accel Scale: %d\r\n", sensorSetting->accelScale);
2718+
SerialPrintf2("6) Accel Rate: %d\r\n", sensorSetting->accelRate);
2719+
SerialPrint(F("7) Accel Filter LP2: "));
2720+
if (sensorSetting->accelFilterLP2 == true) SerialPrintln(F("Enabled"));
2721+
else SerialPrintln(F("Disabled"));
2722+
SerialPrintf2("8) Accel Slope Filter: %d\r\n", sensorSetting->accelSlopeFilter);
2723+
SerialPrintf2("9) Gyro Scale: %d\r\n", sensorSetting->gyroScale);
2724+
SerialPrintf2("10) Gyro Rate: %d\r\n", sensorSetting->gyroRate);
2725+
SerialPrint(F("11) Gyro Filter LP1: "));
2726+
if (sensorSetting->gyroFilterLP1 == true) SerialPrintln(F("Enabled"));
2727+
else SerialPrintln(F("Disabled"));
2728+
SerialPrintf2("12) Gyro LP1 Bandwidth: %d\r\n", sensorSetting->gyroLP1BW);
27112729
}
27122730
SerialPrintln(F("x) Exit"));
27132731

@@ -2721,6 +2739,66 @@ void menuConfigure_ISM330DHCX(void *configPtr)
27212739
sensorSetting->logAccel ^= 1;
27222740
else if (incoming == 3)
27232741
sensorSetting->logGyro ^= 1;
2742+
else if (incoming == 4)
2743+
sensorSetting->logDataReady ^= 1;
2744+
else if (incoming == 5)
2745+
{
2746+
SerialPrint(F("Enter the Accel Full Scale (0 to 3): "));
2747+
int newNum = getNumber(menuTimeout); //x second timeout
2748+
if (newNum < 0 || newNum > 3)
2749+
SerialPrintln(F("Error: Out of range"));
2750+
else
2751+
sensorSetting->accelScale = newNum;
2752+
}
2753+
else if (incoming == 6)
2754+
{
2755+
SerialPrint(F("Enter the Accel Rate (0 to 11): "));
2756+
int newNum = getNumber(menuTimeout); //x second timeout
2757+
if (newNum < 0 || newNum > 11)
2758+
SerialPrintln(F("Error: Out of range"));
2759+
else
2760+
sensorSetting->accelRate = newNum;
2761+
}
2762+
else if (incoming == 7)
2763+
sensorSetting->accelFilterLP2 ^= 1;
2764+
else if (incoming == 8)
2765+
{
2766+
SerialPrint(F("Enter the Accel Slope Filter setting (0 to 0x37): "));
2767+
int newNum = getNumber(menuTimeout); //x second timeout
2768+
if (newNum < 0 || newNum > 55)
2769+
SerialPrintln(F("Error: Out of range"));
2770+
else
2771+
sensorSetting->accelSlopeFilter = newNum;
2772+
}
2773+
else if (incoming == 9)
2774+
{
2775+
SerialPrint(F("Enter the Gyro Full Scale (0 to 12): "));
2776+
int newNum = getNumber(menuTimeout); //x second timeout
2777+
if (newNum < 0 || newNum > 12)
2778+
SerialPrintln(F("Error: Out of range"));
2779+
else
2780+
sensorSetting->gyroScale = newNum;
2781+
}
2782+
else if (incoming == 10)
2783+
{
2784+
SerialPrint(F("Enter the Gyro Rate (0 to 10): "));
2785+
int newNum = getNumber(menuTimeout); //x second timeout
2786+
if (newNum < 0 || newNum > 10)
2787+
SerialPrintln(F("Error: Out of range"));
2788+
else
2789+
sensorSetting->gyroRate = newNum;
2790+
}
2791+
else if (incoming == 11)
2792+
sensorSetting->gyroFilterLP1 ^= 1;
2793+
else if (incoming == 12)
2794+
{
2795+
SerialPrint(F("Enter the Gyro LP1 Bandwidth (0 to 7): "));
2796+
int newNum = getNumber(menuTimeout); //x second timeout
2797+
if (newNum < 0 || newNum > 7)
2798+
SerialPrintln(F("Error: Out of range"));
2799+
else
2800+
sensorSetting->gyroLP1BW = newNum;
2801+
}
27242802
else if (incoming == STATUS_PRESSED_X)
27252803
break;
27262804
else if (incoming == STATUS_GETNUMBER_TIMEOUT)

Firmware/OpenLog_Artemis/nvm.ino

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,15 @@ void recordDeviceSettingsToFile()
790790
settingsFile.println((String)base + "log=" + nodeSetting->log);
791791
settingsFile.println((String)base + "logAccel=" + nodeSetting->logAccel);
792792
settingsFile.println((String)base + "logGyro=" + nodeSetting->logGyro);
793+
settingsFile.println((String)base + "logDataReady=" + nodeSetting->logDataReady);
794+
settingsFile.println((String)base + "accelScale=" + nodeSetting->accelScale);
795+
settingsFile.println((String)base + "gyroScale=" + nodeSetting->gyroScale);
796+
settingsFile.println((String)base + "accelRate=" + nodeSetting->accelRate);
797+
settingsFile.println((String)base + "gyroRate=" + nodeSetting->gyroRate);
798+
settingsFile.println((String)base + "accelFilterLP2=" + nodeSetting->accelFilterLP2);
799+
settingsFile.println((String)base + "gyroFilterLP1=" + nodeSetting->gyroFilterLP1);
800+
settingsFile.println((String)base + "gyroLP1BW=" + nodeSetting->gyroLP1BW);
801+
settingsFile.println((String)base + "accelSlopeFilter=" + nodeSetting->accelSlopeFilter);
793802
}
794803
break;
795804
case DEVICE_MMC5983MA:
@@ -1467,6 +1476,24 @@ bool parseDeviceLine(char* str) {
14671476
nodeSetting->logAccel = d;
14681477
else if (strcmp(deviceSettingName, "logGyro") == 0)
14691478
nodeSetting->logGyro = d;
1479+
else if (strcmp(deviceSettingName, "logDataReady") == 0)
1480+
nodeSetting->logDataReady = d;
1481+
else if (strcmp(deviceSettingName, "accelScale") == 0)
1482+
nodeSetting->accelScale = d;
1483+
else if (strcmp(deviceSettingName, "gyroScale") == 0)
1484+
nodeSetting->gyroScale = d;
1485+
else if (strcmp(deviceSettingName, "accelRate") == 0)
1486+
nodeSetting->accelRate = d;
1487+
else if (strcmp(deviceSettingName, "gyroRate") == 0)
1488+
nodeSetting->gyroRate = d;
1489+
else if (strcmp(deviceSettingName, "accelFilterLP2") == 0)
1490+
nodeSetting->accelFilterLP2 = d;
1491+
else if (strcmp(deviceSettingName, "gyroFilterLP1") == 0)
1492+
nodeSetting->gyroFilterLP1 = d;
1493+
else if (strcmp(deviceSettingName, "gyroLP1BW") == 0)
1494+
nodeSetting->gyroLP1BW = d;
1495+
else if (strcmp(deviceSettingName, "accelSlopeFilter") == 0)
1496+
nodeSetting->accelSlopeFilter = d;
14701497
else
14711498
SerialPrintf2("Unknown device setting: %s\r\n", deviceSettingName);
14721499
}

Firmware/OpenLog_Artemis/settings.h

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//Needed for the MS8607 struct below
21
#include "SparkFun_PHT_MS8607_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_PHT_MS8607
2+
#include "SparkFun_ISM330DHCX.h" // Click here to get the library: http://librarymanager/All#SparkFun_6DoF_ISM330DHCX
33

44
typedef enum
55
{
@@ -344,6 +344,85 @@ struct struct_ISM330DHCX {
344344
bool log = true;
345345
bool logAccel = true;
346346
bool logGyro = true;
347+
bool logDataReady = true;
348+
//Accelerometer Full Scale
349+
//#define ISM_2g 0
350+
//#define ISM_16g 1
351+
//#define ISM_4g 2
352+
//#define ISM_8g 3
353+
int accelScale = ISM_4g;
354+
//Acceleromter Output Data Rate
355+
//#define ISM_XL_ODR_OFF 0
356+
//#define ISM_XL_ODR_12Hz5 1
357+
//#define ISM_XL_ODR_26Hz 2
358+
//#define ISM_XL_ODR_52Hz 3
359+
//#define ISM_XL_ODR_104Hz 4
360+
//#define ISM_XL_ODR_208Hz 5
361+
//#define ISM_XL_ODR_416Hz 6
362+
//#define ISM_XL_ODR_833Hz 7
363+
//#define ISM_XL_ODR_1666Hz 8
364+
//#define ISM_XL_ODR_3332Hz 9
365+
//#define ISM_XL_ODR_6667Hz 10
366+
//#define ISM_XL_ODR_1Hz6 11
367+
int accelRate = ISM_XL_ODR_208Hz;
368+
bool accelFilterLP2 = true;
369+
//Accel Regular Performance Filter Settings
370+
//#define ISM_HP_PATH_DISABLE_ON_OUT 0x00
371+
//#define ISM_SLOPE_ODR_DIV_4 0x10
372+
//#define ISM_HP_ODR_DIV_10 0x11
373+
//#define ISM_HP_ODR_DIV_20 0x12
374+
//#define ISM_HP_ODR_DIV_45 0x13
375+
//#define ISM_HP_ODR_DIV_100 0x14
376+
//#define ISM_HP_ODR_DIV_200 0x15
377+
//#define ISM_HP_ODR_DIV_400 0x16
378+
//#define ISM_HP_ODR_DIV_800 0x17
379+
//#define ISM_HP_REF_MD_ODR_DIV_10 0x31
380+
//#define ISM_HP_REF_MD_ODR_DIV_20 0x32
381+
//#define ISM_HP_REF_MD_ODR_DIV_45 0x33
382+
//#define ISM_HP_REF_MD_ODR_DIV_100 0x34
383+
//#define ISM_HP_REF_MD_ODR_DIV_200 0x35
384+
//#define ISM_HP_REF_MD_ODR_DIV_400 0x36
385+
//#define ISM_HP_REF_MD_ODR_DIV_800 0x37
386+
//#define ISM_LP_ODR_DIV_10 0x01
387+
//#define ISM_LP_ODR_DIV_20 0x02
388+
//#define ISM_LP_ODR_DIV_45 0x03
389+
//#define ISM_LP_ODR_DIV_100 0x04
390+
//#define ISM_LP_ODR_DIV_200 0x05
391+
//#define ISM_LP_ODR_DIV_400 0x06
392+
//#define ISM_LP_ODR_DIV_800 0x07
393+
int accelSlopeFilter = ISM_LP_ODR_DIV_100;
394+
//Gyroscope Full Scale
395+
//#define ISM_125dps 2
396+
//#define ISM_250dps 0
397+
//#define ISM_500dps 4
398+
//#define ISM_1000dps 8
399+
//#define ISM_2000dps 12
400+
//#define ISM_4000dps 1
401+
int gyroScale = ISM_250dps;
402+
//Gyroscope Output Data Rate
403+
//#define ISM_GY_ODR_OFF 0
404+
//#define ISM_GY_ODR_12Hz 1
405+
//#define ISM_GY_ODR_26Hz 2
406+
//#define ISM_GY_ODR_52Hz 3
407+
//#define ISM_GY_ODR_104Hz 4
408+
//#define ISM_GY_ODR_208Hz 5
409+
//#define ISM_GY_ODR_416Hz 6
410+
//#define ISM_GY_ODR_833Hz 7
411+
//#define ISM_GY_ODR_1666Hz 8
412+
//#define ISM_GY_ODR_3332Hz 9
413+
//#define ISM_GY_ODR_6667Hz 10
414+
int gyroRate = ISM_GY_ODR_208Hz;
415+
bool gyroFilterLP1 = true;
416+
//Gyro Bandwidth set
417+
//#define ISM_ULTRA_LIGHT 0
418+
//#define ISM_VERY_LIGHT 1
419+
//#define ISM_LIGHT 2
420+
//#define ISM_MEDIUM 3
421+
//#define ISM_STRONG 4
422+
//#define ISM_VERY_STRONG 5
423+
//#define ISM_AGGRESSIVE 6
424+
//#define ISM_XTREME 7
425+
int gyroLP1BW = ISM_MEDIUM;
347426
unsigned long powerOnDelayMillis = minimumQwiicPowerOnDelay; // Wait for at least this many millis before communicating with this device. Increase if required!
348427
};
349428

0 commit comments

Comments
 (0)