
SCH MME sensor test
Dependencies: mbed Adafruit_GFX
Revision 0:28c89a4b6b69, committed 2019-11-06
- Comitter:
- shinshingo
- Date:
- Wed Nov 06 09:05:08 2019 +0000
- Child:
- 1:bbf8b08b8a20
- Commit message:
- SCH MME L432KC Mbed Sensor Test
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Adafruit_GFX.lib Wed Nov 06 09:05:08 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/nkhorman/code/Adafruit_GFX/#7fb1d4d3525d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Nov 06 09:05:08 2019 +0000 @@ -0,0 +1,51 @@ +#include "mbed.h" +#include "Adafruit_SSD1306.h" +#include "mlx90615.h" + +DigitalOut myled_R(LED1); + +I2C i2c_sensor(I2C_SDA,I2C_SCL); +I2C i2c_oled(D12, A6); + +Adafruit_SSD1306_I2c myOled(i2c_oled,NC,0x78,64,128); +MLX90615 myMlx(&i2c_sensor); + +Serial pc(USBTX, USBRX, 9600); +Serial HC06(D1, D0, 9600); + +int main() +{ + float temp = 0.0; + float amb_temp = 0.0; + int16_t ir_data = 0; + + myOled.begin(); + myOled.printf("%ux%u \nHellow World\r\n", myOled.width(), myOled.height()); + myOled.display(); + + myOled.clearDisplay(); + + pc.printf("===============Hello world===============\n\r"); + + while(1) + { + myled_R = !myled_R; + + temp = 0; + amb_temp = 0; + ir_data = 0; + + if (myMlx.getTemp(&temp)& myMlx.getTempAmbient(&amb_temp) & myMlx.getRawIR(&ir_data)) + { + myOled.clearDisplay(); + myOled.setTextCursor(0,0); + pc.printf("%5.2f, %5.2f, %d\n",temp, amb_temp, ir_data); + HC06.printf("%5.2f, %5.2f, %d\r\n",temp, amb_temp, ir_data); + myOled.printf("%5.2f, %5.2f, %d\r\n",temp, amb_temp, ir_data); + myOled.display(); + } + wait(1.0); + + + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Nov 06 09:05:08 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mlx90615.cpp Wed Nov 06 09:05:08 2019 +0000 @@ -0,0 +1,81 @@ + +#include "mlx90615.h" + + + + +MLX90615::MLX90615(I2C* i2c,int addr){ + + this->i2caddress = addr; + this->i2c = i2c; + +} + + +bool MLX90615::getTemp(float* temp_val){ + + char ch1, ch2; + char cmd[3]; + + cmd[0] = 0x27; + cmd[1] = 0; + cmd[2] = 0; + + i2c->stop(); + wait_us(5); + ch1 = i2c->write(0xb6, cmd, 1, true); + if (ch1 != 0) {return false;} + ch2 = i2c->read(0xb7, cmd, 3); + if (ch2 != 0) {return false;} + wait_us(5); + + *temp_val = ((((cmd[1]&0x007f)<<8)+cmd[0])*0.02)-273.15; + return true; + +} + +bool MLX90615::getTempAmbient(float* temp_val){ + + char ch1, ch2; + char cmd[3]; + + cmd[0] = 0x26; + cmd[1] = 0; + cmd[2] = 0; + + i2c->stop(); + wait_us(5); + ch1 = i2c->write(0xb6, cmd, 1, true); + if (ch1 != 0) {return false;} + ch2 = i2c->read(0xb7, cmd, 3); + if (ch2 != 0) {return false;} + wait_us(5); + + *temp_val = ((((cmd[1]&0x007f)<<8)+cmd[0])*0.02)-273.15; + return true; + +} + +bool MLX90615::getRawIR(int16_t* ir_val){ + + char ch1, ch2; + char cmd[3]; + uint16_t temp; + + cmd[0] = 0x25; + cmd[1] = 0; + cmd[2] = 0; + + i2c->stop(); + wait_us(5); + ch1 = i2c->write(0xb6, cmd, 1, true); + if (ch1 != 0) {return false;} + ch2 = i2c->read(0xb7, cmd, 3); + if (ch2 != 0) {return false;} + wait_us(5); + temp = (uint16_t)((cmd[1]<<8)|cmd[0]); + if(temp & 0x8000) *ir_val = ~((int16_t)(temp & 0x7fff))+1; + else *ir_val = (int16_t)temp; + return true; + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mlx90615.h Wed Nov 06 09:05:08 2019 +0000 @@ -0,0 +1,61 @@ +#include "mbed.h" + +//Melexis Infrared Thermometer MLX90614 Library + +//***************************************************************** +// Build : 2011-06-08 Hikaru Sugiura +// Only read thermo data. +// +// This program is based on Mr.Mitesh Patel's "mlx90614". +// http://mbed.org/users/mitesh2patel/programs/mlx90614/lqnetj +// +// This program does not check CRC. +// If you want to check CRC, please do it your self :) +//****************************************************************// + +/**An Interface for MLX90614 +* +* @code +* //Print temperature data +* #include "mbed.h" +* #include "mlx90614.h" +* +* I2C i2c(p28,p27); //sda,scl +* MLX90614 thermometer(&i2c); +* float temp; +* +* void main(void){ +* if(thermometer.getTemp(&temp)){ +* printf("Temperature : %f \r\n",temp); +* } +* wait(0.5); +* +* } +* @endcode +*/ + + +class MLX90615{ + + public: + /** Create MLX90614 interface, initialize with selected I2C port and address. + * + * @param i2c I2C device pointer + * @param addr Device address(default=0xB4) + */ + MLX90615(I2C* i2c,int addr=0xB6); + + /** Get Temperature data from MLX90614. + * + * @param temp_val return valiable pointer + * @return 0 on success (ack), or non-0 on failure (nack) + */ + bool getTemp(float* temp_val); + bool getTempAmbient(float* temp_val); + bool getRawIR(int16_t* ir_val); + + private: + I2C* i2c; + int i2caddress; + +}; \ No newline at end of file