Skip to content

Commit cdaf6af

Browse files
committed
Adding support for the BNO080 - ** work in progress ** (does not .begin reliably)
1 parent 44c319b commit cdaf6af

File tree

8 files changed

+304
-3
lines changed

8 files changed

+304
-3
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Change Log
22
======================
33

4+
v1.8
5+
---------
6+
7+
* Added a fix to make sure the MS8607 is detected correctly [54](https://github.com/sparkfun/OpenLog_Artemis/issues/54)
8+
* Added logMicroseconds [49](https://github.com/sparkfun/OpenLog_Artemis/issues/49)
9+
* Added an option to use autoPVT when logging GNSS data [50](https://github.com/sparkfun/OpenLog_Artemis/issues/50)
10+
* Started to add support for the BNO080 so users can have access to Quaternions and Euler angles [47](https://github.com/sparkfun/OpenLog_Artemis/issues/47)
11+
* This is work in progress. The BNO080 does not currently .begin reliably - especially on the second attempt - and I don't understand why...
12+
413
v1.7
514
---------
615

Firmware/OpenLog_Artemis/OpenLog_Artemis.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
(done) Add a fix to make sure the MS8607 is detected correctly: https://github.com/sparkfun/OpenLog_Artemis/issues/54
7575
(done) Add logMicroseconds: https://github.com/sparkfun/OpenLog_Artemis/issues/49
7676
(done) Add an option to use autoPVT when logging GNSS data: https://github.com/sparkfun/OpenLog_Artemis/issues/50
77+
(work in progress) Add support for the BNO080 so users have access to Quaternions and Euler angles: https://github.com/sparkfun/OpenLog_Artemis/issues/47
7778
*/
7879

7980
const int FIRMWARE_VERSION_MAJOR = 1;
@@ -206,6 +207,7 @@ ICM_20948_SPI myICM;
206207
#include "SparkFun_ADS122C04_ADC_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_ADS122C04
207208
#include "SparkFun_MicroPressure.h" // Click here to get the library: http://librarymanager/All#SparkFun_MicroPressure
208209
#include "SparkFun_Particle_Sensor_SN-GCJA5_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_Particle_Sensor_SN-GCJA5
210+
#include "SparkFun_BNO080_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_BNO080
209211

210212
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
211213

Firmware/OpenLog_Artemis/Sensors.ino

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,64 @@ void gatherDeviceValues()
803803
}
804804
}
805805
break;
806+
case DEVICE_IMU_BNO080:
807+
{
808+
BNO080 *nodeDevice = (BNO080 *)temp->classPtr;
809+
struct_BNO080 *nodeSetting = (struct_BNO080 *)temp->configPtr;
810+
if (nodeSetting->log == true)
811+
{
812+
// Check that at least one set of readings is being logged
813+
if ((nodeSetting->logQuat) || (nodeSetting->logAccel) || (nodeSetting->logLinAccel) || (nodeSetting->logGyro) || (nodeSetting->logFastGyro) ||
814+
(nodeSetting->logMag) || (nodeSetting->logEuler))
815+
{
816+
if (nodeDevice->dataAvailable()) // Check if new data is available (dangerous? what happens if data is not available?)
817+
{
818+
if (nodeSetting->logQuat)
819+
{
820+
sprintf(tempData, "%.02f,%.02f,%.02f,%.02f,%d,", nodeDevice->getQuatI(), nodeDevice->getQuatJ(), nodeDevice->getQuatK(),
821+
nodeDevice->getQuatReal(), nodeDevice->getQuatRadianAccuracy());
822+
strcat(outputData, tempData);
823+
}
824+
if (nodeSetting->logAccel)
825+
{
826+
sprintf(tempData, "%.02f,%.02f,%.02f,%d,", nodeDevice->getAccelX(), nodeDevice->getAccelY(), nodeDevice->getAccelZ(),
827+
nodeDevice->getAccelAccuracy());
828+
strcat(outputData, tempData);
829+
}
830+
if (nodeSetting->logLinAccel)
831+
{
832+
sprintf(tempData, "%.02f,%.02f,%.02f,%d,", nodeDevice->getLinAccelX(), nodeDevice->getLinAccelY(), nodeDevice->getLinAccelZ(),
833+
nodeDevice->getLinAccelAccuracy());
834+
strcat(outputData, tempData);
835+
}
836+
if (nodeSetting->logGyro)
837+
{
838+
sprintf(tempData, "%.02f,%.02f,%.02f,%d,", nodeDevice->getGyroX(), nodeDevice->getGyroY(), nodeDevice->getGyroZ(),
839+
nodeDevice->getGyroAccuracy());
840+
strcat(outputData, tempData);
841+
}
842+
if (nodeSetting->logFastGyro)
843+
{
844+
sprintf(tempData, "%.02f,%.02f,%.02f,", nodeDevice->getFastGyroX(), nodeDevice->getFastGyroY(), nodeDevice->getFastGyroZ());
845+
strcat(outputData, tempData);
846+
}
847+
if (nodeSetting->logMag)
848+
{
849+
sprintf(tempData, "%.02f,%.02f,%.02f,%d,", nodeDevice->getMagX(), nodeDevice->getMagY(), nodeDevice->getMagZ(),
850+
nodeDevice->getMagAccuracy());
851+
strcat(outputData, tempData);
852+
}
853+
if (nodeSetting->logEuler)
854+
{
855+
sprintf(tempData, "%.01f,%.01f,%.01f,", nodeDevice->getRoll() * 180.0 / PI, nodeDevice->getPitch() * 180.0 / PI,
856+
nodeDevice->getYaw() * 180.0 / PI);
857+
strcat(outputData, tempData);
858+
}
859+
}
860+
}
861+
}
862+
}
863+
break;
806864
default:
807865
Serial.printf("printDeviceValue unknown device type: %s\r\n", getDeviceName(temp->deviceType));
808866
break;
@@ -1172,6 +1230,28 @@ void printHelperText(bool terminalOnly)
11721230
}
11731231
}
11741232
break;
1233+
case DEVICE_IMU_BNO080:
1234+
{
1235+
struct_BNO080 *nodeSetting = (struct_BNO080 *)temp->configPtr;
1236+
if (nodeSetting->log)
1237+
{
1238+
if (nodeSetting->logQuat)
1239+
strcat(helperText, "QuatI,QuatJ,QuatK,QuatR,QuatAcc,");
1240+
if (nodeSetting->logAccel)
1241+
strcat(helperText, "AccelX,AccelY,AccelZ,AccelAcc,");
1242+
if (nodeSetting->logLinAccel)
1243+
strcat(helperText, "LinAccelX,LinAccelY,LinAccelZ,LinAccelAcc,");
1244+
if (nodeSetting->logGyro)
1245+
strcat(helperText, "GyroX,GyroY,GyroZ,GyroAcc,");
1246+
if (nodeSetting->logFastGyro)
1247+
strcat(helperText, "FastGyroX,FastGyroY,FastGyroZ,");
1248+
if (nodeSetting->logMag)
1249+
strcat(helperText, "MagX,MagY,MagZ,MagAcc,");
1250+
if (nodeSetting->logEuler)
1251+
strcat(helperText, "Roll,Pitch,Yaw,");
1252+
}
1253+
}
1254+
break;
11751255
default:
11761256
Serial.printf("\nprinterHelperText device not found: %d\r\n", temp->deviceType);
11771257
break;

