avaldebe/PMserial: Arduino library for PM sensors with serial ...

文章推薦指數: 80 %
投票人數:10人

PMS5003S and PMS5003T sensors need to be declared explicitly on the SerialPM constructor. PMSx003 on HardwareSerial. #include SerialPM pms ... Skiptocontent {{message}} avaldebe / PMserial Public Notifications Fork 11 Star 36 ArduinolibraryforPMsensorswithserialinterface MITLicense 36 stars 11 forks Star Notifications Code Issues 4 Pullrequests 0 Actions Projects 0 Wiki Security Insights More Code Issues Pullrequests Actions Projects Wiki Security Insights master Branches Tags Couldnotloadbranches Nothingtoshow {{refName}} default Couldnotloadtags Nothingtoshow {{refName}} default 1 branch 6 tags Code Latestcommit avaldebe bumpversion … 2b88c70 Mar19,2021 bumpversion 2b88c70 Gitstats 119 commits Files Permalink Failedtoloadlatestcommitinformation. Type Name Latestcommitmessage Committime .vscode     examples     src     .gitignore     .travis.yml     LICENSE     Makefile     README.md     library.json     library.properties     Viewcode PMSerial Sensors Compatibility Usage PMSx003sensortype PMSx003onHardwareSerial PMSx003onSoftwareSerial ESP32Serial1 Advancedusage Sensormessage/protocol Additionalmeasurements Decodedmeasurements Statusanderrorcodes Temperatureandhumidityoffsetcorrection(Optional) Contribute Changelog README.md PMSerial ArduinolibraryforPMsensorswithserialinterface Sensors Plantower TestedWorks Doesn'tWork NotTested Datasheet Notes PMS1003(akaG1) X en,cn PMS3003(akaG3) X en,cn Nopassivemoderead PMS5003(akaG5) X en,cn PMS5003S(akaG5S) X cn PMS5003T(akaG5T) X PMS5003ST(akaG5ST) X PMS7003(akaG7) X cn PMSA003(akaG10) X cn Compatibility MCU TestedWorks Doesn'tWork NotTested Examples Notes ATmega168@8MHz X SoftwareSerial Atmega168@16MHz X 5Vboardsneed3.3V/5Vlevelshifter Atmega328@8MHz X SoftwareSerial Atmega328@16MHz X 5Vboardsneed3.3V/5Vlevelshifter Atmega32u4@8MHz X Atmega32u4@16MHz X HardwareSerial 5Vboardsneed3.3V/5Vlevelshifter Atmega2560@16MHz X HardwareSerial 5Vboardsneed3.3V/5Vlevelshifter STM32f103c8 X HardwareSerial STM32f103cb X HardwareSerial ESP8266 X HardwareSerialSoftwareSerialOLED64x48 needsEspSoftwareSerial@>=6.7.1 ESP32 X HardwareSerialSoftwareSerialOLED64x48 Serial1asSoftwareSerial Usage PMSx003sensortype ThePMSx003sensortypewillinferthesensortypefromthemessageheader. ThesensortypeinferencedoesnotcoverthePMS5003SandPMS5003Tvariants,see#10. PMS5003SandPMS5003TsensorsneedtobedeclaredexplicitlyontheSerialPMconstructor. PMSx003onHardwareSerial #include SerialPMpms(PMSx003,Serial);//PMSx003,UART voidsetup(){ Serial.begin(9600); pms.init();//configserialport } voidloop(){ pms.read();//readthePMsensor Serial.print(F("PM1.0"));Serial.print(pms.pm01);Serial.print(F(",")); Serial.print(F("PM2.5"));Serial.print(pms.pm25);Serial.print(F(",")); Serial.print(F("PM10"));Serial.print(pms.pm10);Serial.println(F("[ug/m3]")); delay(10000);//waitfor10seconds } SetupfordifferentMCUiscoveredontheHardwareSerialexample. PMSx003onSoftwareSerial #include SerialPMpms(PMSx003,10,11);//PMSx003,RX,TX voidsetup(){ Serial.begin(9600); pms.init();//configserialport } voidloop(){ pms.read();//readthePMsensor Serial.print(F("PM1.0"));Serial.print(pms.pm01);Serial.print(F(",")); Serial.print(F("PM2.5"));Serial.print(pms.pm25);Serial.print(F(",")); Serial.print(F("PM10"));Serial.print(pms.pm10);Serial.println(F("[ug/m3]")); delay(10000);//waitfor10seconds } SetupfordifferentMCUiscoveredontheSoftwareSerialexample. ESP32Serial1 OnsomeESP32boardsSerial1defaultpinsareconnectedtotheflash. Usingthestandardconstructorwillcauseacrash,seeespressif/arduino-esp32#148. //willcrashtheESP32 SerialPMpms(PMSx003,Serial1); Fortunately,itispossibletodefinealternativeforpinsbycalling: //defineSerial1pins Serial1.begin(9600,SERIAL_8N1,,); ThePMSeriallibraryusesthisfeaturetoimplementtheflexibilityofSoftwareSerial //defineSerial1pins SerialPMpms(PMSx003,,); TheSoftwareSerialexampleusesSerial1onpins23(RX)and19(TX). TheHardwareSerialexampleusesSerial2. Advancedusage Sensormessage/protocol WiththeexemptionofthePMS3003andPMS5003ST,allsupportedsensors transmitparticulatematter(PM)andnumberconcentrations(NC) measurementsina32bytelongmessage. ThePMS3003onlytransmitPMmeasurementsina24bytemessage. ThePMS5003STtransmitPM,NC,temperature(T),relativehumidity(RH)andformaldehydeconcentration(HCHO)measurements ona40bytemessage. Ontheexamples,thePMSx003sensortypewillinferthesensortypefromthemessageheader andselectthemessagelengthanddecodingprotocolaccordingly. Thesupportedprotocolsare: message/protocol length PM NC T&RH HCHO sensors(aliases) PLANTOWER_AUTO selfdiscovery 3 auto PMSx003 PLANTOWER_24B 24bytes 3 PMS3003 PLANTOWER_32B 32bytes 3 6 PMS1003,PMS5003,PMS7003,PMSA003 PLANTOWER_32B_S 32bytes 3 6 X PMS5003S,cannotbeselfdiscovered PLANTOWER_32B_T 32bytes 3 4 X PMS5003T,cannotbeselfdiscovered PLANTOWER_40B 40bytes 3 6 X X PMS5003ST Additionalmeasurements Thepms.read()methodwillrequestanewmeasurementsetfromthesensoranddecodethesensormessage. Thehas_particulate_matter()/has_number_concentration()methodsindicateifthemessagewasvalid andPM/NCmeasurementsweresuccessfullydecoded. Similarlythehas_temperature_humidity/has_formaldehydemethodsindicateifthemessagewasvalid andT&RH/HCHOmeasurementsweresuccessfullydecoded,however thiskindofadditionalmeasurementsareonlyavailableonPMS5003S,PMS5003TandPMS5003STsensors. Decodedmeasurements Allmeasurementsfoundinthesensormessage willbedecodedandstoredinfollowingmembervariables: variable type[len] measurement particlediameter unit Notes pm01 uint16_t PM <=1.0µm µg/m³ PM1.0,ultrafineparticles pm25 uint16_t PM <=2.5µm µg/m³ PM2.5,fineparticles pm10 uint16_t PM <=10µm µg/m³ PM10 n0p3 uint16_t NC >=0.3µm #/100cm³ n0p5 uint16_t NC >=0.5µm #/100cm³ n1p0 uint16_t NC >=1.0µm #/100cm³ n2p5 uint16_t NC >=2.5µm #/100cm³ n5p0 uint16_t NC >=5.0µm #/100cm³ n10p0 uint16_t NC >=10µm #/100cm³ pm uint16_t[3] PM <=1,2.5,10µm µg/m³ arraycontainingpm01,pm25,pm10 nc uint16_t[6] NC >=0.3,0.5,1,5,10µm #/100cm³ arraycontainingn0p3,..,n10p0 data uint16_t[9] PM/NC allPM/NCdatapm01,..,n10p0 temp float T °C temperature rhum float RH % relativehumidity hcho float HCHO mg/m³ formaldehydeconcentration extra float[3] T/RH/HCHO arraycontainingtemp,rhum,hcho Foranefficientuseofmemory,thedata,pmandncarraysandthe individualmeasurementvariablesareimplementedwithaunion/structcombination. SeetheexamplesforanfullPM/NCoutput. Statusanderrorcodes Thepms.statusmembervariablecontainsthestatusandeventualerrorcode resultingfromthelastsensorread. Theavailablestatus/errorcodesandpre-definederrormessagesare: status/errorcode errormessage pre-definedtext pms.OK pms.ERROR_TIMEOUT PMS_ERROR_TIMEOUT "Sensorreadtimeout" pms.ERROR_PMS_TYPE PMS_ERROR_PMS_TYPE "WrongPMSx003sensortype" pms.ERROR_MSG_UNKNOWN PMS_ERROR_MSG_UNKNOWN "Unknownmessageprotocol" pms.ERROR_MSG_HEADER PMS_ERROR_MSG_HEADER "Incompletemessageheader" pms.ERROR_MSG_BODY PMS_ERROR_MSG_BODY "Incompletemessagebody" pms.ERROR_MSG_START PMS_ERROR_MSG_START "Wrongmessagestart" pms.ERROR_MSG_LENGTH PMS_ERROR_MSG_LENGTH "Messagetoolong" pms.ERROR_MSG_CKSUM PMS_ERROR_MSG_CKSUM "Wrongmessagechecksum" Foreasyofuse,theerrormessagearepre-definedwith#define. Seetheexamplesforerrorhandlingimplementation. Temperatureandhumidityoffsetcorrection(Optional) Somesensorshaveasmalldeviationwithtemperatureandhumidityreadings. Thecompensateispossiblewithacorrectionoffsetdefinedbyset_temp_offset()andset_rhum_offset(). Theresultwillbereading+offset.DefaultoffsetvaluesareO. Example: set_temp_offset(-0.6); set_rhum_offset(2); Contribute Ifyouhavereadthisfar,thisisthelibraryforyourproject oryoucannotfigureouthowtouseit.Inanycase,Icanuseyourhelp. Ifyoufindanytyposorsomethingisnotclear,pleasegotoissue#3andleaveamessage. Reopentheissueifneeded. Ifyouwantsomethingabitmorechallenging.Iwouldappreciatemoreexampleprojects. Seeissue#4forinspiration.PRsarewelcomed. Changelog 1.1.1 FixSoftwareSerialdanglingpointer#19/PR20 ESP8266nolongerrequiresEspSoftwareSerial 1.1.0 Supportatmelsamdevices#8/PR12 SupportthePMS5003S/ST/Tsensors#10,#16/PR17 Supportsleep/wakecommands#14/PR15 UseSerial1as"SoftwareSerial"forESP32,#7/PR9 1.0.1 FixbrokenSoftwareSerialforESP8266,#6 ESP8266useEspSoftwareSerial@>=6.7.1 1.0.0 firstcompleterelease About ArduinolibraryforPMsensorswithserialinterface Topics esp8266 esp32 air-quality arduino-library pm25 pm10 uno leonardo pms3003 pms5003 pms7003 mega2560 stm32f1 particulate-matter pmsa003 Resources Readme License MITLicense Stars 36 stars Watchers 4 watching Forks 11 forks Releases 6 tags Packages0 Nopackagespublished Contributors3       Languages C++ 98.7% Makefile 1.3% Youcan’tperformthatactionatthistime. Yousignedinwithanothertaborwindow.Reloadtorefreshyoursession. Yousignedoutinanothertaborwindow.Reloadtorefreshyoursession.



請為這篇文章評分?