Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 2:5e957dcc94bc
- Parent:
- 1:0624feb5a279
- Child:
- 3:3023306be214
diff -r 0624feb5a279 -r 5e957dcc94bc main.cpp
--- a/main.cpp Tue Feb 11 22:51:15 2020 +0000
+++ b/main.cpp Sun Mar 08 04:08:55 2020 +0000
@@ -1,4 +1,6 @@
#include "mbed.h"
+//#include "Mlx90615.h"
+
/* for the button press device should start reading, then it should stop the loop for button press */
@@ -10,53 +12,204 @@
I2C i2c(PB_11,PB_10); //sda,scl
+//SDFileSystem sd(PA_7, PA_6, PA_5, PA_4, "sd"); //// mosi, miso, sclk, cs, the pinout on the mbed Cool Components workshop board stm32F4
+
+//////////////MLX90615////////////////////////////////////////////////////
+
+const int dev_add_W = 0xB6 ; // address with write(0) bit at last////Address must be bit shifted left already shifted,
+const int reg_To_address = 0x27 ;//address of temperature of the object pointed
+const int reg_Ta_address = 0x26 ;//address of temperature of the object pointed
+//const int reg_emis_address = 0x13 ;//address of the emissivity register
+//const int emis_human = 16384 ;/// emis_val=0.98*16384+.49;
+/*
+
+uint8_t crc8(uint8_t *addr, uint8_t len)
+{
+ uint8_t crc = 0;
+ while (len--) {
+ uint8_t inbyte = *addr++;
+ int i;
+ for (i = 8; i; i--)
+ {
+ uint8_t carry = (crc ^ inbyte) & 0x80;
+ crc <<= 1;
+ if (carry)
+ crc ^= 0x7;
+ inbyte <<= 1;
+ }
+ }
+ return crc;
+} */
-const int dev_add_W = 0xB6 ; // address with write(0) bit at last////Address must be bit shifted left,
-const int reg_To_address = 0x27 ;//temperature of the object pointed
+class Mlx90615 {
+public:
+ /* Mlx90615(): { // _pin(pin) means pass pin to the DigitalOut constructor
+ // default the output to 0
+ }*/
+
+ float readTemp(int regAddress)
+ {
+ char cmd[2];
+ char reg[1];
+ int ack=1;
+ reg[0] = regAddress;
+
+ /// write to the address of the device
+ i2c.write(dev_add_W);
+ i2c.read(ack);
+ // write to the reg address
+ i2c.write(reg_To_address);
+ i2c.read(ack);
+
+ // write (int address, const char *data, int length, bool repeated=false)
+ i2c.write(dev_add_W,reg,1,true ); // write with repeated start
+ i2c.read(ack);
+
+ // read (int address, char *data, int length, bool repeated=false)
+ i2c.read(dev_add_W, cmd,2,false);
+ int temp = (cmd[1]<<8)|cmd[0]; // raw temp value
+ float tempC = (0.02*temp) -273.15; // temp in Celcius
+ float tempF= (tempC*9/5) +31;
+
+ return tempF;
+
+
+ }
+
+
+//private:;
+
+};
+
+
+/*float mlx90615_readTemp(int regAddress)
+{
+ char cmd[2];
+ char reg[1];
+ int ack=1;
+ reg[0] = regAddress;
+
+ /// write to the address of the device
+ i2c.write(dev_add_W);
+ i2c.read(ack);
+ // write to the reg address
+ i2c.write(reg_To_address);
+ i2c.read(ack);
+
+ // write (int address, const char *data, int length, bool repeated=false)
+ i2c.write(dev_add_W,reg,1,true ); // write with repeated start
+ i2c.read(ack);
+
+ // read (int address, char *data, int length, bool repeated=false)
+ i2c.read(dev_add_W, cmd,2,false);
+ int temp = (cmd[1]<<8)|cmd[0]; // raw temp value
+ float tempC = (0.02*temp) -273.15; // temp in Celcius
+ float tempF= temp;//(tempC*9/5) +31;
+
+ return tempF;
+
+
+}*/
+/*
+
+void mlx90615_emisWrite(int emis_val)
+{
+
+
+ //uint8_t data_low = 0;
+// uint8_t data_high = 0;
+// int ack=1;
+//
+//
+//
+// data_low=(uint8_t)(emis_val & 0x00ff);;
+// data_high= (uint8_t)((emis_val & 0xff00) >> 8);
+//
+// uint8_t *emisData=0x00;
+// uint8_t emisData_A[4];// arrary to keep it in pointer
+// emisData_A[0]=dev_add_W;
+// emisData_A[1]=reg_emis_address;
+// emisData_A[2]=data_low;
+// emisData_A[3]=data_high;
+// emisData=emisData_A;
+
+
+ char cmd[4] = { 0 };
+ uint8_t crcbuf[4] = { 0 };
+
+
+
+ crcbuf[0] = dev_add_W; //write Address
+ crcbuf[1] = cmd[0] = reg_emis_address;
+ crcbuf[2] = cmd[1] = (uint8_t)(emis_val & 0xFF);
+ crcbuf[3] = cmd[2] = (uint8_t)((emis_val) >> 8);
+ cmd[3] = crc8(crcbuf, 4);
+
+ i2c.write(dev_add_W, cmd, 4, true);
+ wait(0.1);
+
+
+
+
+
+
+ // /// write to the address of the device
+// i2c.write(dev_add_W);
+// i2c.read(ack);
+// // write to the reg address
+// i2c.write(reg_To_address);
+// i2c.read(ack);
+//
+// //write the low 8 bits
+// i2c.write(data_low);
+// i2c.read(ack);
+//
+// //write to the high bits
+// i2c.write(data_high);
+// i2c.read(ack);
+//
+// //write pec
+// i2c.write(crc8(emisData,4));
+// i2c.read(ack);
+
+}*/
+
+//////////////MLX90615///////////////////////////////////////////////////////////////////////
void read_ecg(bool work)
{
float meas_r;
float meas_v;
- int temp;
- float tempC;
- int ack=1;
+ float bodyTempF;
+ float envTempF;
+ Mlx90615 mlx;
+
+
if(work){
meas_r = analog_value.read(); // Read the analog input value (value from 0.0 to 1.0 = full ADC conversion range)
meas_v = meas_r * 3300; // Converts value in the 0V-3.3V range
- char cmd[2];
- char reg[1];
- reg[0] = 0x27;
- // i2c.write(dev_add_W, 1, true);
- // i2c.read(ack);
+
+ bodyTempF = mlx.readTemp(reg_To_address);
+ envTempF = mlx.readTemp(reg_Ta_address);
- i2c.write(dev_add_W);
- i2c.read(ack);
- i2c.write(reg_To_address);
- i2c.read(ack);
-
- // write (int address, const char *data, int length, bool repeated=false)
- i2c.write(dev_add_W,reg,1,true );
- i2c.read(ack);
- // read (int address, char *data, int length, bool repeated=false)
- i2c.read(dev_add_W, cmd,2,false);
- temp = (cmd[1]<<8)|cmd[0];
- tempC = (0.02*temp) -273.15;
-
+
// Display values
printf("measure = %f = %.0f mV\n", meas_r, meas_v);
//temp =15143;
- printf("Temperature : %f \r\n",tempC);
+ printf("Body Temperature : %f \r\n",bodyTempF);
+
+
+ printf("Env Temperature : %f \r\n",envTempF);
}
@@ -65,6 +218,10 @@
}
+
+ // toggleing the button ////////////// +
+
+
void toggle()
{
myled = !myled;
@@ -80,6 +237,10 @@
int main() {
button.rise(&toggle) ;
+
+ //mlx90615_emisWrite(emis_human);
+ //mlx90615_emisWrite(emis_human);
+ wait(0.5);
while(1)
{
@@ -87,8 +248,14 @@
read_ecg(workState);
wait(1);
- }
+ }
}
+
+
+
+
+
+