Added the functions to read and set the emissivity of the sensor.
Diff: mlx90614.cpp
- Revision:
- 5:3c4431224932
- Parent:
- 2:01d333d06727
- Child:
- 6:689f0dab386c
diff -r dcd4fe76bd13 -r 3c4431224932 mlx90614.cpp --- a/mlx90614.cpp Thu Jun 09 13:50:26 2011 +0000 +++ b/mlx90614.cpp Mon May 11 17:28:37 2020 +0000 @@ -45,4 +45,136 @@ *temp_val=temp_thermo-273; //Convert kelvin to degree Celsius return true; //load data successfully, return true -} \ No newline at end of file +} + +float MLX90614::GetEmissivity(void) { + char p1,p2,p3; + float temp_thermo; + bool ch; + + i2c_thermo.stop(); //stop i2c if not ack + wait(0.01); + i2c_thermo.start(); //start I2C + ch=i2c_thermo.write(MLX96014_ADDRESS); //device address with write condition + + if(!ch)return -90.0f; //No Ack, return False + + ch=i2c_thermo.write(0x24); //device ram address where Tobj value is present + + if(!ch)return -91.0f; //No Ack, return False + + + i2c_thermo.start(); //repeat start + ch=i2c_thermo.write(MLX96014_ADDRESS|0x01); //device address with read condition + if(!ch)return -92.0f; //No Ack, return False + + p1=i2c_thermo.read(1); //Tobj low byte + p2=i2c_thermo.read(1); //Tobj heigh byte + p3=i2c_thermo.read(0); //PEC + + i2c_thermo.stop(); //stop condition + semaDHT.acquire(); + debug("p2: %02X, p1: %02X\r\n",p2,p1); + semaDHT.release(); + + //temp_thermo=((((p2&0x007f)<<8)+p1)*0.02)-0.01; //degree centigrate conversion + //*temp_val=temp_thermo-273; //Convert kelvin to degree Celsius + + return (((p2<<8) + p1)/65535.0f); //load data successfully, return true +} + +int MLX90614::BlankEEPROM(int em) { + uint8_t p1[5]; + float temp_thermo; + bool ch; + +//CRC for this config is 0x3B + p1[0]=MLX96014_ADDRESS; + p1[1]=0x24; + p1[2]=0x00; + p1[3]=0x00; + + // uint8_t crc = crc8(p1, 4); + // debug("CRC: 0x%02X\r\n",crc); + + i2c_thermo.stop(); //stop i2c if not ack + wait(0.01); + i2c_thermo.start(); //start I2C + ch=i2c_thermo.write(p1[0]); //device address with write condition + if(!ch)return -1; //No Ack, return False + + ch=i2c_thermo.write(p1[1]); //device ram address where Tobj value is present + if(!ch)return -2; //No Ack, return False + + ch = i2c_thermo.write(p1[3]); //Tobj low byte + if (!ch) return -3; + + ch = i2c_thermo.write(p1[2]); //Tobj heigh byte + if (!ch) return -4; + + + + ch = i2c_thermo.write(em); + if (!ch) return -5; + + i2c_thermo.stop(); //stop condition + + debug("Em: %1.3f\r\n",MLX90617_GetEmissivity()); + + return 0; +} + +int MLX90614::SetEmissivity(float em, uint8_t lclCrc) { + uint8_t p1[5]; + float temp_thermo; + bool ch; + uint16_t number; + //uint8_t *num[2]; + + temp_thermo = 65535.0f * em; + number=temp_thermo; + uint8_t num[2]; + + num[0] = number & 0xFF; + num[1] = number >> 8; + + //debug("F: %1.3f, INt: %d, H:%02X, L: %02X\r\n",temp_thermo,number,num[1],num[0]); +// //CRC for this config is 0x3B +// p1[0]=thermometer.i2caddress; +// p1[1]=0x24; +// p1[2]=0x19; +// p1[3]=0x99; + +//CRC for this config is 0x05 + p1[0]=MLX96014_ADDRESS; + p1[1]=0x24; + p1[2]=num[0]; + p1[3]=num[1]; + + // uint8_t crc = crc8(p1, 4); + // debug("CRC: 0x%02X\r\n",crc); + + i2c_thermo.stop(); //stop i2c if not ack + wait(0.01); + i2c_thermo.start(); //start I2C + ch=i2c_thermo.write(p1[0]); //device address with write condition + if(!ch)return -1; //No Ack, return False + + ch=i2c_thermo.write(p1[1]); //device ram address where Tobj value is present + if(!ch)return -2; //No Ack, return False + + ch = i2c_thermo.write(p1[2]); //Tobj low byte + if (!ch) return -3; + + ch = i2c_thermo.write(p1[3]); //Tobj heigh byte + if (!ch) return -4; + + ch = i2c_thermo.write(lclCrc); + if (!ch) return -5; + + i2c_thermo.stop(); //stop condition + + debug("Em: %1.3f\r\n",MLX90617_GetEmissivity()); + + return 0; +}