PlatformIO Community

MICROMOD ML BOARD + NRF52840 + ICM 20948 + PlatformIO


I have a problem using the ICM 20948 inside PlatformIO.

Hardware Setup: MicroMod ML carrier board + nRF52840 processor board + ICM 20948
Software tools: Arduino IDE and Visual Code with PlatformIO

When I upload the example Example1_Basics using the Arduino IDE, I get :
Scaled. Acc (mg) [ -00003.42, 00000.98, 01043.95 ], Gyr (DPS) [ 00001.53, -00000.29, 00000.91 ], Mag (uT) [ -00033.75, 00007.20, 00025.20 ], Tmp (C) [ 00025.54 ]
Scaled. Acc (mg) [ 00010.25, -00006.35, 01041.50 ], Gyr (DPS) [ 00002.85, -00000.05, 00002.42 ], Mag (uT) [ -00034.50, 00006.30, 00025.20 ], Tmp (C) [ 00025.73 ]

However, if I upload the same example using Platformio, I get:
Initialization of the sensor returned: Data Underflow
Trying again…

Some code other result.

In Arduino IDE and PlatformIO the MicroMod board is recognized ad Arduino Nano 33 BLE.

Is the board definition different between Arduino IDE and PlatformIO.

Any suggestions are welcome.
Thanks for the feedback.


  • What exact platformio.ini do you have?
  • I presume you are running this sketch?
  • What are the exact board settings in the Arduino IDE? (Screenshot of Tools menu)
  • In the Arduino IDE board manager, what version of the Arduino core that you are using with this board is it showing? This core and v2.1.0?

To get the board up and running in Arduino IDE (1.8.15) I have followed the instruction: MicroMod nRF52840 Processor Hookup Guide -
In the Arduino IDE Arduino mbed 1.3.1 is used and the Arduino IDE detect the MicroMod board, Board: “Sparkfun MicroMod nRF52840 Board”.

In PlatformIO
platform = nordicnrf52
board = nano33ble
framework = arduino
lib_deps = sparkfun/SparkFun 9DoF IMU Breakout - ICM 20948 - Arduino Library@^1.2.7

The simple Blink example is working, and sending a text to the serial monitor also works fine. However, the moment I try to read for example a sensor (Example1_Basics), it compiles but I get, for the ICM 20948, Initialization of the sensor returned: Data Underflow. Trying again…

Of course, I forget a detail, the nRF52840 Processor board uses the Arduino BLE bootloader however, the MicroMod has a different board definition.

I see they’re instructing there to add a custom variant folder, SF_MM_nRF52840_PB, to the core, along with boards.txt modificatations. So in PlatformIO you will have to do the equivalent of that.

Please change your platformio.ini to

platform = nordicnrf52@7.1.0
board = nano33ble
framework = arduino
board_build.variant = SF_MM_nRF52840_PB

( @7.1.0 is needed to get core version 1.3.2, bugfix of 1.3.1).

Rebuild your sketch. You should get errors now saying something like

arm-none-eabi-g++: error: C:\Users\Max\.platformio\packages\framework-arduino-mbed@1.3.2\variants\SF_MM_nRF52840_PB\includes.txt: No such file or directory

Open the above path to the variants folder (so for above e.g. C:\Users\Max\.platformio\packages\framework-arduino-mbed@1.3.2\variants\). Download the variant definition here and copy the SF_MM_nRF52840_PB from there into the variants folder. It should now look like


Then, rebuild the project. It should now give you a success.

RAM:   [==        ]  16.5% (used 43136 bytes from 262144 bytes)
Flash: [=         ]   7.8% (used 76604 bytes from 983040 bytes)
============== [SUCCESS] Took 13.93 seconds ==============
1 Like

I performed two tests: the 9DoF IMU Breakout - ICM 20948 and the acc on the MicroMod ML.
Both IMU and acc, work fine.

Thanks for the support!

Hi, I’ve tried the approach proposed by @maxgerhardt but upon building I get a cortex_m4.h not found. The full path to the complaining header is
~/.platformio/packages/framework-arduino-mbed@1.3.2/cores/arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/modules/nrfx/mdk/nrf52840.h:151:10: fatal error: core_cm4.h: No such file or directory
Looking for such cortex_m4.h header I found a candidate library, armmbed/cmsis-core but this doesn’t help.
Zero result on google about this so I’m now turning back to you for some help.
I’m on linux, and PlatformIO Core, version 6.0.1

Sparkfun updated the Arduino core version they’re using with their custom variant, so the answer is no longer valid. I’ll see what works now…

Irrelevant to the topic, just a side note: we are Saturday, I’m a fellow European writing from a place 10,000km East of Germany and as soon as I finished writing I see at the bottom of this page an icon reading “M replying…”. Nothing short of an incredibly responsive Max!

1 Like

Could you please try out GitHub - maxgerhardt/pio-MicroMod_Processor_Board-nRF52840?

1 Like

With your repo I have no more issue with the absence of cortex_m4.h header indeed and the build is a [SUCCESS] (with the same sketch as the one you mentioned).
Now this was only an exercise for me to try to solve another issue with the same nrf52840 “micromod” from sparkfun to work with their input and display carrier board (I have some issues with pin definitions, PWM0 pins not found though I see it in the pins_arduino.h in the SF_MM_nRF52840_PB variants of your original solution earlier but not in that of your updated one. [EDIT: the PWM0 is defined in the updated variant also].). But that will be for another topic unless I manage to solve it.
Many thanks for your updated solution to this post, have a good Saturday!

The sketch is in .ino format, if you put that code into a .cpp file, you must convert it according to Convert Arduino file to C++ manually — PlatformIO latest documentation. I.e., you should have after all #include lines…

void printPaddedInt16b(int16_t val);
void printRawAGMT(ICM_20948_AGMT_t agmt);
void printFormattedFloat(float val, uint8_t leading, uint8_t decimals);
#ifdef USE_SPI
void printScaledAGMT(ICM_20948_SPI *sensor);
void printScaledAGMT(ICM_20948_I2C *sensor);

for all function predeclarations.

If you don’t care about proper code completion (only possible in .c/.cpp files), rename the source file to src/main.ino instead of src/main.cpp.

1 Like

Yes, sorry I was too slow to edit my post, I had solved that … (It’s late here and I’m exhausted, hadn’t catch it fast enough, I was editing my post to say it builds successfully while you were replying).

Max, your solution DOES work also for using this nrf52840 board with the MicroMod input and display carrier board contrary to what I thought one post earlier…