Firmware/OpenLog_Artemis/autoDetect.ino

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ bool addDevice(deviceType_e deviceType, uint8_t address, uint8_t muxAddress, uin
237237
temp->configPtr = new struct_SNGCJA5;
238238
}
239239
break;
240+
case DEVICE_IMU_BNO080:
241+
{
242+
temp->classPtr = new BNO080;
243+
temp->configPtr = new struct_BNO080;
244+
}
245+
break;
240246
default:
241247
Serial.printf("addDevice Device type not found: %d\r\n", deviceType);
242248
break;
@@ -459,6 +465,18 @@ bool beginQwiicDevices()
459465
temp->online = true;
460466
}
461467
break;
468+
case DEVICE_IMU_BNO080:
469+
{
470+
BNO080 *tempDevice = (BNO080 *)temp->classPtr;
471+
struct_BNO080 *nodeSetting = (struct_BNO080 *)temp->configPtr; //Create a local pointer that points to same spot as node does
472+
if (nodeSetting->powerOnDelayMillis > qwiicPowerOnDelayMillis) qwiicPowerOnDelayMillis = nodeSetting->powerOnDelayMillis; // Increase qwiicPowerOnDelayMillis if required
473+
//if(settings.printDebugMessages == true) tempDevice->enableDebugging();
474+
if (tempDevice->begin(temp->address, qwiic) == true) //Address, Wire port. Returns true on success.
475+
temp->online = true;
476+
else
477+
printDebug(F("beginQwiicDevices: BNO080.begin failed.\r\n"));
478+
}
479+
break;
462480
default:
463481
Serial.printf("beginQwiicDevices: device type not found: %d\r\n", temp->deviceType);
464482
break;
@@ -683,7 +701,7 @@ void configureDevice(node * temp)
683701
SFE_ADS122C04 *sensor = (SFE_ADS122C04 *)temp->classPtr;
684702
struct_ADS122C04 *sensorSetting = (struct_ADS122C04 *)temp->configPtr;
685703

