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.
main.cpp
00001 #include <string> 00002 #include "mbed.h" 00003 #include "sps30.h" 00004 00005 #define SDA0 D14 //PTE25 00006 #define SCL0 D15 //PTE24 00007 #define LEDON 0 00008 #define LEDOFF 1 00009 00010 using namespace std; 00011 00012 Serial pc(SERIAL_TX, SERIAL_RX); 00013 00014 //sps30 sps(SDA1, SCL1, 100000); //Microchip real time clock (set as 400kHz) 00015 DigitalOut myled(LED1); 00016 00017 //----------------------------------------------------------------------------- 00018 // initial splash display 00019 00020 void initSplash() { 00021 pc.printf("\r\n\r\n"); 00022 pc.printf("-----------------------------------------------------------------------------\r\n"); 00023 } 00024 00025 //----------------------------------------------------------------------------- 00026 // initial the scd30 00027 /* 00028 void initSPS30() { 00029 pc.printf("Initializing SPS30...\r\n"); 00030 uint8_t dbg = sps.SoftReset(); 00031 if (dbg != sps30::SPSnoERROR) pc.printf("No ack \r\n"); 00032 wait_ms(2000); 00033 sps.GetSerialNumber(); 00034 pc.printf(" - SPS30 s/n ascii: "); 00035 for(int i = 0; i < sizeof(sps.sn); i++) 00036 { 00037 pc.printf("%c", sps.sn[i]); 00038 } 00039 pc.printf("\r\n"); 00040 sps.GetArticleCode(); 00041 pc.printf(" - SPS30 article code ascii: "); 00042 for(int i = 0; i < sizeof(sps.acode); i++) 00043 { 00044 pc.printf("%d", sps.acode[i]); 00045 } 00046 pc.printf("\r\n"); 00047 sps.SetAutoCleanInterval(); 00048 pc.printf(" - SPS30 auto clean interval: %d", sps.clean_interval_i); 00049 pc.printf("\r\n"); 00050 00051 sps.StartMeasurement(); 00052 // sps.startFanClean(); 00053 // pc.printf(" - SPS30 start manual clean \r\n"); 00054 00055 } 00056 */ 00057 //----------------------------------------------------------------------------- 00058 //----------------------------------------------------------------------------- 00059 00060 00061 00062 int main() 00063 { 00064 myled = LEDOFF; 00065 pc.baud(9600); 00066 wait_ms(200); 00067 initSplash(); 00068 00069 Sps30 sps(SDA2, SCL2, 100000); 00070 sps.InitSensor(); 00071 wait(1); 00072 pc.printf("Serial Number: %s \r\n", sps.sensor_serial); 00073 00074 int count = 0; 00075 pc.printf("Ready...\r\n"); 00076 pc.printf(" count | MASS CONCENTRATION (ug/m3) | NUMBER CONCENTRATION (#/cm3) | Typical Particle Size \r\n"); 00077 pc.printf(" | PM1.0 | PM2.5 | PM4.0 | PM10.0 | PM0.5 | PM1.0 | PM2.5 | PM4.0 | PM10.0 | (um) \r\n"); 00078 pc.printf("---------------------------------------------------------------------------------------------------------------------------\r\n"); 00079 while(1) 00080 { 00081 myled = !myled; 00082 wait_ms(250); 00083 int ret = sps.PollSensor(); 00084 if (ret == SensorDriver::SENSOR_DATAOK) 00085 { 00086 pc.printf(" %5d |", count); 00087 for (int i = 0; i < sps.sensor_data.size(); i++) 00088 { 00089 pc.printf(" %s |", sps.sensor_data[i].second); 00090 } 00091 pc.printf("\r\n"); 00092 count++; 00093 } 00094 00095 /* 00096 sps.GetReadyStatus(); 00097 uint16_t redy = sps.ready; 00098 if(redy == sps30::SPSisReady) { 00099 uint8_t crcc = sps.ReadMeasurement(); 00100 count++; 00101 if(crcc != sps30::SPSnoERROR) pc.printf("ERROR: %d\r\n", crcc); 00102 else pc.printf(" %5d | %7.3f | %7.3f | %7.3f | %7.3f | %7.3f | %7.3f | %7.3f | %7.3f | %7.3f | %7.3f \r\n", \ 00103 count, sps.mass_1p0_f, sps.mass_2p5_f, sps.mass_4p0_f, sps.mass_10p0_f, sps.num_0p5_f, \ 00104 sps.num_1p0_f, sps.num_2p5_f, sps.num_4p0_f, sps.num_10p0_f, sps.typ_pm_size_f); 00105 } 00106 */ 00107 // pc.printf("breakpoint 2"); 00108 // sps.sensor_data.clear(); 00109 wait(5); 00110 } 00111 }
Generated on Tue Jul 26 2022 07:43:19 by
1.7.2