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: Cayenne-MQTT-mbed NetworkSocketAPI X_NUCLEO_IDW01M1v2 mbed Servo
Fork of Cayenne-X-NUCLEO-IDW01M1-TMP36 by
BME280.hpp
00001 #include "mbed.h" 00002 #define size 14 00003 Serial sensor(PA_11,PA_12); 00004 Serial pc(USBTX,USBRX); 00005 int AT[3] = {0xA5,0x52,0xF7}; 00006 class BME280{ 00007 public: 00008 void judgement_data(char buf[]); 00009 int Temp_read(); 00010 00011 private: 00012 void receive(); 00013 void send_AT(); 00014 char buf[size]; 00015 int Lux,Temp,Preesure,Hum,Height; 00016 00017 }; 00018 void BME280::judgement_data(char buf[]){ 00019 int i=0; 00020 if(buf[i++]== 0x5A){ 00021 //pc.printf("first_step\n"); 00022 if(buf[i++]== 0x5A){ 00023 //pc.printf("second_step\n"); 00024 //i++;//go to data type 00025 if(buf[i] == 0x15){ 00026 //pc.printf("Lux type\n"); 00027 i++;//04 00028 Lux = ((buf[i+1]<<24) | (buf[i+2]<<16) | (buf[i+3]<<8) | buf[i+4])/100; 00029 //Lux = (0x00<<24) | (0x00<<16) | (0xFE<<8) | 0x40;//test 00030 //pc.printf("Lux = %d\n", Lux); 00031 }else if(buf[i] == 0x45){ 00032 //pc.printf("temp type\n"); 00033 i++;//0A 00034 Temp = ((buf[i+1]<<8)|(buf[i+2]))/100; 00035 Preesure = ((buf[i+3]<<24)|(buf[i+4]<<16)|(buf[i+5]<<8)|(buf[i+6]))/100; 00036 Hum = ((buf[i+7]<<8)|(buf[i+8]))/100; 00037 Height = ((buf[i+9]<<8)|(buf[i+10])); 00038 //pc.printf("Temp = %d\n", Temp); 00039 //pc.printf("Preesure = %d\n", Preesure); 00040 //pc.printf("Hum = %d\n", Hum); 00041 //pc.printf("Height = %d\n", Height); 00042 } 00043 } 00044 } 00045 } 00046 void BME280::receive(){ 00047 for(int i=0;i<size;i++){ 00048 buf[i] = sensor.getc(); 00049 //pc.putc(buf[i]); 00050 } 00051 00052 } 00053 void BME280::send_AT(){ 00054 for(int i=0;i<3;i++){ 00055 sensor.putc(AT[i]); 00056 //pc.putc(AT[i]); 00057 } 00058 } 00059 int BME280::Temp_read(){ 00060 send_AT(); 00061 //wait(0.2); 00062 receive(); 00063 //wait(0.2); 00064 judgement_data(this->buf); 00065 00066 return Temp; 00067 }
Generated on Fri Jul 15 2022 12:34:44 by
1.7.2
