Malexis 90640 sensor

Dependencies:   mbed

Committer:
withboobs
Date:
Thu Apr 19 18:23:43 2018 +0000
Revision:
1:3f763d28c1be
Parent:
0:99e98f131071
Child:
2:44869d695501
nothing to say;

Who changed what in which revision?

UserRevisionLine numberNew 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 1:3f763d28c1be 5 #define FRAMES_NUM 15
withboobs 0:99e98f131071 6 #define TA_SHIFT 8
withboobs 0:99e98f131071 7
withboobs 1:3f763d28c1be 8 Timer timer;
withboobs 1:3f763d28c1be 9 Serial pc(USBTX, USBRX); // tx, rx, Virtual serial port over USB
withboobs 1:3f763d28c1be 10 void PrintEEPROM(uint16_t *p);
withboobs 1:3f763d28c1be 11 void PrintRawData(uint16_t *p);
withboobs 1:3f763d28c1be 12 void PrintToF(float *p);
withboobs 1:3f763d28c1be 13 void PrintToU(float *p);
withboobs 0:99e98f131071 14
withboobs 1:3f763d28c1be 15 DigitalOut led_green(LED2);
withboobs 0:99e98f131071 16
withboobs 0:99e98f131071 17 int main()
withboobs 0:99e98f131071 18 {
withboobs 0:99e98f131071 19 MLX90640_I2CFreqSet(1000);
withboobs 1:3f763d28c1be 20 pc.baud(230400);
withboobs 1:3f763d28c1be 21 paramsMLX90640 mlx90640;
withboobs 1:3f763d28c1be 22 uint8_t slaveAddress = 0x33;
withboobs 0:99e98f131071 23 uint16_t *pEE;
withboobs 0:99e98f131071 24 uint16_t *pFrame;
withboobs 0:99e98f131071 25 static uint16_t eeMLX90640[832];
withboobs 0:99e98f131071 26 float mlx90640Vdd;
withboobs 0:99e98f131071 27 float mlx90640Ta;
withboobs 0:99e98f131071 28 static uint16_t mlx90640Frame[834];
withboobs 0:99e98f131071 29 static float mlx90640To[768];
withboobs 0:99e98f131071 30 float emissivity = 1;
withboobs 0:99e98f131071 31 int status = 0;
withboobs 0:99e98f131071 32 int frameCnt = 0;
withboobs 0:99e98f131071 33 float eTa; //Ta for emissivity compensation
withboobs 1:3f763d28c1be 34
withboobs 0:99e98f131071 35 pEE = eeMLX90640;
withboobs 0:99e98f131071 36 pFrame = mlx90640Frame;
withboobs 1:3f763d28c1be 37 status = MLX90640_SetRefreshRate(slaveAddress,1);
withboobs 1:3f763d28c1be 38 //status = MLX90640_SetResolution(slaveAddress[i],0x03);
withboobs 1:3f763d28c1be 39 //status = MLX90640_SetInterleavedMode(slaveAddress[i]);
withboobs 1:3f763d28c1be 40 status = MLX90640_SetChessMode(slaveAddress);
withboobs 1:3f763d28c1be 41 //printf("Reading EEPROM for MLX90640 device %d...\r\n",i+1);
withboobs 1:3f763d28c1be 42 MLX90640_I2CFreqSet(400);
withboobs 1:3f763d28c1be 43 status = MLX90640_DumpEE(slaveAddress, pEE);
withboobs 1:3f763d28c1be 44 MLX90640_I2CFreqSet(1000);
withboobs 1:3f763d28c1be 45 //printf("Extracting parameters for MLX90640 device %d...\r\n",i+1);
withboobs 1:3f763d28c1be 46 status = MLX90640_ExtractParameters(pEE, &mlx90640 );
withboobs 0:99e98f131071 47
withboobs 1:3f763d28c1be 48 while (1)
withboobs 0:99e98f131071 49 {
withboobs 1:3f763d28c1be 50 led_green = 1; // turn on LED until initialization is complete
withboobs 1:3f763d28c1be 51 status = MLX90640_GetFrameData(slaveAddress, pFrame);
withboobs 1:3f763d28c1be 52 led_green = 0; // turn on LED until initialization is complete
withboobs 1:3f763d28c1be 53 eTa = MLX90640_GetTa(pFrame, &mlx90640) - TA_SHIFT;
withboobs 1:3f763d28c1be 54 MLX90640_CalculateTo(pFrame, &mlx90640, emissivity, eTa, mlx90640To);
withboobs 1:3f763d28c1be 55 PrintToU(mlx90640To);
withboobs 0:99e98f131071 56 }
withboobs 0:99e98f131071 57
withboobs 0:99e98f131071 58 }
withboobs 1:3f763d28c1be 59
withboobs 1:3f763d28c1be 60 void PrintToU(float *p)
withboobs 1:3f763d28c1be 61 {
withboobs 1:3f763d28c1be 62 uint16_t d;
withboobs 1:3f763d28c1be 63 pc.printf("S",d);
withboobs 1:3f763d28c1be 64 for(int i=0; i<768; i++)
withboobs 1:3f763d28c1be 65 {
withboobs 1:3f763d28c1be 66 d = 10 * *p++;
withboobs 1:3f763d28c1be 67 pc.printf("%04x",d);
withboobs 1:3f763d28c1be 68 }
withboobs 1:3f763d28c1be 69 pc.printf("E\n");
withboobs 1:3f763d28c1be 70
withboobs 1:3f763d28c1be 71 }
withboobs 1:3f763d28c1be 72
withboobs 1:3f763d28c1be 73 void PrintToF(float *p)
withboobs 1:3f763d28c1be 74 {
withboobs 1:3f763d28c1be 75 for(int i=0; i<768; i++)
withboobs 1:3f763d28c1be 76 {
withboobs 1:3f763d28c1be 77 pc.printf("%0.3f,",*p++);
withboobs 1:3f763d28c1be 78 }
withboobs 1:3f763d28c1be 79 pc.printf("\n");
withboobs 1:3f763d28c1be 80
withboobs 1:3f763d28c1be 81 }
withboobs 1:3f763d28c1be 82
withboobs 1:3f763d28c1be 83 void PrintRawData(uint16_t *p)
withboobs 1:3f763d28c1be 84 {
withboobs 1:3f763d28c1be 85 for(int i=0; i<832; i++) {
withboobs 1:3f763d28c1be 86 pc.printf("%04X,",*p++);
withboobs 1:3f763d28c1be 87 }
withboobs 1:3f763d28c1be 88 pc.printf("\r\n");
withboobs 1:3f763d28c1be 89 }