Recent implementation of a MLX90614 IR temperature sensor library based on the example code of Jonathan Jones. Working with the current I2C mbed library.

Dependents:   D7_MLX_AND_BAT

Fork of MLX90614 by Jens Strümper

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MLX90614.cpp Source File

MLX90614.cpp

00001 #include "MLX90614.h"
00002 
00003 MLX90614::MLX90614(I2C *i2c) : i2c_(i2c) {
00004 }
00005 
00006 float MLX90614::readTemp(uint8_t reg) {
00007     char cmd[3] = { 0 };
00008     cmd[0] = ram_access | reg;
00009     i2c_->write(default_addr, cmd, 1, true); 
00010     i2c_->read(default_addr, cmd, 3);
00011     return 0.02f * static_cast<float>(((cmd[1] & 0x7F) << 8) | cmd[0]) - 273.15f;
00012 }
00013 
00014 
00015 float MLX90614::ambientTemp(){
00016     return readTemp(T_ambient);
00017 }
00018 
00019 float MLX90614::objectTemp(){
00020     return readTemp(T_obj1);
00021 }