Malexis 90640 sensor

Dependencies:   mbed

Committer:
withboobs
Date:
Thu Apr 19 19:16:44 2018 +0000
Revision:
2:44869d695501
Parent:
1:3f763d28c1be
Child:
3:d2e64ef64905
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 2:44869d695501 8 #define FIRMWARE "eye_r_eye-mlx90640_32x24-v_1_0"
withboobs 2:44869d695501 9
withboobs 1:3f763d28c1be 10 Serial pc(USBTX, USBRX); // tx, rx, Virtual serial port over USB
withboobs 1:3f763d28c1be 11 void PrintEEPROM(uint16_t *p);
withboobs 1:3f763d28c1be 12 void PrintRawData(uint16_t *p);
withboobs 1:3f763d28c1be 13 void PrintToF(float *p);
withboobs 1:3f763d28c1be 14 void PrintToU(float *p);
withboobs 0:99e98f131071 15
withboobs 1:3f763d28c1be 16 DigitalOut led_green(LED2);
withboobs 0:99e98f131071 17
withboobs 2:44869d695501 18 char buffer[3076]={'S'};
withboobs 2:44869d695501 19
withboobs 0:99e98f131071 20 int main()
withboobs 0:99e98f131071 21 {
withboobs 2:44869d695501 22 uint8_t printme=0;
withboobs 0:99e98f131071 23 MLX90640_I2CFreqSet(1000);
withboobs 1:3f763d28c1be 24 pc.baud(230400);
withboobs 1:3f763d28c1be 25 paramsMLX90640 mlx90640;
withboobs 1:3f763d28c1be 26 uint8_t slaveAddress = 0x33;
withboobs 0:99e98f131071 27 uint16_t *pEE;
withboobs 0:99e98f131071 28 uint16_t *pFrame;
withboobs 0:99e98f131071 29 static uint16_t eeMLX90640[832];
withboobs 0:99e98f131071 30 static uint16_t mlx90640Frame[834];
withboobs 0:99e98f131071 31 static float mlx90640To[768];
withboobs 0:99e98f131071 32 float emissivity = 1;
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 2:44869d695501 37 MLX90640_SetRefreshRate(slaveAddress,2);
withboobs 1:3f763d28c1be 38 //status = MLX90640_SetResolution(slaveAddress[i],0x03);
withboobs 1:3f763d28c1be 39 //status = MLX90640_SetInterleavedMode(slaveAddress[i]);
withboobs 2:44869d695501 40 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 2:44869d695501 43 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 2:44869d695501 46 MLX90640_ExtractParameters(pEE, &mlx90640 );
withboobs 0:99e98f131071 47
withboobs 1:3f763d28c1be 48 while (1)
withboobs 0:99e98f131071 49 {
withboobs 2:44869d695501 50 if (pc.readable())
withboobs 2:44869d695501 51 {
withboobs 2:44869d695501 52 char c = pc.getc();
withboobs 2:44869d695501 53 if (printme)
withboobs 2:44869d695501 54 {
withboobs 2:44869d695501 55 switch (c)
withboobs 2:44869d695501 56 {
withboobs 2:44869d695501 57 case 'p':
withboobs 2:44869d695501 58 printme=1;
withboobs 2:44869d695501 59 break;
withboobs 2:44869d695501 60
withboobs 2:44869d695501 61 case 'q':
withboobs 2:44869d695501 62 printme=0;
withboobs 2:44869d695501 63 break;
withboobs 2:44869d695501 64 }
withboobs 2:44869d695501 65 continue;
withboobs 2:44869d695501 66 }
withboobs 2:44869d695501 67
withboobs 2:44869d695501 68 switch (c)
withboobs 2:44869d695501 69 {
withboobs 2:44869d695501 70 case '1':
withboobs 2:44869d695501 71 MLX90640_SetRefreshRate(slaveAddress,1);
withboobs 2:44869d695501 72 break;
withboobs 2:44869d695501 73
withboobs 2:44869d695501 74 case '2':
withboobs 2:44869d695501 75 MLX90640_SetRefreshRate(slaveAddress,2);
withboobs 2:44869d695501 76 break;
withboobs 2:44869d695501 77
withboobs 2:44869d695501 78 case '4':
withboobs 2:44869d695501 79 MLX90640_SetRefreshRate(slaveAddress,4);
withboobs 2:44869d695501 80 break;
withboobs 2:44869d695501 81
withboobs 2:44869d695501 82 case '?':
withboobs 2:44869d695501 83 pc.printf(FIRMWARE "\n");
withboobs 2:44869d695501 84 break;
withboobs 2:44869d695501 85
withboobs 2:44869d695501 86 case 'p':
withboobs 2:44869d695501 87 printme=1;
withboobs 2:44869d695501 88 break;
withboobs 2:44869d695501 89
withboobs 2:44869d695501 90 case 'q':
withboobs 2:44869d695501 91 printme=0;
withboobs 2:44869d695501 92 break;
withboobs 2:44869d695501 93 } // switch
withboobs 2:44869d695501 94 }
withboobs 2:44869d695501 95
withboobs 1:3f763d28c1be 96 led_green = 1; // turn on LED until initialization is complete
withboobs 2:44869d695501 97 MLX90640_GetFrameData(slaveAddress, pFrame);
withboobs 1:3f763d28c1be 98 led_green = 0; // turn on LED until initialization is complete
withboobs 1:3f763d28c1be 99 eTa = MLX90640_GetTa(pFrame, &mlx90640) - TA_SHIFT;
withboobs 1:3f763d28c1be 100 MLX90640_CalculateTo(pFrame, &mlx90640, emissivity, eTa, mlx90640To);
withboobs 2:44869d695501 101 if (printme)
withboobs 2:44869d695501 102 {
withboobs 2:44869d695501 103 PrintToU(mlx90640To);
withboobs 2:44869d695501 104 }
withboobs 0:99e98f131071 105 }
withboobs 0:99e98f131071 106
withboobs 0:99e98f131071 107 }
withboobs 1:3f763d28c1be 108
withboobs 1:3f763d28c1be 109 void PrintToU(float *p)
withboobs 1:3f763d28c1be 110 {
withboobs 2:44869d695501 111 uint16_t idx=1,i;
withboobs 2:44869d695501 112 uint16_t d;
withboobs 2:44869d695501 113 for(i=0; i<768; i++)
withboobs 1:3f763d28c1be 114 {
withboobs 1:3f763d28c1be 115 d = 10 * *p++;
withboobs 2:44869d695501 116 sprintf(buffer+idx,"%04x",d);
withboobs 2:44869d695501 117 idx+=4;
withboobs 1:3f763d28c1be 118 }
withboobs 2:44869d695501 119 buffer[idx++] = 'E';
withboobs 2:44869d695501 120 buffer[idx++] = '\n';
withboobs 2:44869d695501 121 buffer[idx++] = 0;
withboobs 2:44869d695501 122 pc.printf(buffer);
withboobs 1:3f763d28c1be 123 }
withboobs 1:3f763d28c1be 124
withboobs 1:3f763d28c1be 125 void PrintToF(float *p)
withboobs 1:3f763d28c1be 126 {
withboobs 1:3f763d28c1be 127 for(int i=0; i<768; i++)
withboobs 1:3f763d28c1be 128 {
withboobs 1:3f763d28c1be 129 pc.printf("%0.3f,",*p++);
withboobs 1:3f763d28c1be 130 }
withboobs 1:3f763d28c1be 131 pc.printf("\n");
withboobs 1:3f763d28c1be 132
withboobs 1:3f763d28c1be 133 }
withboobs 1:3f763d28c1be 134
withboobs 1:3f763d28c1be 135 void PrintRawData(uint16_t *p)
withboobs 1:3f763d28c1be 136 {
withboobs 1:3f763d28c1be 137 for(int i=0; i<832; i++) {
withboobs 1:3f763d28c1be 138 pc.printf("%04X,",*p++);
withboobs 1:3f763d28c1be 139 }
withboobs 1:3f763d28c1be 140 pc.printf("\r\n");
withboobs 1:3f763d28c1be 141 }