Why Is the Sampling Rate of the TMAG5273 Sensor on Arduino UNO Lower Than Expected?

We are using an Arduino UNO and the TMAG5273 sensor (purchased from SparkFun Linear 3D Hall-Effect Sensor - TMAG5273 (Qwiic) - SEN-23880 - SparkFun Electronics) to measure changes in a rapidly fluctuating magnetic field.

Based on the datasheet, we have configured the registers as follows:

  • DEVICE_CONFIG_1 (Bits 4-2, CONV_AVG): 0h (1x average, 10.0-kSPS (3-axes) or 20-kSPS (1 axis))
  • DEVICE_CONFIG_2 (Bits 1-0, OPERATING_MODE): 2h (Continuous measure mode)
  • SENSOR_CONFIG_1 (Bits 7-4, MAG_CH_EN): 4h (Z channel enabled)

Using the Arduino code we implemented, we collected data output to the serial monitor for 1 second, resulting in approximately 1100 samples, which translates to 1.1 kSPS. This is significantly lower than the 20 kSPS value mentioned in the datasheet.

We would like to request assistance to understand why this discrepancy occurs. The library files were downloaded from the following site: GitHub - sparkfun/SparkFun_TMAG5273_Arduino_Library: Communicates with the TMAG5273 over I2C to quickly integrate a Hall-effect sensor into your project.

We have attached the Arduino file we used, and would appreciate it if you could review it.

#include <Wire.h>            // Used to establish serial communication on the I2C bus
#include "SparkFun_TMAG5273_Arduino_Library.h" // Used to send and recieve specific information from our sensor

TMAG5273 sensor; // Initialize hall-effect sensor

uint8_t i2cAddress = 0x22; 
void setup() 
{
  Wire.begin();
  Wire.setClock(1000000);
  // Start serial communication at 115200 baud
  Serial.begin(115200);  

  // Begin example of the magnetic sensor code (and add whitespace for easy reading)
  Serial.println("TMAG5273 Example 1: Basic Readings");
  Serial.println("");

  // If begin is successful (0), then start example
  if(sensor.begin(i2cAddress, Wire) == 1)
  {
    Serial.println("Begin");
  }
  else // Otherwise, infinite loop
  {
    Serial.println("Device failed to setup - Freezing code.");
    while(1); // Runs forever
  }
  Serial.println("CLEARDATA");
  Serial.println("LABEL,x [mT],y [mT],z [mT]");

  sensor.setOperatingMode(2);  
  sensor.setConvAvg(0); 
  sensor.setMagneticChannel(7);
}

void loop() 
{
  // Checks if mag channels are on - turns on in setup
  if(sensor.getMagneticChannel() != 0) 
  {
    float magX = sensor.getXData();
    float magY = sensor.getYData();
    float magZ = sensor.getZData();
    // float Mag = sensor.getAngleResult();
    // float Magnitude = sensor.getMagnitudeResult();
    // float ZTH = sensor.getZThreshold();
    // uint8_t IntPint = sensor.getInterruptPinStatus(); 
    // float magZraw = sensor.getZrawData();
    // uint8_t IntMode = sensor.getInterruptMode(); 
    // uint8_t range = sensor.getXYAxisRange(); 
    // uint8_t range = sensor.getZAxisRange(); 
    // uint16_t ID = sensor.getManufacturerID(); 
    // uint8_t Add = sensor.getI2CAddress(); 
    // uint8_t DevStat = sensor.getDeviceStatus(); 
   Serial.print(magZraw);
    //Serial.print(" ");
    //Serial.print("DATA,");
    Serial.print(magX);
    Serial.print(",");
    Serial.print(magY);
    Serial.print(",");
    Serial.println(magZ); 
  }
  else
  {
    // If there is an issue, stop the magnetic readings and restart sensor/example
    Serial.println("Mag Channels disabled, stopping..");
    while(1);
  }
  delay(200);
}

It looks like the sketch/program shared sets them too;

sensor.setOperatingMode(2);
sensor.setConvAvg(0);
sensor.setMagneticChannel(7);

Try changing those too (and perhaps disabling /comment out all unneeded code)