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.
Revision 3:3023306be214, committed 2020-12-03
- Comitter:
- vctkarthik
- Date:
- Thu Dec 03 16:59:50 2020 +0000
- Parent:
- 2:5e957dcc94bc
- Commit message:
- stm32f413-Discovery board
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Mar 08 04:08:55 2020 +0000
+++ b/main.cpp Thu Dec 03 16:59:50 2020 +0000
@@ -1,6 +1,6 @@
#include "mbed.h"
//#include "Mlx90615.h"
-
+// this is working one for Disco-F413Zh board as of Dec 3, 2020
/* for the button press device should start reading, then it should stop the loop for button press */
@@ -9,18 +9,18 @@
InterruptIn button(PA_0);
DigitalOut myled(LED1);
bool workState= false;
-
+
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 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;
+//const int emis_human = 16384 ;/// emis_val=0.98*16384+.49;
/*
uint8_t crc8(uint8_t *addr, uint8_t len)
@@ -41,47 +41,46 @@
return crc;
} */
-
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 tempC = (0.02*temp) -273.15; // temp in Celcius
float tempF= (tempC*9/5) +31;
-
+
return tempF;
-
+
}
-
-
+
+
//private:;
-
+
};
-
+
/*float mlx90615_readTemp(int regAddress)
{
@@ -89,43 +88,43 @@
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 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_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;
@@ -133,26 +132,26 @@
// 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);
@@ -160,19 +159,19 @@
// // 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
+//
+// //write to the high bits
// i2c.write(data_high);
// i2c.read(ack);
-//
+//
// //write pec
// i2c.write(crc8(emisData,4));
// i2c.read(ack);
-
+
@@ -184,78 +183,100 @@
{
float meas_r;
float meas_v;
+ int temp;
+ float tempC;
+ int ack=1;
float bodyTempF;
- float envTempF;
+ 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;
+
+ //temp =15143;
+ printf("Temperature : %f \r\n",tempC);
printf("Body Temperature : %f \r\n",bodyTempF);
-
-
+
+
printf("Env Temperature : %f \r\n",envTempF);
-
+
}
-
-
-
-
+
+
+
+
}
-
-
+
+
// toggleing the button ////////////// +
-
-
+
+
void toggle()
{
- myled = !myled;
+ myled = !myled;
workState = !workState;
-
-
-
-
+
+
+
+
}
-
+
int main() {
-
+
button.rise(&toggle) ;
-
+
//mlx90615_emisWrite(emis_human);
//mlx90615_emisWrite(emis_human);
wait(0.5);
while(1)
{
-
+
button.rise(&toggle) ;
read_ecg(workState);
-
+
wait(1);
+
}
-
-
-
+
+
+
}
-