686-
//Configure the wite mode for readPT100Centigrade and readPT100Fahrenheit
704+
//Configure the wire mode for readPT100Centigrade and readPT100Fahrenheit
687705
//(readInternalTemperature and readRawVoltage change and restore the mode automatically)
688706
if (sensorSetting->useFourWireMode)
689707
sensor->configureADCmode(ADS122C04_4WIRE_MODE);
@@ -705,6 +723,23 @@ void configureDevice(node * temp)
705723
case DEVICE_PARTICLE_SNGCJA5:
706724
//Nothing to configure
707725
break;
726+
case DEVICE_IMU_BNO080:
727+
{
728+
BNO080 *sensor = (BNO080 *)temp->classPtr;
729+
struct_BNO080 *sensorSetting = (struct_BNO080 *)temp->configPtr;
730+
731+
if ((sensorSetting->logQuat) || (sensorSetting->logEuler))
732+
sensor->enableRotationVector((uint16_t)(settings.usBetweenReadings / 1000));
733+
if (sensorSetting->logAccel)
734+
sensor->enableAccelerometer((uint16_t)(settings.usBetweenReadings / 1000));
735+
if (sensorSetting->logLinAccel)
736+
sensor->enableLinearAccelerometer((uint16_t)(settings.usBetweenReadings / 1000));
737+
if ((sensorSetting->logGyro) || (sensorSetting->logFastGyro))
738+
sensor->enableGyro((uint16_t)(settings.usBetweenReadings / 1000));
739+
if (sensorSetting->logMag)
740+
sensor->enableMagnetometer((uint16_t)(settings.usBetweenReadings / 1000));
741+
}
742+
break;
708743
default:
709744
Serial.printf("configureDevice: Unknown device type %d: %s\r\n", deviceType, getDeviceName((deviceType_e)deviceType));
710745
break;
@@ -795,6 +830,9 @@ FunctionPointer getConfigFunctionPtr(uint8_t nodeNumber)
795830
case DEVICE_PARTICLE_SNGCJA5:
796831
ptr = (FunctionPointer)menuConfigure_SNGCJA5;
797832
break;
833+
case DEVICE_IMU_BNO080:
834+
ptr = (FunctionPointer)menuConfigure_BNO080;
835+
break;
798836
default:
799837
Serial.println(F("getConfigFunctionPtr: Unknown device type"));
800838
Serial.flush();
@@ -932,6 +970,7 @@ void swap(struct node * a, struct node * b)
932970
#define ADR_UBLOX 0x42 //But can be set to any address
933971
#define ADR_ADS122C04 0x45 //Alternates: 0x44, 0x41 and 0x40
934972
#define ADR_TMP117 0x48 //Alternates: 0x49, 0x4A, and 0x4B
973+
#define ADR_BNO080 0x4B //Alternate: 0x4A
935974
#define ADR_SGP30 0x58
936975
#define ADR_CCS811 0x5B //Alternates: 0x5A
937976
#define ADR_LPS25HB 0x5D //Alternates: 0x5C
@@ -1063,6 +1102,14 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb
10631102
break;
10641103
case 0x4A:
10651104
{
1105+
//Confidence: High - Checks product ID report
1106+
BNO080 sensor1;
1107+
if(settings.printDebugMessages == true) sensor1.enableDebugging();
1108+
if (sensor1.begin(i2cAddress, qwiic) == true) //Address, Wire port
1109+
return (DEVICE_IMU_BNO080);
1110+
else
1111+
printDebug(F("testDevice: BNO080.begin failed.\r\n"));
1112+
10661113
//Confidence: High - Checks 16 bit ID
10671114
TMP117 sensor;
10681115
if (sensor.begin(i2cAddress, qwiic) == true) //Address, Wire port
@@ -1071,6 +1118,14 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb
10711118
break;
10721119
case 0x4B:
10731120
{
1121+
//Confidence: High - Checks product ID report
1122+
BNO080 sensor1;
1123+
if(settings.printDebugMessages == true) sensor1.enableDebugging();
1124+
if (sensor1.begin(i2cAddress, qwiic) == true) //Address, Wire port
1125+
return (DEVICE_IMU_BNO080);
1126+
else
1127+
printDebug(F("testDevice: BNO080.begin failed.\r\n"));
1128+
10741129
//Confidence: High - Checks 16 bit ID
10751130
TMP117 sensor;
10761131
if (sensor.begin(i2cAddress, qwiic) == true) //Address, Wire port
@@ -1470,6 +1525,9 @@ const char* getDeviceName(deviceType_e deviceNumber)
14701525
case DEVICE_PARTICLE_SNGCJA5:
14711526
return "Particle-SNGCJA5";
14721527
break;
1528+
case DEVICE_IMU_BNO080:
1529+
return "IMU-BNO080";
1530+
break;
14731531

14741532
case DEVICE_UNKNOWN_DEVICE:
14751533
return "Unknown device";

Firmware/OpenLog_Artemis/menuAttachedDevices.ino

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@ void menuAttachedDevices()
315315
case DEVICE_PARTICLE_SNGCJA5:
316316
Serial.printf("%s SN-GCJA5 Particle Sensor %s\r\n", strDeviceMenu, strAddress);
317317
break;
318+
case DEVICE_IMU_BNO080:
319+
Serial.printf("%s BNO080 IMU %s\r\n", strDeviceMenu, strAddress);
320+
break;
318321
default:
319322
Serial.printf("Unknown device type %d in menuAttachedDevices\r\n", temp->deviceType);
320323
break;
@@ -2151,3 +2154,83 @@ void menuConfigure_SNGCJA5(void *configPtr)
21512154
printUnknown(incoming);
21522155
}
21532156
}
2157+
2158+
void menuConfigure_BNO080(void *configPtr)
2159+
{
2160+
struct_BNO080 *sensorSetting = (struct_BNO080*)configPtr;
2161+
while (1)
2162+
{
2163+
Serial.println();
2164+
Serial.println(F("Menu: Configure BNO080 IMU"));
2165+
2166+
Serial.print(F("1) Sensor Logging: "));
2167+
if (sensorSetting->log == true) Serial.println(F("Enabled"));
2168+
else Serial.println(F("Disabled"));
2169+
2170+
if (sensorSetting->log == true)
2171+
{
2172+
Serial.print(F("2) Log Rotation Vector (Quaternions): "));
2173+
if (sensorSetting->logQuat == true) Serial.println(F("Enabled"));
2174+
else Serial.println(F("Disabled"));
2175+
2176+
Serial.print(F("3) Log Accelerometer: "));
2177+
if (sensorSetting->logAccel == true) Serial.println(F("Enabled"));
2178+
else Serial.println(F("Disabled"));
2179+
2180+
Serial.print(F("4) Log Linear Acceleration (Minus Gravity): "));
2181+
if (sensorSetting->logLinAccel == true) Serial.println(F("Enabled"));
2182+
else Serial.println(F("Disabled"));
2183+
2184+
Serial.print(F("5) Log Gyro: "));
2185+
if (sensorSetting->logGyro == true) Serial.println(F("Enabled"));
2186+
else Serial.println(F("Disabled"));
2187+
2188+
Serial.print(F("6) Log FastGyro: "));
2189+
if (sensorSetting->logFastGyro == true) Serial.println(F("Enabled"));
2190+
else Serial.println(F("Disabled"));
2191+
2192+
Serial.print(F("7) Log Magnetometer: "));
2193+
if (sensorSetting->logMag == true) Serial.println(F("Enabled"));
2194+
else Serial.println(F("Disabled"));
2195+
2196+
Serial.print(F("8) Log Euler Angles (Roll/Pitch/Yaw): "));
2197+
if (sensorSetting->logEuler == true) Serial.println(F("Enabled"));
2198+
else Serial.println(F("Disabled"));
2199+
}
2200+
Serial.println(F("x) Exit"));
2201+
2202+
byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds
2203+
2204+
if (incoming == '1')
2205+
sensorSetting->log ^= 1;
2206+
else if (sensorSetting->log == true)
2207+
{
2208+
if (incoming == '2')
2209+
sensorSetting->logQuat ^= 1;
2210+
else if (incoming == '3')
2211+
sensorSetting->logAccel ^= 1;
2212+
else if (incoming == '4')
2213+
sensorSetting->logLinAccel ^= 1;
2214+
else if (incoming == '5')
2215+
sensorSetting->logGyro ^= 1;
2216+
else if (incoming == '6')
2217+
sensorSetting->logFastGyro ^= 1;
2218+
else if (incoming == '7')
2219+
sensorSetting->logMag ^= 1;
2220+
else if (incoming == '8')
2221+
sensorSetting->logEuler ^= 1;
2222+
else if (incoming == 'x')
2223+
break;
2224+
else if (incoming == STATUS_GETBYTE_TIMEOUT)
2225+
break;
2226+
else
2227+
printUnknown(incoming);
2228+
}
2229+
else if (incoming == 'x')
2230+
break;
2231+
else if (incoming == STATUS_GETBYTE_TIMEOUT)
2232+
break;
2233+
else
2234+
printUnknown(incoming);
2235+
}
2236+
}

