Single and Dual Zone Infra Red Thermometer
MLX90614.h@2:1d6817048eb1, 2017-12-26 (annotated)
- Committer:
- mcm
- Date:
- Tue Dec 26 10:09:48 2017 +0000
- Revision:
- 2:1d6817048eb1
- Parent:
- 1:df258d25fd8a
- Child:
- 3:6a5b6fcff28e
Function file is ready to be tested.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mcm | 1:df258d25fd8a | 1 | /** |
mcm | 1:df258d25fd8a | 2 | * @brief MLX90614.h |
mcm | 1:df258d25fd8a | 3 | * @details Single and Dual Zone Infra Red Thermometer. |
mcm | 1:df258d25fd8a | 4 | * Header file. |
mcm | 1:df258d25fd8a | 5 | * |
mcm | 1:df258d25fd8a | 6 | * |
mcm | 1:df258d25fd8a | 7 | * @return NA |
mcm | 1:df258d25fd8a | 8 | * |
mcm | 1:df258d25fd8a | 9 | * @author Manuel Caballero |
mcm | 1:df258d25fd8a | 10 | * @date 26/December/2017 |
mcm | 1:df258d25fd8a | 11 | * @version 26/December/2017 The ORIGIN |
mcm | 1:df258d25fd8a | 12 | * @pre NaN. |
mcm | 1:df258d25fd8a | 13 | * @warning NaN |
mcm | 1:df258d25fd8a | 14 | * @pre This code belongs to AqueronteBlog ( http://unbarquero.blogspot.com ). |
mcm | 1:df258d25fd8a | 15 | */ |
mcm | 1:df258d25fd8a | 16 | #ifndef MLX90614_H |
mcm | 1:df258d25fd8a | 17 | #define MLX90614_H |
mcm | 1:df258d25fd8a | 18 | |
mcm | 1:df258d25fd8a | 19 | #include "mbed.h" |
mcm | 1:df258d25fd8a | 20 | |
mcm | 1:df258d25fd8a | 21 | |
mcm | 1:df258d25fd8a | 22 | /** |
mcm | 1:df258d25fd8a | 23 | Example: |
mcm | 1:df258d25fd8a | 24 | |
mcm | 1:df258d25fd8a | 25 | [TODO] |
mcm | 1:df258d25fd8a | 26 | */ |
mcm | 1:df258d25fd8a | 27 | |
mcm | 1:df258d25fd8a | 28 | |
mcm | 1:df258d25fd8a | 29 | /*! |
mcm | 1:df258d25fd8a | 30 | Library for the MLX90614 Single and Dual Zone Infra Red Thermometer. |
mcm | 1:df258d25fd8a | 31 | */ |
mcm | 1:df258d25fd8a | 32 | class MLX90614 |
mcm | 1:df258d25fd8a | 33 | { |
mcm | 1:df258d25fd8a | 34 | public: |
mcm | 1:df258d25fd8a | 35 | /** |
mcm | 1:df258d25fd8a | 36 | * @brief DEFAULT ADDRESSES |
mcm | 1:df258d25fd8a | 37 | */ |
mcm | 1:df258d25fd8a | 38 | typedef enum { |
mcm | 1:df258d25fd8a | 39 | MLX90614_ADDRESS = ( 0x5A << 1 ) /*!< MLX90614 I2C Address */ |
mcm | 1:df258d25fd8a | 40 | } MLX90614_address_t; |
mcm | 1:df258d25fd8a | 41 | |
mcm | 1:df258d25fd8a | 42 | |
mcm | 1:df258d25fd8a | 43 | // COMMANDS |
mcm | 1:df258d25fd8a | 44 | /** |
mcm | 1:df258d25fd8a | 45 | * @brief COMMANDS |
mcm | 1:df258d25fd8a | 46 | */ |
mcm | 1:df258d25fd8a | 47 | typedef enum { |
mcm | 1:df258d25fd8a | 48 | MLX90614_RAM_ACCESS = 0b00011111, /*!< Seconds. RANGE 00-59 */ |
mcm | 1:df258d25fd8a | 49 | MLX90614_EEPROM_ACCESS = 0b00100000, /*!< LSB of Temp */ |
mcm | 1:df258d25fd8a | 50 | MLX90614_FLAGS = 0b11110000, /*!< LSB of Temp */ |
mcm | 1:df258d25fd8a | 51 | MLX90614_SLEEP = 0b11111111 /*!< LSB of Temp */ |
mcm | 1:df258d25fd8a | 52 | } MLX90614_command_t; |
mcm | 1:df258d25fd8a | 53 | |
mcm | 1:df258d25fd8a | 54 | |
mcm | 1:df258d25fd8a | 55 | // REGISTERS |
mcm | 1:df258d25fd8a | 56 | /** |
mcm | 1:df258d25fd8a | 57 | * @brief EEPROM REGISTERS |
mcm | 1:df258d25fd8a | 58 | */ |
mcm | 1:df258d25fd8a | 59 | typedef enum { |
mcm | 1:df258d25fd8a | 60 | MLX90614_TO_MAX = ( MLX90614_EEPROM_ACCESS | 0x00 ), /*!< To max */ |
mcm | 1:df258d25fd8a | 61 | MLX90614_TO_MIN = ( MLX90614_EEPROM_ACCESS | 0x01 ), /*!< To min */ |
mcm | 1:df258d25fd8a | 62 | MLX90614_PWMCTRL = ( MLX90614_EEPROM_ACCESS | 0x02 ), /*!< PWMCTRL */ |
mcm | 1:df258d25fd8a | 63 | MLX90614_TA_RANGE = ( MLX90614_EEPROM_ACCESS | 0x03 ), /*!< Ta range */ |
mcm | 1:df258d25fd8a | 64 | MLX90614_EMISSIVITY_CORRECTION_COEFFICIENT = ( MLX90614_EEPROM_ACCESS | 0x04 ), /*!< Emissivity correction coefficient */ |
mcm | 1:df258d25fd8a | 65 | MLX90614_CONFIG_REGISTER_1 = ( MLX90614_EEPROM_ACCESS | 0x05 ), /*!< Config Register1 */ |
mcm | 1:df258d25fd8a | 66 | MLX90614_SMBUS_ADDRESS = ( MLX90614_EEPROM_ACCESS | 0x0E ), /*!< SMBus address (LSByte only) */ |
mcm | 1:df258d25fd8a | 67 | MLX90614_ID_NUMBER_0 = ( MLX90614_EEPROM_ACCESS | 0x0C ), /*!< ID number */ |
mcm | 1:df258d25fd8a | 68 | MLX90614_ID_NUMBER_1 = ( MLX90614_EEPROM_ACCESS | 0x0D ), /*!< ID number */ |
mcm | 1:df258d25fd8a | 69 | MLX90614_ID_NUMBER_2 = ( MLX90614_EEPROM_ACCESS | 0x0E ), /*!< ID number */ |
mcm | 1:df258d25fd8a | 70 | MLX90614_ID_NUMBER_3 = ( MLX90614_EEPROM_ACCESS | 0x0F ) /*!< ID number */ |
mcm | 1:df258d25fd8a | 71 | } MLX90614_eeprom_registers_t; |
mcm | 1:df258d25fd8a | 72 | |
mcm | 1:df258d25fd8a | 73 | |
mcm | 1:df258d25fd8a | 74 | /** |
mcm | 1:df258d25fd8a | 75 | * @brief RAM REGISTERS |
mcm | 1:df258d25fd8a | 76 | */ |
mcm | 1:df258d25fd8a | 77 | typedef enum { |
mcm | 1:df258d25fd8a | 78 | MLX90614_RAW_DATA_IR_CHANNEL_1 = ( MLX90614_RAM_ACCESS & 0x04 ), /*!< Raw data IR channel 1 */ |
mcm | 1:df258d25fd8a | 79 | MLX90614_RAW_DATA_IR_CHANNEL_2 = ( MLX90614_RAM_ACCESS & 0x05 ), /*!< Raw data IR channel 2 */ |
mcm | 1:df258d25fd8a | 80 | MLX90614_TA = ( MLX90614_RAM_ACCESS & 0x06 ), /*!< TA */ |
mcm | 1:df258d25fd8a | 81 | MLX90614_TOBJ_1 = ( MLX90614_RAM_ACCESS & 0x07 ), /*!< TOBJ 1 */ |
mcm | 1:df258d25fd8a | 82 | MLX90614_TOBJ_2 = ( MLX90614_RAM_ACCESS & 0x08 ) /*!< TOBJ 2 */ |
mcm | 1:df258d25fd8a | 83 | } MLX90614_ram_registers_t; |
mcm | 1:df258d25fd8a | 84 | |
mcm | 1:df258d25fd8a | 85 | |
mcm | 1:df258d25fd8a | 86 | |
mcm | 1:df258d25fd8a | 87 | // COMMANDS |
mcm | 1:df258d25fd8a | 88 | /** |
mcm | 1:df258d25fd8a | 89 | * @brief FLAGS |
mcm | 1:df258d25fd8a | 90 | */ |
mcm | 1:df258d25fd8a | 91 | typedef enum { |
mcm | 1:df258d25fd8a | 92 | FLAG_EEBUSY_HIGH = ( 1 << 7 ), /*!< The previous write/erase EEPROM access is still in progress. High active */ |
mcm | 1:df258d25fd8a | 93 | FLAG_EEBUSY_LOW = ( 0 << 7 ), /*!< The previous write/erase EEPROM access is still in progress. LOW */ |
mcm | 1:df258d25fd8a | 94 | FLAG_EE_DEAD_HIGH = ( 1 << 5 ), /*!< EEPROM double error has occurred. High active */ |
mcm | 1:df258d25fd8a | 95 | FLAG_EE_DEAD_LOW = ( 0 << 5 ), /*!< EEPROM double error has occurred. LOW */ |
mcm | 1:df258d25fd8a | 96 | FLAG_INIT_LOW = ( 0 << 4 ), /*!< POR initialization routine is still ongoing. Low active */ |
mcm | 1:df258d25fd8a | 97 | FLAG_INIT_HIGH = ( 1 << 4 ) /*!< POR initialization routine is still ongoing. HIGH */ |
mcm | 1:df258d25fd8a | 98 | } MLX90614_flags_t; |
mcm | 1:df258d25fd8a | 99 | |
mcm | 1:df258d25fd8a | 100 | |
mcm | 1:df258d25fd8a | 101 | /** |
mcm | 1:df258d25fd8a | 102 | * @brief CONFIG REGISTER 1 |
mcm | 1:df258d25fd8a | 103 | */ |
mcm | 1:df258d25fd8a | 104 | // IIR |
mcm | 1:df258d25fd8a | 105 | typedef enum { |
mcm | 1:df258d25fd8a | 106 | CONFIGREG1_IIR_MASK = ( 7 << 0 ), /*!< IIR Mask */ |
mcm | 1:df258d25fd8a | 107 | CONFIGREG1_IIR_100 = ( 4 << 0 ), /*!< IIR (100%) a1=1, b1=0 */ |
mcm | 1:df258d25fd8a | 108 | CONFIGREG1_IIR_80 = ( 5 << 0 ), /*!< IIR (80%) a1=0.8, b1=0.2 */ |
mcm | 1:df258d25fd8a | 109 | CONFIGREG1_IIR_67 = ( 6 << 0 ), /*!< IIR (67%) a1=0.666, b1=0.333 */ |
mcm | 1:df258d25fd8a | 110 | CONFIGREG1_IIR_57 = ( 7 << 0 ), /*!< IIR (57%) a1=0.571, b1=0.428 */ |
mcm | 1:df258d25fd8a | 111 | CONFIGREG1_IIR_50 = ( 0 << 0 ), /*!< IIR (50%) a1=0.5, b1=0.5 */ |
mcm | 1:df258d25fd8a | 112 | CONFIGREG1_IIR_25 = ( 1 << 0 ), /*!< IIR (25%) a1=0.25, b1=0.75 */ |
mcm | 1:df258d25fd8a | 113 | CONFIGREG1_IIR_17 = ( 2 << 0 ), /*!< IIR (17%) a1=0.166(6), b1=0.83(3) */ |
mcm | 1:df258d25fd8a | 114 | CONFIGREG1_IIR_13 = ( 3 << 0 ) /*!< IIR (13%) a1=0.125, b1=0.875 */ |
mcm | 1:df258d25fd8a | 115 | } MLX90614_configregister1_iir_t; |
mcm | 1:df258d25fd8a | 116 | |
mcm | 1:df258d25fd8a | 117 | |
mcm | 1:df258d25fd8a | 118 | |
mcm | 1:df258d25fd8a | 119 | |
mcm | 1:df258d25fd8a | 120 | |
mcm | 1:df258d25fd8a | 121 | |
mcm | 1:df258d25fd8a | 122 | |
mcm | 1:df258d25fd8a | 123 | #ifndef MLX90614_VECTOR_STRUCT_H |
mcm | 1:df258d25fd8a | 124 | #define MLX90614_VECTOR_STRUCT_H |
mcm | 1:df258d25fd8a | 125 | typedef struct { |
mcm | 1:df258d25fd8a | 126 | uint16_t RawTA; |
mcm | 1:df258d25fd8a | 127 | uint16_t RawTObj1; |
mcm | 1:df258d25fd8a | 128 | uint16_t RawTObj2; |
mcm | 1:df258d25fd8a | 129 | uint8_t PEC; |
mcm | 1:df258d25fd8a | 130 | |
mcm | 1:df258d25fd8a | 131 | float TA; |
mcm | 1:df258d25fd8a | 132 | float TObj1; |
mcm | 1:df258d25fd8a | 133 | float TObj2; |
mcm | 1:df258d25fd8a | 134 | |
mcm | 1:df258d25fd8a | 135 | uint16_t ID[4]; |
mcm | 1:df258d25fd8a | 136 | float Emissivity; |
mcm | 1:df258d25fd8a | 137 | MLX90614_configregister1_iir_t IIR; |
mcm | 1:df258d25fd8a | 138 | MLX90614_flags_t Flags; |
mcm | 1:df258d25fd8a | 139 | } MLX90614_vector_data_t; |
mcm | 1:df258d25fd8a | 140 | #endif |
mcm | 1:df258d25fd8a | 141 | |
mcm | 1:df258d25fd8a | 142 | |
mcm | 1:df258d25fd8a | 143 | |
mcm | 1:df258d25fd8a | 144 | |
mcm | 1:df258d25fd8a | 145 | /** |
mcm | 1:df258d25fd8a | 146 | * @brief INTERNAL CONSTANTS |
mcm | 1:df258d25fd8a | 147 | */ |
mcm | 1:df258d25fd8a | 148 | #define MLX90614_KELVIN_TO_CELSIUS 273.15 |
mcm | 1:df258d25fd8a | 149 | #define MLX90614_KELVIN_CONVERSION 0.02 |
mcm | 1:df258d25fd8a | 150 | |
mcm | 1:df258d25fd8a | 151 | // MACRO: round function |
mcm | 1:df258d25fd8a | 152 | #define _MYROUND( x ) ({ \ |
mcm | 1:df258d25fd8a | 153 | uint32_t aux_pre; \ |
mcm | 1:df258d25fd8a | 154 | float aux_x; \ |
mcm | 1:df258d25fd8a | 155 | \ |
mcm | 1:df258d25fd8a | 156 | aux_x = (x); \ |
mcm | 1:df258d25fd8a | 157 | aux_pre = (x); \ |
mcm | 1:df258d25fd8a | 158 | aux_x -= aux_pre; \ |
mcm | 1:df258d25fd8a | 159 | aux_x *= 10; \ |
mcm | 1:df258d25fd8a | 160 | \ |
mcm | 1:df258d25fd8a | 161 | if ( aux_x >= 5 ) \ |
mcm | 1:df258d25fd8a | 162 | aux_pre++; \ |
mcm | 1:df258d25fd8a | 163 | \ |
mcm | 1:df258d25fd8a | 164 | aux_pre; \ |
mcm | 1:df258d25fd8a | 165 | }) |
mcm | 1:df258d25fd8a | 166 | |
mcm | 1:df258d25fd8a | 167 | |
mcm | 1:df258d25fd8a | 168 | typedef enum { |
mcm | 1:df258d25fd8a | 169 | MLX90614_SUCCESS = 0, |
mcm | 1:df258d25fd8a | 170 | MLX90614_FAILURE = 1, |
mcm | 1:df258d25fd8a | 171 | |
mcm | 1:df258d25fd8a | 172 | MLX90614_TIMEOUT = 2*65535, |
mcm | 1:df258d25fd8a | 173 | MLX90614_FLAG_ERROR = 0x8000, |
mcm | 1:df258d25fd8a | 174 | |
mcm | 1:df258d25fd8a | 175 | I2C_SUCCESS = 0, /*!< I2C communication was fine */ |
mcm | 1:df258d25fd8a | 176 | I2C_FAILURE = 1 |
mcm | 1:df258d25fd8a | 177 | } MLX90614_status_t; |
mcm | 1:df258d25fd8a | 178 | |
mcm | 1:df258d25fd8a | 179 | |
mcm | 1:df258d25fd8a | 180 | |
mcm | 1:df258d25fd8a | 181 | |
mcm | 1:df258d25fd8a | 182 | |
mcm | 1:df258d25fd8a | 183 | /** Create an MLX90614 object connected to the specified I2C pins. |
mcm | 1:df258d25fd8a | 184 | * |
mcm | 1:df258d25fd8a | 185 | * @param sda I2C data pin |
mcm | 1:df258d25fd8a | 186 | * @param scl I2C clock pin |
mcm | 1:df258d25fd8a | 187 | * @param addr I2C slave address |
mcm | 1:df258d25fd8a | 188 | * @param freq I2C frequency in Hz. |
mcm | 1:df258d25fd8a | 189 | */ |
mcm | 1:df258d25fd8a | 190 | MLX90614 ( PinName sda, PinName scl, uint32_t addr, uint32_t freq ); |
mcm | 1:df258d25fd8a | 191 | |
mcm | 1:df258d25fd8a | 192 | /** Delete MLX90614 object. |
mcm | 1:df258d25fd8a | 193 | */ |
mcm | 1:df258d25fd8a | 194 | ~MLX90614(); |
mcm | 1:df258d25fd8a | 195 | |
mcm | 1:df258d25fd8a | 196 | /** It gets the ID numbers. |
mcm | 1:df258d25fd8a | 197 | */ |
mcm | 1:df258d25fd8a | 198 | MLX90614_status_t MLX90614_GetID_Numbers ( MLX90614_vector_data_t* myID ); |
mcm | 1:df258d25fd8a | 199 | |
mcm | 1:df258d25fd8a | 200 | /** It reads the raw ambient temperature. |
mcm | 1:df258d25fd8a | 201 | */ |
mcm | 1:df258d25fd8a | 202 | MLX90614_status_t MLX90614_ReadRawTA ( MLX90614_vector_data_t* myRawTA ); |
mcm | 1:df258d25fd8a | 203 | |
mcm | 1:df258d25fd8a | 204 | /** It reads the ambient temperature in Celsius degrees. |
mcm | 1:df258d25fd8a | 205 | */ |
mcm | 2:1d6817048eb1 | 206 | MLX90614_status_t MLX90614_ReadTA ( MLX90614_vector_data_t* myTA ); |
mcm | 1:df258d25fd8a | 207 | |
mcm | 1:df258d25fd8a | 208 | /** It reads the raw object 1 temperature. |
mcm | 1:df258d25fd8a | 209 | */ |
mcm | 1:df258d25fd8a | 210 | MLX90614_status_t MLX90614_ReadRawTObj1 ( MLX90614_vector_data_t* myRawTObj1 ); |
mcm | 1:df258d25fd8a | 211 | |
mcm | 1:df258d25fd8a | 212 | /** It reads the object 1 temperature. |
mcm | 1:df258d25fd8a | 213 | */ |
mcm | 1:df258d25fd8a | 214 | MLX90614_status_t MLX90614_ReadTObj1 ( MLX90614_vector_data_t* myObj1 ); |
mcm | 1:df258d25fd8a | 215 | |
mcm | 1:df258d25fd8a | 216 | /** It reads the raw object 2 temperature. |
mcm | 1:df258d25fd8a | 217 | */ |
mcm | 1:df258d25fd8a | 218 | MLX90614_status_t MLX90614_ReadRawTObj2 ( MLX90614_vector_data_t* myRawTObj2 ); |
mcm | 1:df258d25fd8a | 219 | |
mcm | 1:df258d25fd8a | 220 | /** It reads the object 2 temperature. |
mcm | 1:df258d25fd8a | 221 | */ |
mcm | 1:df258d25fd8a | 222 | MLX90614_status_t MLX90614_ReadTObj2 ( MLX90614_vector_data_t* myObj2 ); |
mcm | 1:df258d25fd8a | 223 | |
mcm | 1:df258d25fd8a | 224 | /** It gets the Emissivity correction coefficient. |
mcm | 1:df258d25fd8a | 225 | */ |
mcm | 1:df258d25fd8a | 226 | MLX90614_status_t MLX90614_GetEmissivity ( MLX90614_vector_data_t* myEmissivity ); |
mcm | 1:df258d25fd8a | 227 | |
mcm | 1:df258d25fd8a | 228 | /** It sets the Emissivity correction coefficient. |
mcm | 1:df258d25fd8a | 229 | */ |
mcm | 1:df258d25fd8a | 230 | MLX90614_status_t MLX90614_SetEmissivity ( MLX90614_vector_data_t myEmissivity ); |
mcm | 1:df258d25fd8a | 231 | |
mcm | 1:df258d25fd8a | 232 | /** It gets the IIR. |
mcm | 1:df258d25fd8a | 233 | */ |
mcm | 1:df258d25fd8a | 234 | MLX90614_status_t MLX90614_GetIIR ( MLX90614_vector_data_t* myIIR ); |
mcm | 1:df258d25fd8a | 235 | |
mcm | 1:df258d25fd8a | 236 | /** It sets the IIR. |
mcm | 1:df258d25fd8a | 237 | */ |
mcm | 1:df258d25fd8a | 238 | MLX90614_status_t MLX90614_SetIIR ( MLX90614_configregister1_iir_t myIIR ); |
mcm | 1:df258d25fd8a | 239 | |
mcm | 1:df258d25fd8a | 240 | /** It gets the FLAGS. |
mcm | 1:df258d25fd8a | 241 | */ |
mcm | 1:df258d25fd8a | 242 | MLX90614_status_t MLX90614_GetFLAGS ( MLX90614_vector_data_t* myFlags ); |
mcm | 1:df258d25fd8a | 243 | |
mcm | 1:df258d25fd8a | 244 | |
mcm | 1:df258d25fd8a | 245 | |
mcm | 1:df258d25fd8a | 246 | |
mcm | 1:df258d25fd8a | 247 | private: |
mcm | 1:df258d25fd8a | 248 | I2C _i2c; |
mcm | 1:df258d25fd8a | 249 | uint32_t _MLX90614_Addr; |
mcm | 1:df258d25fd8a | 250 | }; |
mcm | 1:df258d25fd8a | 251 | |
mcm | 1:df258d25fd8a | 252 | #endif |