MLX90614 Faster read out of Temperature than 100 ms

Hello Arduino community,

I'm new to the Arduino area.
I'm trying to get a MLX90614 temperature sensor via I2C on a Nano to run.

It works so well. But I face the problem that I can read only every 100 ms a new temperature. Of course I can query the sensor faster, but then I get the same temperature several times. Does anyone have an idea how I can increase the readout rate?

Thanks for any help - Kauf

#include <Wire.h>               // I2C
#include <Adafruit_MLX90614.h>  //Thermopile IR Sensor
// Init MLX90614
    Adafruit_MLX90614 mlx = Adafruit_MLX90614();
 
void setup(void)
{  
// start serial port
    Serial.begin(2000000);
    while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port only
    }


// Start up the I2C Port
    Wire.begin();
  

// Start up the MLX 90614 IR- Sensor
    mlx.begin(); }


 
void loop(void)
{
          //mlx.begin();
          Serial.print(mlx.readObjectTempC());
          Serial.print("\t");
          Serial.println(millis());
}

See the MLX96014 data sheet for the maximum readout rate.

What are you trying to accomplish?

Also: how are you going to make sure the temperature in your system is the same at your sensor at such short times? It takes time for temperatures to equalise.

you can increase the speed of I2C bus, see Wire - Arduino Reference

try 400000 which is in practice about 2.5x faster than default 100000

tip of the day:
use ctrl-T to autoformat your code. will make it easier to read

I have a very fast temperature change. Within 0.1 second, the temperature change is over. That is, the change has its maximum after about 0.05 seconds. So that I can roughly estimate the temperature profile with at least one fit, I actually need at least 3-4 measuring points in the 0.1 second.

Can you post the output of the sketch you posted in message #1 above?

Then try this sketch, it makes 5 samples without printing the values. That is as fast as it can be done.

#include <Wire.h>
#include <Adafruit_MLX90614.h>  //Thermopile IR Sensor

Adafruit_MLX90614 mlx = Adafruit_MLX90614();
 
void setup(void)
{  
    Serial.begin(2000000);
    while (!Serial);

    Wire.begin();
    Wire.setClock(400000);
    mlx.begin(); 
}

 
void loop(void)
{
  float sample[5];

  uint32_t start = micros();
  for ( int i = 0; i < 5; i++)
  {
    sample[i] = mlx.readObjectTempC(); 
  }
  uint32_t stop = micros();

  Serial.print("Duration:\t");
  Serial.println(stop - start);
  Serial.print("Samples:\t");
  Serial.println(5);
  for ( int i = 0; i < 5; i++)
  {
    Serial.println(sample[i]);
  }
}
1 Like

Data sheet says:

On-chip filtering and settling time:
The MLX90614 features configurable on-chip digital filters. They allow customization for speed or noise.
Factory default configurations and the typical settling time and noise for the MLX90614 family are given below.
Device Settling time, sec Typical noise, °C rms Spike limit
MLX90614AAA, BAA, DAA 0.10 0.05 100%
Table 8: factory default IIR and FIR configuration, settling time and typical noise
Details on the filters are given in the application note “Understanding MLX90614 on-chip digital signal
filters” available from www.melexis.com.

Or this sketch that waits until there is a large enough change detected and it makes 50 samples

#include <Wire.h>
#include <Adafruit_MLX90614.h>  //Thermopile IR Sensor

Adafruit_MLX90614 mlx = Adafruit_MLX90614();
 
void setup(void)
{  
  Serial.begin(2000000);
  while (!Serial);

  Wire.begin();
  Wire.setClock(400000);
  mlx.begin(); 
}

 
void loop(void)
{
  float sample[50];
  float threshold = 1.0;

  // WAIT FOR TEMP TO CHANGE MORE THAN THRESHOLD
  sample[0] = mlx.readObjectTempC();
  do
  {
    sample[1] = mlx.readObjectTempC();
  } while(abs(sample[1] - sample[0] < threshold)
  
  // MAKE UP TO 50 SAMPLES
  uint32_t start = micros();
  for ( int i = 2; i < 50; i++)
  {
    sample[i] = mlx.readObjectTempC(); 
  }
  uint32_t stop = micros();

  // PRINT ALL SAMPLES
  Serial.print("   START:\t");
  Serial.println(start);
  Serial.print("    STOP:\t");
  Serial.println(stop);
  Serial.print("DURATION:\t");
  Serial.println(stop - start);
  Serial.print(" SAMPLES:\t");
  Serial.println(50);
  for ( int i = 0; i < 50; i++)
  {
    Serial.print(i);
    Serial.print('\t');
    Serial.println(sample[i]);
  }
}

Just had a look at the sensor's data sheet (which of course you did already, didn't you?).

