Einstein Filho
/
MLX90614
Mangue Baja Personalized MLX program
MLX90614.cpp@2:5e50e3dd1d17, 2019-08-01 (annotated)
- Committer:
- einsteingustavo
- Date:
- Thu Aug 01 11:43:08 2019 +0000
- Revision:
- 2:5e50e3dd1d17
- Parent:
- 0:755bd47fd6be
Mangue Baja Personalized MLX program
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(PinName sda, PinName scl) |
jensstruemper | 0:755bd47fd6be | 4 | { |
jensstruemper | 0:755bd47fd6be | 5 | i2c_ = new I2C(sda, scl); |
jensstruemper | 0:755bd47fd6be | 6 | i2c_->frequency(400000); |
jensstruemper | 0:755bd47fd6be | 7 | } |
jensstruemper | 0:755bd47fd6be | 8 | |
jensstruemper | 0:755bd47fd6be | 9 | MLX90614::MLX90614(I2C *i2c) : i2c_(i2c) { |
jensstruemper | 0:755bd47fd6be | 10 | } |
jensstruemper | 0:755bd47fd6be | 11 | |
jensstruemper | 0:755bd47fd6be | 12 | MLX90614::~MLX90614() { |
jensstruemper | 0:755bd47fd6be | 13 | delete i2c_; |
jensstruemper | 0:755bd47fd6be | 14 | } |
jensstruemper | 0:755bd47fd6be | 15 | |
jensstruemper | 0:755bd47fd6be | 16 | float MLX90614::get_temp(uint8_t reg) { |
jensstruemper | 0:755bd47fd6be | 17 | char cmd[3] = { 0 }; |
jensstruemper | 0:755bd47fd6be | 18 | // read the temperature data (kelvin) |
jensstruemper | 0:755bd47fd6be | 19 | cmd[0] = ram_access | reg; |
jensstruemper | 0:755bd47fd6be | 20 | i2c_->write(default_addr,cmd,1,true); i2c_->read(default_addr,cmd,3); |
jensstruemper | 0:755bd47fd6be | 21 | // convert to meaningful units, still in kelvin - just normalized |
jensstruemper | 0:755bd47fd6be | 22 | return 0.02 * static_cast<float>((cmd[1]<<8)|cmd[0]); |
jensstruemper | 0:755bd47fd6be | 23 | } |
jensstruemper | 0:755bd47fd6be | 24 | |
jensstruemper | 0:755bd47fd6be | 25 | float MLX90614::read_temp(int select) { |
jensstruemper | 0:755bd47fd6be | 26 | uint8_t reg_addrs[] = { T_ambient, T_obj1 }; |
jensstruemper | 0:755bd47fd6be | 27 | float tt = 0.0; |
jensstruemper | 0:755bd47fd6be | 28 | if (select == 0){ |
jensstruemper | 0:755bd47fd6be | 29 | tt = get_temp(reg_addrs[0])-273.15; |
jensstruemper | 0:755bd47fd6be | 30 | } |
jensstruemper | 0:755bd47fd6be | 31 | if (select == 1){ |
jensstruemper | 0:755bd47fd6be | 32 | tt = get_temp(reg_addrs[1])-273.15; |
jensstruemper | 0:755bd47fd6be | 33 | } |
jensstruemper | 0:755bd47fd6be | 34 | return tt; |
jensstruemper | 0:755bd47fd6be | 35 | } |