11#include < Wire.h>
2+ #include < avr/pgmspace.h>
23// Similar to https://github.com/Levi--G/IMU-WhoAmIVerifier
34
45// Do be aware that MPU9150's will report as 6050s, this is because a 9150 is a 6050 with a magnetometer
@@ -16,12 +17,12 @@ typedef struct IMU {
1617 uint8_t Address2;
1718 uint8_t Register;
1819 uint8_t ExpectedID;
19- const char * IMUName PROGMEM ;
20- const char * IMUCapabilities PROGMEM ;
20+ const char * IMUName;
21+ const char * IMUCapabilities;
2122 bool LibSupported;
2223};
2324
24- const IMU IMUList[NUM_IMUS ] =
25+ const IMU IMUList[NUM_IMUS ] PROGMEM =
2526{
2627 {0x68 , 0x69 , 0x75 , 0x68 , " MPU6050" , " 3A,3G" , true },
2728 {0x68 , 0x69 , 0x75 , 0x70 , " MPU6500" , " 3A,3G" , true },
@@ -36,6 +37,7 @@ const IMU IMUList[NUM_IMUS] =
3637 {0x6B , 0x6A , 0x0F , 0x6A , " LSM6DSL or LSM6DS3TR-C" , " 3A,3G" , true },
3738 {0x68 , 0x69 , 0x75 , 0x98 , " ICM20689" , " 3A,3G" , true },
3839 {0x68 , 0x69 , 0x75 , 0x20 , " ICM20690" , " 3A,3G" , true },
40+ {0x68 , 0x69 , 0x00 , 0xEA , " ICM20948" , " 3A,3G,3M" , true },
3941 {0x6B , 0x6A , 0x00 , 0x05 , " QMI8658" , " 3A,3G" , true },
4042 {0x18 , 0x19 , 0x00 , 0xFA , " BMI055 or BMX055" , " 3A,3G or 3A,3G,3M" , true },
4143 {0x1E , 0x1E , 0x0C , 0x33 , " HMC5883L" , " 3M" , true },
@@ -61,7 +63,6 @@ const IMU IMUList[NUM_IMUS] =
6163 {0x68 , 0x69 , 0x00 , 0xE1 , " ICM20649" , " 3A,3G" , false },
6264 {0x68 , 0x69 , 0x75 , 0xA9 , " ICG20660" , " 3A,3G" , false },
6365 {0x68 , 0x69 , 0x75 , 0x91 , " IAM20680" , " 3A,3G" , false },
64- {0x68 , 0x69 , 0x00 , 0xEA , " ICM20948" , " 3A,3G,3M" , false },
6566 {0x68 , 0x69 , 0x75 , 0x6C , " IIM42351" , " 3A" , false },
6667 {0x68 , 0x69 , 0x75 , 0x6D , " IIM42352" , " 3A" , false },
6768 {0x68 , 0x69 , 0x75 , 0x4E , " ICM40627" , " 3A,3G" , false },
@@ -72,6 +73,12 @@ const IMU IMUList[NUM_IMUS] =
7273 {0x68 , 0x69 , 0x00 , 0x68 , " MPU3050" , " 3G" , false }
7374};
7475
76+ static inline IMU getIMU (uint8_t i) {
77+ IMU tmp;
78+ memcpy_P (&tmp, &IMUList[i], sizeof (IMU ));
79+ return tmp;
80+ }
81+
7582void setup () {
7683 Serial.begin (9600 );
7784 while (!Serial) ;
@@ -101,10 +108,11 @@ void loop() {
101108 bool detected = false ;
102109 for (int i = 0 ; i < NUM_IMUS ; i++)
103110 {
111+ IMU imu = getIMU (i);
104112#ifdef WIRE_HAS_TIMEOUT
105113 if (errorflag || Wire.getWireTimeoutFlag ()) {
106114 Serial.print (F (" Error while reading address 0x" ));
107- Serial.print (IMUList[i] .Address1 , HEX );
115+ Serial.print (imu .Address1 , HEX );
108116 Serial.print (F (" : " ));
109117 if (Wire.getWireTimeoutFlag ()) {
110118 Serial.println (F (" I2C bus timed out. (Bad IMU? check wiring.)" ));
@@ -119,16 +127,16 @@ void loop() {
119127 return ;
120128 }
121129#endif
122- if (readByte (IMUList[i] .Address1 , IMUList[i] .Register ) == IMUList[i] .ExpectedID )
130+ if (readByte (imu .Address1 , imu .Register ) == imu .ExpectedID )
123131 {
124132 detected = true ;
125133 Serial.print (F (" IMU Found: " ));
126- Serial.print (IMUList[i] .IMUName );
134+ Serial.print (imu .IMUName );
127135 Serial.print (F (" On address: 0x" ));
128- Serial.println (IMUList[i] .Address1 , HEX );
136+ Serial.println (imu .Address1 , HEX );
129137 Serial.print (F (" This IMU is capable of the following axis: " ));
130- Serial.println (IMUList[i] .IMUCapabilities );
131- if (IMUList[i] .LibSupported ) {
138+ Serial.println (imu .IMUCapabilities );
139+ if (imu .LibSupported ) {
132140 Serial.println (F (" This IMU is supported by the FastIMU library." ));
133141 }
134142 else
@@ -137,21 +145,21 @@ void loop() {
137145 }
138146 Serial.println (F (" ======================================" ));
139147 }
140- else if (readByte (IMUList[i] .Address2 , IMUList[i] .Register ) == IMUList[i] .ExpectedID )
148+ else if (readByte (imu .Address2 , imu .Register ) == imu .ExpectedID )
141149 {
142150 detected = true ;
143151 Serial.print (F (" IMU Found: " ));
144- Serial.print (IMUList[i] .IMUName );
152+ Serial.print (imu .IMUName );
145153 Serial.print (F (" On address: 0x" ));
146- Serial.println (IMUList[i] .Address2 , HEX );
154+ Serial.println (imu .Address2 , HEX );
147155 Serial.print (F (" This IMU is capable of the following axis: " ));
148- Serial.println (IMUList[i] .IMUCapabilities );
149- if (IMUList[i] .LibSupported ) {
156+ Serial.println (imu .IMUCapabilities );
157+ if (imu .LibSupported ) {
150158 Serial.println (F (" This IMU is supported by the FastIMU library." ));
151159 }
152160 else
153161 {
154- Serial.println (F (" This IMU is not supported by the FastIMU library." ));
162+ Serial.println (F (" This IMU is not supported by the FastIMU library." ));
155163 }
156164 Serial.println (F (" ======================================" ));
157165 }
0 commit comments