![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
I2C MLX90614 InfraRed Thermo sensor
mlx90614.cpp@1:99681219efbe, 2016-10-26 (annotated)
- Committer:
- rkuo2000
- Date:
- Wed Oct 26 03:32:53 2016 +0000
- Revision:
- 1:99681219efbe
- Parent:
- 0:0f4840f6bf23
update to mbed OS 5.2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rkuo2000 | 0:0f4840f6bf23 | 1 | #include "mbed.h" |
rkuo2000 | 0:0f4840f6bf23 | 2 | #include "mlx90614.h" |
rkuo2000 | 0:0f4840f6bf23 | 3 | |
rkuo2000 | 0:0f4840f6bf23 | 4 | I2C mlx90614_i2c(PD_12, PD_10); // I2C1_SDA, I2C1_SCL |
rkuo2000 | 0:0f4840f6bf23 | 5 | |
rkuo2000 | 0:0f4840f6bf23 | 6 | void MLX90614_WriteByte(uint8_t MLX90614_reg, uint8_t MLX90614_data) |
rkuo2000 | 0:0f4840f6bf23 | 7 | { |
rkuo2000 | 0:0f4840f6bf23 | 8 | char data_out[2]; |
rkuo2000 | 0:0f4840f6bf23 | 9 | data_out[0]= MLX90614_reg; |
rkuo2000 | 0:0f4840f6bf23 | 10 | data_out[1]= MLX90614_data; |
rkuo2000 | 0:0f4840f6bf23 | 11 | mlx90614_i2c.write(MLX90614_slave_addr, data_out, 2, 0); |
rkuo2000 | 0:0f4840f6bf23 | 12 | } |
rkuo2000 | 0:0f4840f6bf23 | 13 | |
rkuo2000 | 0:0f4840f6bf23 | 14 | uint16_t MLX90614_ReadByte(uint8_t MLX90614_reg) |
rkuo2000 | 0:0f4840f6bf23 | 15 | { |
rkuo2000 | 0:0f4840f6bf23 | 16 | char data_out[1], data_in[3]; |
rkuo2000 | 0:0f4840f6bf23 | 17 | data_out[0] = MLX90614_reg; |
rkuo2000 | 0:0f4840f6bf23 | 18 | mlx90614_i2c.write(MLX90614_slave_addr, data_out, 1, 1); |
rkuo2000 | 0:0f4840f6bf23 | 19 | mlx90614_i2c.read(MLX90614_slave_addr, data_in, 3, 0); |
rkuo2000 | 0:0f4840f6bf23 | 20 | return ((data_in[1]<<8)+data_in[0]); |
rkuo2000 | 0:0f4840f6bf23 | 21 | } |
rkuo2000 | 0:0f4840f6bf23 | 22 | |
rkuo2000 | 0:0f4840f6bf23 | 23 | uint16_t MLX90614::getTA() |
rkuo2000 | 0:0f4840f6bf23 | 24 | { |
rkuo2000 | 0:0f4840f6bf23 | 25 | uint16_t t; |
rkuo2000 | 0:0f4840f6bf23 | 26 | t = MLX90614_ReadByte(MLX90614_TA); // Ambient Temperature |
rkuo2000 | 0:0f4840f6bf23 | 27 | return ((t*2) - 27315) /100; |
rkuo2000 | 0:0f4840f6bf23 | 28 | } |
rkuo2000 | 0:0f4840f6bf23 | 29 | |
rkuo2000 | 0:0f4840f6bf23 | 30 | uint16_t MLX90614::getTOBJ1() |
rkuo2000 | 0:0f4840f6bf23 | 31 | { |
rkuo2000 | 0:0f4840f6bf23 | 32 | uint16_t t; |
rkuo2000 | 0:0f4840f6bf23 | 33 | t = MLX90614_ReadByte(MLX90614_TOBJ1); // Object Temperature 1 |
rkuo2000 | 0:0f4840f6bf23 | 34 | return ((t*2) - 27315) /100; |
rkuo2000 | 0:0f4840f6bf23 | 35 | } |