Recent implementation of a MLX90614 IR temperature sensor library based on the example code of Jonathan Jones. Working with the current I2C mbed library.
Fork of MLX90614 by
MLX90614.cpp@1:b70477df5c75, 2017-02-17 (annotated)
- Committer:
- shawe
- Date:
- Fri Feb 17 12:51:18 2017 +0000
- Revision:
- 1:b70477df5c75
- Parent:
- 0:755bd47fd6be
refactored;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jensstruemper | 0:755bd47fd6be | 1 | #include "MLX90614.h" |
jensstruemper | 0:755bd47fd6be | 2 | |
jensstruemper | 0:755bd47fd6be | 3 | MLX90614::MLX90614(I2C *i2c) : i2c_(i2c) { |
jensstruemper | 0:755bd47fd6be | 4 | } |
jensstruemper | 0:755bd47fd6be | 5 | |
shawe | 1:b70477df5c75 | 6 | float MLX90614::readTemp(uint8_t reg) { |
shawe | 1:b70477df5c75 | 7 | char cmd[3] = { 0 }; |
shawe | 1:b70477df5c75 | 8 | cmd[0] = ram_access | reg; |
shawe | 1:b70477df5c75 | 9 | i2c_->write(default_addr, cmd, 1, true); |
shawe | 1:b70477df5c75 | 10 | i2c_->read(default_addr, cmd, 3); |
shawe | 1:b70477df5c75 | 11 | return 0.02f * static_cast<float>(((cmd[1] & 0x7F) << 8) | cmd[0]) - 273.15f; |
shawe | 1:b70477df5c75 | 12 | } |
shawe | 1:b70477df5c75 | 13 | |
shawe | 1:b70477df5c75 | 14 | |
shawe | 1:b70477df5c75 | 15 | float MLX90614::ambientTemp(){ |
shawe | 1:b70477df5c75 | 16 | return readTemp(T_ambient); |
shawe | 1:b70477df5c75 | 17 | } |
shawe | 1:b70477df5c75 | 18 | |
shawe | 1:b70477df5c75 | 19 | float MLX90614::objectTemp(){ |
shawe | 1:b70477df5c75 | 20 | return readTemp(T_obj1); |
shawe | 1:b70477df5c75 | 21 | } |