For faster sampling you may tap into the continuous PWM output this sensor offers:

The 10-bit PWM is as a standard configured to transmit continuously the measured object temperature for an object temperature range of -20 to 120 ˚C with an output resolution of 0.14 ˚C.

This way you can receive one sample every 1.024 ms, so almost 1000 samples per second. Your big challenge with that is to retain only the data of interest as an Arduino can record no more than about half a second of such data in its RAM (2 bytes per reading makes for 2048 bytes per second - and that's the same as all the RAM an ATmega328 processor has - including what is needed to run your program).

I2C with all it's overhead, plus the need for the sensor to do a temperature conversion, means that it is comparatively slow. As you say you can read faster but you get the same temperature reading, the sensor probably converts only ten times a second. I'm sure you can find the details of that in the data sheet, as you will be able to find the details on how that PWM works exactly (if your library doesn't support it).

The "settling time" specfies how rapidly the device responds to changes in the object temperature and that is 0.1 seconds (see reply #7).

Therefore, it does not make any sense to read temperatures faster than 10 times per second.

@robtillart: The output from the sketch from post 1:

22.31	0
22.31	1
22.31	2
22.31	3
22.35	4
22.35	5
22.35	6
22.35	7
22.35	8
22.35	9
22.35	10
22.35	11
22.35	13
22.35	14
22.35	15
22.35	16
22.35	17
22.35	18
22.35	19
22.35	20
22.35	21
22.35	22
22.35	23
22.35	24
22.35	25
22.35	26
22.35	27
22.35	28
22.35	29
22.35	30
22.35	31
22.35	32
22.35	33
22.35	34
22.35	35
22.35	36
22.35	37
22.35	39
22.35	40
22.35	41
22.35	43
22.35	44
22.35	45
22.35	46
22.35	47
22.35	48
22.35	49
22.35	50
22.35	51
22.35	52
22.35	53
22.35	54
22.35	55
22.35	56
22.35	57
22.35	58
22.35	59
22.35	60
22.35	61
22.35	62
22.35	63
22.35	64
22.35	66
22.35	67
22.35	68
22.35	69
22.35	70
22.35	71
22.35	72
22.35	73
22.35	74
22.35	75
22.35	76
22.35	77
22.35	78
22.35	79
22.35	80
22.35	81
22.35	82
22.35	83
22.35	84
22.35	86
22.35	87
22.35	88
22.35	89
22.35	90
22.35	91
22.35	92
22.35	94
22.35	95
22.35	96
22.35	97
22.35	98
22.35	99
22.35	100
22.35	101
22.35	102
22.31	103
22.31	104
22.31	105
22.31	106
22.31	107
22.31	108
22.31	110
22.31	111
22.31	112
22.31	113
22.31	114
22.31	115
22.31	116
22.31	117
22.31	118
22.31	119
22.31	120
22.31	121
22.31	123
22.31	124
22.31	125
22.31	126
22.31	128
22.31	129
22.31	130
22.31	131
22.31	132
22.31	133
22.31	134
22.31	135
22.31	137
22.31	138
22.31	139
22.31	140
22.31	141
22.31	142
22.31	143
22.31	144
22.31	145
22.31	146
22.31	147
22.31	148
22.31	150
22.31	151
22.31	152
22.31	153
22.31	154
22.31	155
22.31	156
22.31	157
22.31	158
22.31	159
22.31	160
22.31	161
22.31	163
22.31	164
22.31	165
22.31	166
22.31	167
22.31	168
22.31	169
22.31	171
22.31	172
22.31	173
22.31	174
22.31	175
22.31	177
22.31	178
22.31	179
22.31	180
22.31	181
22.31	182
22.31	183
22.31	184
22.31	185
22.31	186
22.31	187
22.31	188
22.31	190
22.31	191
22.31	192
22.31	193
22.31	194
22.31	195
22.31	196
22.31	197
22.31	198
22.31	199
22.31	200

As you can see, the temperature will change about every 100 ms as described in the datasheet, which is too slow for me.

I also added Wire.setClock(400000); but the temperature will also change every 100 ms.

I want to give PWM a try but have no Idea how to prog it because I am a newbie...
Using google I could not find a arduino lib for using PWM with the MLX90614.

But I found this MLX app note: MLX App note for PWM

kaufpark:
As you can see, the temperature will change about every 100 ms as described in the datasheet, which is too slow for me.

I think this is simply not the correct sensor for you.
Actually I can't find the update frequency in the data sheet, but other web sites refer to a 0.1 second minimum update time.

Hi friends.
you have Some news for configure the mlx90614 in pwm mode.

im search this code. for make it.