Malexis 90640 sensor
Dependencies: mbed
main.cpp@0:99e98f131071, 2018-03-27 (annotated)
- Committer:
- withboobs
- Date:
- Tue Mar 27 13:34:11 2018 +0000
- Revision:
- 0:99e98f131071
- Child:
- 1:3f763d28c1be
nothing to say
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
withboobs | 0:99e98f131071 | 1 | #include "mbed.h" |
withboobs | 0:99e98f131071 | 2 | #include <MLX90640_I2C_Driver.h> |
withboobs | 0:99e98f131071 | 3 | #include <MLX90640_API.h> |
withboobs | 0:99e98f131071 | 4 | |
withboobs | 0:99e98f131071 | 5 | #define DEVICE_NUM 1 |
withboobs | 0:99e98f131071 | 6 | #define FRAMES_NUM 4 |
withboobs | 0:99e98f131071 | 7 | #define TA_SHIFT 8 |
withboobs | 0:99e98f131071 | 8 | |
withboobs | 0:99e98f131071 | 9 | #define BAUDRATE 115200 |
withboobs | 0:99e98f131071 | 10 | |
withboobs | 0:99e98f131071 | 11 | Serial pc(SERIAL_TX, SERIAL_RX); |
withboobs | 0:99e98f131071 | 12 | |
withboobs | 0:99e98f131071 | 13 | int main() |
withboobs | 0:99e98f131071 | 14 | { |
withboobs | 0:99e98f131071 | 15 | pc.baud(BAUDRATE); |
withboobs | 0:99e98f131071 | 16 | |
withboobs | 0:99e98f131071 | 17 | MLX90640_I2CFreqSet(1000); |
withboobs | 0:99e98f131071 | 18 | paramsMLX90640 mlx90640[2]; |
withboobs | 0:99e98f131071 | 19 | uint8_t slaveAddress[2] = {0x33,0x34}; |
withboobs | 0:99e98f131071 | 20 | uint16_t *pEE; |
withboobs | 0:99e98f131071 | 21 | uint16_t *pFrame; |
withboobs | 0:99e98f131071 | 22 | paramsMLX90640 *pParam; |
withboobs | 0:99e98f131071 | 23 | static uint16_t eeMLX90640[832]; |
withboobs | 0:99e98f131071 | 24 | float mlx90640Vdd; |
withboobs | 0:99e98f131071 | 25 | float mlx90640Ta; |
withboobs | 0:99e98f131071 | 26 | static uint16_t mlx90640Frame[834]; |
withboobs | 0:99e98f131071 | 27 | static float mlx90640To[768]; |
withboobs | 0:99e98f131071 | 28 | float emissivity = 1; |
withboobs | 0:99e98f131071 | 29 | int status = 0; |
withboobs | 0:99e98f131071 | 30 | int frameCnt = 0; |
withboobs | 0:99e98f131071 | 31 | float eTa; //Ta for emissivity compensation |
withboobs | 0:99e98f131071 | 32 | |
withboobs | 0:99e98f131071 | 33 | pParam = mlx90640; |
withboobs | 0:99e98f131071 | 34 | pEE = eeMLX90640; |
withboobs | 0:99e98f131071 | 35 | pFrame = mlx90640Frame; |
withboobs | 0:99e98f131071 | 36 | |
withboobs | 0:99e98f131071 | 37 | for(int i = 0; i < DEVICE_NUM; i++) |
withboobs | 0:99e98f131071 | 38 | { |
withboobs | 0:99e98f131071 | 39 | //status = MLX90640_SetRefreshRate(slaveAddress[i],2); |
withboobs | 0:99e98f131071 | 40 | //status = MLX90640_SetResolution(slaveAddress[i],0x03); |
withboobs | 0:99e98f131071 | 41 | //status = MLX90640_SetInterleavedMode(slaveAddress[i]); |
withboobs | 0:99e98f131071 | 42 | //status = MLX90640_SetChessMode(slaveAddress[i]); |
withboobs | 0:99e98f131071 | 43 | //printf("Reading EEPROM for MLX90640 device %d...\r",i+1); |
withboobs | 0:99e98f131071 | 44 | MLX90640_I2CFreqSet(400); |
withboobs | 0:99e98f131071 | 45 | status = MLX90640_DumpEE(slaveAddress[i], pEE); |
withboobs | 0:99e98f131071 | 46 | MLX90640_I2CFreqSet(400); |
withboobs | 0:99e98f131071 | 47 | // printf("Extracting parameters for MLX90640 device %d...\r",i+1); |
withboobs | 0:99e98f131071 | 48 | status = MLX90640_ExtractParameters(pEE, (pParam+i)); |
withboobs | 0:99e98f131071 | 49 | } |
withboobs | 0:99e98f131071 | 50 | |
withboobs | 0:99e98f131071 | 51 | while (frameCnt < FRAMES_NUM) |
withboobs | 0:99e98f131071 | 52 | { |
withboobs | 0:99e98f131071 | 53 | for(int i = 0; i < DEVICE_NUM; i++) |
withboobs | 0:99e98f131071 | 54 | { |
withboobs | 0:99e98f131071 | 55 | // printf("Reading Frame data for MLX90640 device %d... \n",i+1); |
withboobs | 0:99e98f131071 | 56 | status = MLX90640_GetFrameData(slaveAddress[i], pFrame); |
withboobs | 0:99e98f131071 | 57 | eTa = MLX90640_GetTa(pFrame,(pParam+i)) - TA_SHIFT; |
withboobs | 0:99e98f131071 | 58 | MLX90640_CalculateTo(pFrame, (pParam+i), emissivity, eTa, mlx90640To); |
withboobs | 0:99e98f131071 | 59 | MLX90640_GetImage(pFrame, (pParam+i), mlx90640To); |
withboobs | 0:99e98f131071 | 60 | |
withboobs | 0:99e98f131071 | 61 | for(int i = 0; i < 24; i++) |
withboobs | 0:99e98f131071 | 62 | { |
withboobs | 0:99e98f131071 | 63 | pc.printf("S%2d:",i); |
withboobs | 0:99e98f131071 | 64 | for(int j = 0; j < 32; j ++) |
withboobs | 0:99e98f131071 | 65 | { |
withboobs | 0:99e98f131071 | 66 | int16_t p = 32 * i +j; |
withboobs | 0:99e98f131071 | 67 | pc.printf("%06.1f;",mlx90640To[p]); |
withboobs | 0:99e98f131071 | 68 | } |
withboobs | 0:99e98f131071 | 69 | pc.printf("\n"); |
withboobs | 0:99e98f131071 | 70 | } |
withboobs | 0:99e98f131071 | 71 | |
withboobs | 0:99e98f131071 | 72 | //printf("Calculated To for MLX90640 device %d is ready \r",i+1); |
withboobs | 0:99e98f131071 | 73 | } |
withboobs | 0:99e98f131071 | 74 | |
withboobs | 0:99e98f131071 | 75 | frameCnt++; |
withboobs | 0:99e98f131071 | 76 | } |
withboobs | 0:99e98f131071 | 77 | |
withboobs | 0:99e98f131071 | 78 | } |