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.
Dependencies: mbed
Revision 6:b5f2a1f5b91a, committed 2020-06-14
- Comitter:
- christodoulos
- Date:
- Sun Jun 14 13:14:13 2020 +0000
- Parent:
- 5:97429a69bdcd
- Commit message:
- Si7051 (used in POCBreath_V2_smd_commercial)
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri May 01 14:32:54 2020 +0000
+++ b/main.cpp Sun Jun 14 13:14:13 2020 +0000
@@ -1,17 +1,29 @@
#include "mbed.h"
-#include "eco2.h"
//I2C bus for both ZMOD and temperature sensor
-Serial pc(PC_12, PD_2);
-I2C i2c(PB_9, PB_8);
-DigitalOut wake(PB_2);
-
-uint16_t eco2, tvoc;
-
-
+Serial ttl(PC_12, PD_2);
+I2C ZMODtemp(PB_9, PB_8);
+DigitalOut red(PC_4);
+DigitalOut amber(PC_5);
+DigitalOut green(PB_0);
int main()
{
- int addr=0x80; //si7050 8bit address
+ ttl.baud(115200); //baudrate for the serial connection, 9600 for hc05 115200 for rn
+
+ ttl.printf("$");//enter command mode only for rn
+ wait(0.5);
+ ttl.printf("$$");//enter command mode
+ wait(0.5);
+ ttl.printf("SN,Si7051\r");//set new name
+ wait(0.5);
+ ttl.printf("SS,C0\r");//set transparent uart
+ wait(0.5);
+ ttl.printf("&,4782CC640611\r");//Assign mac
+ wait(0.5);
+ ttl.printf("---\r");//enter data mode
+ wait(0.5);
+
+ int ZMODTEMPaddr=0x80; //si7050 8bit address
char wTemp[1];
wTemp[0]=0xE3; //Hold master mode
@@ -22,15 +34,24 @@
wInit[0]=0xE6; //User register 1
wInit[1]=0x00; //Set 14 bit resolution, other read-ony registers shouldn't be affected
- i2c.write(addr,wInit,2);
+ ZMODtemp.write(ZMODTEMPaddr,wInit,2);
while(1){
- i2c.write(addr,wTemp,1);
- i2c.read(addr,rTemp,2); //Returns 2 bytes
+ ZMODtemp.write(ZMODTEMPaddr,wInit,2); //maybe
+ ZMODtemp.write(ZMODTEMPaddr,wTemp,1);
+ ZMODtemp.read(ZMODTEMPaddr,rTemp,2); //Returns 2 bytes
float temp_code=(rTemp[0]<<8)+rTemp[1];
float temp=((175.72*temp_code)/65536)-46.85;
- pc.printf("Temp: %f\n",temp);
-
+ ttl.printf("Temp: %f\n",temp_code);
+ wait(1);
+ red=1;
+ amber=1;
+ green=1;
+ wait(2);
+ red=0;
+ amber=0;
+ green=0;
+ wait(2);
}
}
\ No newline at end of file