Firmware/OpenLog_Artemis/nvm.ino

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,19 @@ void recordDeviceSettingsToFile()
649649
settingsFile.println((String)base + "logFanStatus=" + nodeSetting->logFanStatus);
650650
}
651651
break;
652+
case DEVICE_IMU_BNO080:
653+
{
654+
struct_BNO080 *nodeSetting = (struct_BNO080 *)temp->configPtr;
655+
settingsFile.println((String)base + "log=" + nodeSetting->log);
656+
settingsFile.println((String)base + "logQuat=" + nodeSetting->logQuat);
657+
settingsFile.println((String)base + "logAccel=" + nodeSetting->logAccel);
658+
settingsFile.println((String)base + "logLinAccel=" + nodeSetting->logLinAccel);
659+
settingsFile.println((String)base + "logGyro=" + nodeSetting->logGyro);
660+
settingsFile.println((String)base + "logFastGyro=" + nodeSetting->logFastGyro);
661+
settingsFile.println((String)base + "logMag=" + nodeSetting->logMag);
662+
settingsFile.println((String)base + "logEuler=" + nodeSetting->logEuler);
663+
}
664+
break;
652665
default:
653666
Serial.printf("recordSettingsToFile Unknown device: %s\r\n", base);
654667
//settingsFile.println((String)base + "=UnknownDeviceSettings");
@@ -1172,6 +1185,29 @@ bool parseDeviceLine(char* str) {
11721185
Serial.printf("Unknown device setting: %s\r\n", deviceSettingName);
11731186
}
11741187
break;
1188+
case DEVICE_IMU_BNO080:
1189+
{
1190+
struct_BNO080 *nodeSetting = (struct_BNO080 *)deviceConfigPtr; //Create a local pointer that points to same spot as node does
1191+
if (strcmp(deviceSettingName, "log") == 0)
1192+
nodeSetting->log = d;
1193+
else if (strcmp(deviceSettingName, "logQuat") == 0)
1194+
nodeSetting->logQuat = d;
1195+
else if (strcmp(deviceSettingName, "logAccel") == 0)
1196+
nodeSetting->logAccel = d;
1197+
else if (strcmp(deviceSettingName, "logLinAccel") == 0)
1198+
nodeSetting->logLinAccel = d;
1199+
else if (strcmp(deviceSettingName, "logGyro") == 0)
1200+
nodeSetting->logGyro = d;
1201+
else if (strcmp(deviceSettingName, "logFastGyro") == 0)
1202+
nodeSetting->logFastGyro = d;
1203+
else if (strcmp(deviceSettingName, "logMag") == 0)
1204+
nodeSetting->logMag = d;
1205+
else if (strcmp(deviceSettingName, "logEuler") == 0)
1206+
nodeSetting->logEuler = d;
1207+
else
1208+
Serial.printf("Unknown device setting: %s\r\n", deviceSettingName);
1209+
}
1210+
break;
11751211
default:
11761212
Serial.printf("Unknown device type: %d\r\n", deviceType);
11771213
Serial.flush();

0 commit comments

Comments
 (0)