|
目的:ESP-12M,CO2センサー,CCS811(3) で作成したCO2 センサーに液晶表示を接続する
注意点1:
LCDのI2C アドレスを試行錯誤で決める
LiquidCrystal_I2C lcd(0x27, 20, 4); // 0x20 , 0x27 , 0x3F
注意点2:
LCD と I2Cコントローラは、3.3Vで動作した
注意点3:
CCS811のエージングは、仕様では48時間。 これでだいたい安定する。
1週間エージングするとさらに安定する。
1602 LCD 部品 : amazon
HiLetgo® 5個セット5V 1602LCD IIC/I2C/TWI/SPIシリアルインターフェイスモジュールポートarduinoに対応 [並行輸入品]
HiLetgo® 2個セット DC3.3V HD44780 1602 16x2キャラクタ LCDディスプレイモジュール MEGA2560 Nano Due Raspberry Pi Arduino UNO R3用 ブルーバックライト
その後、 20x4 のLCDと入れ替えた。2社から購入したところ、基板のパターンは同じであった。記号を印刷するスクリーンマスクが違うだけだった。
これらのVCCの仕様はいずれも5Vだが、1個だけは3,3Vでも動いている。別の1個は最初30秒は動くが自然に表示が崩れてしまう。違いの原因は設計ではなく、部品の選定または部品のばらつきだと推測する。
またはバックライトの色が原因。イエローは3.3Vで動くが、ブルーは動かない。イエローでも半固定抵抗をめいっぱい回して動いたので、部品のばらつきによって動かない場合も十分予想できる。
つまり一般的には3.3Vでは動かないと思うほうが良い。運がよければ動くかもしれない。
スケッチは1602 とほぼ同じである。ライブラリーは共通で使えた。
I2Cのアドレスは同じであった。これはたまたまである。 アドレスは半田でパターンをショートさせることで選択できる。
2004 LCD 部品 : amazon
HiLetgo® 5V 2004 20X4 キャラクタ LCDディスプレイ IIC I2C TWI SP I シリアル インタフェース 0x27/0x3f イエロー [並行輸入品] 3.3V動作Ok。 しかし、たまたま動いたと考えるべき。一般には3.3Vでは動かない。
Longruner Arduino ディスプレイ Arduino UNO R3 Mega2560適応 2004 LCD ディスプレイ モジュール IIC/I2C/TWI ブルースクリーン パネル拡張 ボード 4ピン ジャンパーワイヤーが付き LK51 3.3V動作不可能、もちろん5V動作Ok
朝食を食べると、TVOCが急増し、その後、緩やかに減少する。
夕食を食べると、TVOCが急増し、その後、緩やかに減少する。
感度がすごく安定してきた
FTP_dosi_r20n.ino
// revised from version h,k 2019/6/29
// SPIFFS usage http://arduino.esp8266.com/Arduino/versions/2.0.0/doc/filesystem.html // SPIFFS usage http://gadget.renesas.com/ja/reference/sakura/library_sdmmcfile.html // original source code http://toccho.xsrv.jp/2018/07/09/sensor-ftp-csv-esp-wroom02/ // combined with deepsleeptest8285HiLetGo_CCS811BME280_r11 // // reference source code for Liquid Crystal 2019/6/24 // http://sawayakanaegao.blog.fc2.com/blog-category-36.html // #include <Wire.h> #include "LiquidCrystal_I2C.h" // 20190624 #include <SparkFunCCS811.h> //Click here to get the library: http://librarymanager/All#SparkFun_CCS811 #include <SoftwareSerial.h> #include <FS.h> #include <ESP8266WiFi.h> // ESP8266?p???C?u???? #include <WiFiUdp.h> // UDP??M???s?????C?u???? #include <time.h> #define CCS811_ADDR 0x5A //Alternate I2C Address
#define PIN_NOT_WAKE 5 // #define row_max 5
#define PIN_CAM 13 // IO 13(5??s??)??Pch-FET???????? #define TIMEOUT 2000 // ?^?C???A?E?g 2?b #define SSID "" // ????LAN?A?N?Z?X?|?C???g??SSID
#define PASS "" // ????LAN?A?N?Z?X?|?C???g??p?X???[?h #define SENDTO "192.168.0.255" // UDP???M??IP?A?h???X(??X????K?v???)
#define PORT 1024 // UDP???M?|?[?g???(??X????K?v???) //FTP?T?[?o?[?????????????
#define FTP_TO "databooster.stars.ne.jp" // FTP ???M???IP?A?h???X(?????????????????B????????IP?????????????) #define FTP_USER "databooster.stars.ne.jp" // FTP ???[?U?? #define FTP_PASS "" // FTP ?p?X???[?h #define FTP_DIR "/FTP_dosi_r20m" // FTP ?f?B???N?g?? #define FILENAME "/spiffs.txt" //FTP?T?[?o?[?????t?@?C????(???????t?@?C????) #define FILENAMEserver "/datatoserver.txt" #define FILENAMEtemp "/datatotemp.txt" #define JST 3600*9
LiquidCrystal_I2C lcd(0x27, 20, 4); // 0x20 , 0x27 , 0x3F
CCS811 myCCS811(CCS811_ADDR); File file;
WiFiUDP udpFtp; // UDP??M?p??C???X?^???X???` WiFiServer server(80); // Wi-Fi?T?[?o(?|?[?g80=HTTP)??` void setup() {
delay(100); lcd.begin(); delay(100); Serial.begin(115200); delay(100); Serial.println(); Serial.println("CCS811"); Wire.begin();
//This begins the CCS811 sensor and prints error status of .begin() CCS811Core::status returnCode = myCCS811.begin(); delay(100); Serial.print("CCS811 begin exited with: "); //Pass the error code to a function to print the results printDriverError( returnCode ); Serial.println(); //It is recommended to check return status on .begin(), but it is not required.
// CCS811Core::status returnCode = myCCS811.begin(); if (returnCode != CCS811Core::SENSOR_SUCCESS) { Serial.println(".begin() returned with an error."); while (1); //No reason to go further } SPIFFS.begin();
delay(100); WiFi.mode(WIFI_STA); // ????LAN??STA???[?h???? WiFi.begin(SSID, PASS); // ????LAN?A?N?Z?X?|?C???g???? while (WiFi.status() != WL_CONNECTED) { // ???????????????? Serial.print("."); delay(500); // ?????????? } server.begin(); // ?T?[?o???N?????? configTime( JST, 0, "ntp.nict.jp", "ntp.jst.mfeed.ad.jp");
} void loop() {
//Check to see if data is available delay(100); if (myCCS811.dataAvailable()) { //Calling this function updates the global tVOC and eCO2 variables myCCS811.readAlgorithmResults(); delay(100); //printInfoSerial fetches the values of tVOC and eCO2 printInfoSerial(); delay(100); // 20190529 // delay(3000); Serial.println("CCS811 data:"); Serial.print(" CO2 concentration : "); Serial.print(myCCS811.getCO2()); delay(10); Serial.println(" ppm"); // 20190622
time_t t; struct tm *tm; delay(200); // must wait for more than 200 msec t = time(NULL); tm = localtime(&t); char datetime[10]; sprintf(datetime, "%02d/%02d %02d:%02d", tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min); Serial.println(datetime); // make file for web float realCO2 = myCCS811.getCO2(); delay(100); float realTVOC = myCCS811.getTVOC(); delay(100); float analogOUT_L = analogRead(A0) + 10; delay(100); // 20190624
lcd.clear(); lcd.setCursor(0,0); lcd.print(datetime); delay(10); lcd.setCursor(0,1); lcd.print("CO2"); delay(10); lcd.setCursor(5,1); lcd.print(realCO2,0); delay(10); lcd.setCursor(0,2);
lcd.print("TVOC"); delay(10); lcd.setCursor(5,2); lcd.print(realTVOC,1); delay(10); lcd.setCursor(0,3);
lcd.print("CdS"); delay(10); lcd.setCursor(5,3); lcd.print(analogOUT_L / 10 , 0); delay(10); File f = SPIFFS.open(FILENAME, "a"); // ?????????t?@?C?????J??(??L???[?h??I?[?v??) delay(10); f.print(datetime); // ??????????????(???????????????????????????) f.print(" , "); f.print(realCO2 / 100.0,1);
f.print(" , "); delay(100); f.print(realTVOC / 10.0,1);
f.print(" , "); delay(100); f.print(analogOUT_L / 10 , 0);
f.print(" , "); delay(100); f.print("100.0 , "); delay(100); f.println("100.0"); f.close(); //?t?@?C???????? File file = SPIFFS.open(FILENAME, "r"); // ?????????t?@?C?????J??
if (file == 0) sleep(); // ?t?@?C?????J????????Ζ?? // add
int row = 0 ; int row_org = 0 ; Serial.println(""); while(file.available()){ String str; str = file.readStringUntil('\n'); Serial.println(str); row = row + 1 ; } row_org = row ; file.seek(0, SeekSet); Serial.print("num of row = "); Serial.println(row_org); File fileserver = SPIFFS.open(FILENAMEserver, "w"); File filetemp = SPIFFS.open(FILENAMEtemp, "w"); row = 0;
int row_max = 50 ; String str; while(file.available()){ str = file.readStringUntil('\n'); if ( row_org < row_max + row + 1 ) { fileserver.print(str); fileserver.print('\n'); filetemp.print(str); filetemp.print('\n'); Serial.println(row);
} row = row + 1 ; } file.close(); SPIFFS.remove(FILENAME);
SPIFFS.rename(FILENAMEtemp, FILENAME); delay(200); // must wait for more than 200 msec
byte ret = doFTP(FILENAMEserver); // FTP????M????
if (ret) { Serial.print("FTP Err :"); Serial.println(ret); delay(3000); } Serial.print("http://"); // ?f?o?C?X?????V???A???\?? Serial.print(WiFi.localIP()); // ?{?@??IP?A?h???X???V???A???\?? Serial.println(FILENAME); udpFtp.beginPacket(SENDTO, PORT); // UDP???M????? udpFtp.print(", http://"); udpFtp.print(WiFi.localIP()); // ?{?@??IP?A?h???X? M udpFtp.println(FILENAME); // ?f?o?C?X??? M udpFtp.endPacket(); // UDP???M??I??(???????M????) // end delay(100); }
else if (myCCS811.checkForStatusError()) { //If the CCS811 found an internal error, print it. delay(100); printSensorError(); } delay(1000); //Wait for next reading
Serial.println("finish"); // ?I???\?? delay(54000 + 14 * 60 * 1000); //finish???M??@???? // delay(54000); //finish???M??@???? }
//---------------------------------------------------------------
void printInfoSerial() { //getCO2() gets the previously read data from the library delay(100); Serial.println("CCS811 data:"); Serial.print(" CO2 concentration : "); delay(100); Serial.print(myCCS811.getCO2()); delay(100); Serial.println(" ppm"); //getTVOC() gets the previously read data from the library
Serial.print(" TVOC concentration : "); delay(100); Serial.print(myCCS811.getTVOC()); delay(100); Serial.println(" ppb"); }
//printDriverError decodes the CCS811Core::status type and prints the
//type of error to the serial terminal. // //Save the return value of any function of type CCS811Core::status, then pass //to this function to see what the output was. void printDriverError( CCS811Core::status errorCode ) { switch ( errorCode ) { case CCS811Core::SENSOR_SUCCESS: Serial.print("SUCCESS"); break; case CCS811Core::SENSOR_ID_ERROR: Serial.print("ID_ERROR"); break; case CCS811Core::SENSOR_I2C_ERROR: Serial.print("I2C_ERROR"); break; case CCS811Core::SENSOR_INTERNAL_ERROR: Serial.print("INTERNAL_ERROR"); break; case CCS811Core::SENSOR_GENERIC_ERROR: Serial.print("GENERIC_ERROR"); break; default: Serial.print("Unspecified error."); } } //printSensorError gets, clears, then prints the errors
//saved within the error register. void printSensorError() { delay(1000); // 201904 important uint8_t error = myCCS811.getErrorRegister(); delay(100); // 201904 important if ( error == 0xFF ) //comm error { Serial.println("Failed to get ERROR_ID register."); } else { Serial.print("Error: "); if (error & 1 << 5) Serial.print("HeaterSupply"); if (error & 1 << 4) Serial.print("HeaterFault"); if (error & 1 << 3) Serial.print("MaxResistance"); if (error & 1 << 2) Serial.print("MeasModeInvalid"); if (error & 1 << 1) Serial.print("ReadRegInvalid"); if (error & 1 << 0) Serial.print("MsgInvalid"); Serial.println(); } } さらに、ESP-12M,CO2センサー,CCS811(3) のコードを追加する
|

- >
- コンピュータとインターネット
- >
- コンピュータ
- >
- ソフトウェア





