OK now that we have our calibration storage worked out, lets try writing a calibration to disk!

Load up the other example, sensor_calibration_write

You'll see that we first load any existing calibration from non-volatile storage with cal.loadCalibration(). Then we set the calibrations we want to save with:

// in uTesla
  cal.mag_hardiron[0] = -3.35;
  cal.mag_hardiron[1] = -0.74;
  cal.mag_hardiron[2] = -40.79;

  // in uTesla
  cal.mag_softiron[0] = 0.965;
  cal.mag_softiron[1] = 0.018;
  cal.mag_softiron[2] = 0.010;  
  cal.mag_softiron[3] = 0.018;
  cal.mag_softiron[4] = 0.960;
  cal.mag_softiron[5] = 0.003;  
  cal.mag_softiron[6] = 0.010;
  cal.mag_softiron[7] = 0.003;
  cal.mag_softiron[8] = 1.080;  

  // in Radians/s
  cal.gyro_zerorate[0] = 0.05;
  cal.gyro_zerorate[1] = -0.01;
  cal.gyro_zerorate[2] = -0.01;

which only changes the calibrations in temporary memory. Finally we run cal.saveCalibration() to write the calibration to permanent storage.

Upload this to your board.

EEPROM Example

If you use a chip with EEPROM, you'll see similar output from the previous page, this time you will get to see the HEX data stored in EEPROM. We use the same format as PJRC's NXPMotionSense library so you will see 0x75, 0x54 as the first two bytes of the data chunk

External FLASH example

If you use a chip with external flash, you should see similar output from the previous pre-check, but now it will write the calibration and also print out calibration file for you. You can see that it's stored in JSON format for easy parsing in Python or Arduino!

Reading back calibration

OK no matter which way you calibrated, now you can load the calibration read example to see the saved values loaded up and printed out!

For EEPROM:

For external FLASH:

This guide was first published on Feb 17, 2020. It was last updated on Feb 17, 2020.

This page (Calibration Write Check) was last updated on Oct 23, 2021.

Text editor powered by tinymce.