// This example shows how to read temperature/pressure // This sketch basedon Infeneon example i2ccommand.ino // https://www.infineon.com/cms/jp/product/sensor/pressure-sensors/pressure-sensors-for-iot/dps310/ // LCD lib from Lang-ship https://lang-ship.com/blog/work/esp32-3248s035/ // use Serial.begin(9600); // instead of 115200, position is at first! // Y.Okamoto 2021-01-23 Pressure cal. on 04-18 // board writing error 2024-05-03 (Solved the following!) // 2024-05-04 on writing moment: on board BOOT SW = push!! // encounter unknown compiling error on 2024-05-05 by ChatGPT suggesstion // But it solved to use AruinoIDE v2 on 5th May // upgrade version name to 1Hz ver3 is trashed // update on 11th May 2024 // It is necessary to connect R24 pins for capturing screenshot of LCD // for more details are shown at http://seagull.stars.ne.jp/Barometer/prototype/Micro-Barometer_ESP32_Recipe.html Thanks to Mr.Masayuki Tanaka #include const char* ssid = "Your ID"; //My-Rooter ID "xxxxxxxxxxx"; const char* password = "Your PW"; //My_Rooter PW "xxxxxxxxxxx"; WiFiClient client; // Battery_checker_init from https://programresource.net/2020/02/24/2960.html // with RGB #define RGB(r,g,b) (int16_t)(b + (g << 5) + (r << 11)) //色0~31 緑0~63 unsigned long currentMillis; unsigned long lastupdateMillis = 0; // for 1Hz sampling by ChatGPT int lastbattery = -1; // DPS310 micro-pressure sensor library #include Dps310 Dps310PressureSensor = Dps310(); float temperature; float pressure; // [Pascal] float pressure_h; // [hPa] float meanP; // previous pressure value float height; float cal_P= -0.700; // Pressure calibration from -0.725 on 5th May 2024 uint8_t oversampling = 7; // over sampling rate int16_t ret; // init for dislay ------------------------------------ int t = 0; // temp t int l = 1; // line number int d = 1; // data number int tm = 0; // time mark init. int dmax = 7200; // 120[min] data at 1Hz int lmax = 15; // signal line number 2022-08-15, 20 to 25 on 5th May 2024 int xmax = 480; // display xmax pixel // connecting JST server #define JST (3600L * 9) #include struct tm timeinfo; uint8_t minLastReport = 0; String dateStr; // date for file name String timeStr; // time for file name // SD card init. #include #include #include File myFile; // Open filer String myFile_BMP; // Open filer char fn[100]; // file name // Graphics library #include "ESP32-3248S035r.h" // by Lang-ship https://lang-ship.com/blog/work/esp32-3248s035/ static LGFX lcd; // LGFXのインスタンスを作成。 #define BitImageSize (320 * 480 * 3) //画面キャプチャーイメージサイズ #define PixelPerMeter (320 / 4 * 100) //画面解像度 // setup-------------------------------------------------------- void setup() { Serial.begin(9600); // at first! wifi_start(); // wifi // Initialize SD card. forget this! 2023-01-24 if (!SD.begin()) { lcd.println( "Card failed, or not present"); // Print a message if the SD card while (1); } lcd.init(); // 回転方向を 0~3 の4方向から設定します。(4~7を使用すると上下反転になります。) lcd.setRotation(3); Serial.begin(115200); lcd.setColorDepth(16); lcd.startWrite(); lcd.setAddrWindow(0, 0, lcd.width(), lcd.height()); while (!Serial); // confirmatiion Dps310PressureSensor.begin(Wire); // connect to DPS310 via i2c Serial.println("Init complete!"); // serial port completed //WiFi.mode(WIFI_OFF); // 2022-08-15 https://www.mgo-tec.com/blog-entry-m5stack-yahoo-weather-news-scrolle-watch-message.html } // for 1Hz sampling by ChatGPT int lastSecond = -1; // Variable to store the last second void loop() { lcd.clear(); // lcd.fillScreen(TFT_PINK); l = 1; lcd.setCursor(0, 0); getLocalTime(&timeinfo); // get local time lcd.printf("%02d/%02d/%02d %02d:%02d:%02d", timeinfo.tm_year + 1900, timeinfo.tm_mon + 1, timeinfo.tm_mday, timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec); dateStr = (String)(timeinfo.tm_year + 1900) + "-" + (String)(timeinfo.tm_mon + 1) + "-" + (String)timeinfo.tm_mday; timeStr = (String)timeinfo.tm_hour + "_" + (String)timeinfo.tm_min + "_" + (String)timeinfo.tm_sec; // title lcd.setCursor(180, 0); lcd.printf("DPS310-ESP32_1Hz by Yoshio Okamoto 6th May 2024"); Serial.println(); ret = Dps310PressureSensor.measurePressureOnce(pressure, oversampling); meanP = pressure/100.0 + cal_P; // Pressure calibration; ; // uint16_t c = M5.Lcd.color565(r, g, b); lcd.drawLine(5,200, 5,300,0x001F); lcd.drawLine(0,200,10,200,0x001F); lcd.drawLine(0,300,10,300,0x001F); lcd.drawCentreString("+1.0hPa", 20, 180, 1); // get sensor data ------------------------------- Serial.println(); ret = Dps310PressureSensor.measureTempOnce(temperature, oversampling); // for temperature [Cercius] if (ret != 0) { Serial.print("FAIL! ret = "); Serial.println(ret); } else { Serial.print("Temperature: "); Serial.println(temperature); // lcd.drawCentreString(" " + String(temperature) + "'C", 6, 260, 2); } ret = Dps310PressureSensor.measurePressureOnce(pressure, oversampling); // for At_pressure [Pa] if (ret != 0) { Serial.print("FAIL! ret = "); Serial.println(ret); } else { Serial.print("Pressure: "); Serial.print(pressure / 100.0, 4); Serial.println(" hPa"); pressure_h = pressure/100.0 + cal_P; // Pressure calibration; // pressure for [hPa] } // data file open myFile = SD.open("/"+ dateStr + "-" + timeStr + ".dat", FILE_APPEND); // "/" is important Serial.println("/"+ dateStr + "-" + timeStr + ".dat"); while (l <= lmax){ // graph plot int x; // x int y; // y int xp; // previous x int yp; // previous y int x0 = 0; // first plot offset float ls = 16.0; // line span 15 to 16 on 5th May 2024 float pm = 100.0; // magnify Pressure 100 pixel for +1hPa lastSecond = timeinfo.tm_sec; // Update lastSecond // for 1Hz sampling while (timeinfo.tm_sec == lastSecond) { // Check if the clock second has changed delay(1); getLocalTime(&timeinfo); } // display time and increment lastSecond = timeinfo.tm_sec; // Update lastSecond lcd.setCursor(0, 0); lcd.printf("%02d/%02d/%02d %02d:%02d:%02d", timeinfo.tm_year + 1900, timeinfo.tm_mon + 1, timeinfo.tm_mday, timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec); dateStr = (String)(timeinfo.tm_year + 1900) + "-" + (String)(timeinfo.tm_mon + 1) + "-" + (String)timeinfo.tm_mday; timeStr = (String)timeinfo.tm_hour + "_" + (String)timeinfo.tm_min + "_" + (String)timeinfo.tm_sec; // get local time // get temperature from DPS310 ----------------------- ret = Dps310PressureSensor.measureTempOnce(temperature, oversampling); if (ret != 0) { // Serial.print("FAIL! ret = "); // Serial.println(ret); } else { // Serial.print("Temperature: "); // Serial.print(temperature); // Serial.println(" degrees of Celsius"); } // get pressure from DPS310 ----------------------- ret = Dps310PressureSensor.measurePressureOnce(pressure, oversampling); if (ret != 0) { // Serial.print("FAIL! ret = "); // Serial.println(ret); } else { // Serial.print("Pressure: "); // Serial.print(pressure); // Serial.println(" Pascal"); } pressure_h = pressure/100.0 + cal_P; // Pressure calibration // calc height height = (( pow ( (1010.0 / pressure_h), ( 1.0 / 5.257 )) - 1.0 ) * ( temperature + 273.15) ) / 0.0065; // display data ----------------------------------- lcd.drawCentreString(String(pressure_h,3) + " hPa", 240, 300, 2); lcd.drawCentreString(String(temperature) + " ^C", 340, 300, 2); lcd.drawCentreString(String(height) + " m", 430, 300, 2); getLocalTime(&timeinfo); // get time for timemark if(minLastReport != timeinfo.tm_min) { // if min increment then time mark minLastReport = timeinfo.tm_min; tm = 6; // time mark[min] } else tm = 0; // no time mark // graph plot ------------------------------------- x = t + x0; y = int((meanP - pressure_h) * pm + l * ls -tm + 10.0); // sign reversed 10.0 need to adjust the line position lcd.drawPixel(x, y, TFT_GREEN); // At_pressure graph plot lcd.drawCentreString("d=" + String(d), 20, 310, 1); // valuse are displayed on LCD lcd.drawCentreString("x=" + String(x), 80, 310, 1); lcd.drawCentreString("y=" + String(y),140, 310, 1); // write data to SD card -------------------------- myFile.printf("%02d/%02d/%02d %02d:%02d:%02d %4.3f, %3.2f \n",timeinfo.tm_year + 1900,timeinfo.tm_mon + 1,timeinfo.tm_mday,timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec, pressure_h, temperature); Serial.printf("%02d/%02d/%02d %02d:%02d:%02d %4.3f, %3.2f \n",timeinfo.tm_year + 1900,timeinfo.tm_mon + 1,timeinfo.tm_mday,timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec, pressure_h, temperature); t = t + 1; if (t > xmax){ // if the signal line reached at the right end t = 0; // rest the signal position for x l = l + 1; // iterate the signal line y position } d = d + 1; } myFile.close(); // close data file // capture screen Screen_Capture_BMP(); //delay(5000); } void Screen_Capture_BMP(){ lcd.setBrightness(10); //バックライトを暗くする Serial.println("BMP_start"); // std::size_t dlen; bool result = false; //static constexpr char filename[] = "/lovyangfx_test.bmp"; File file = SD.open("/"+ dateStr + "-" + timeStr + ".bmp", "w"); if (file) { int width = 480; int height = 320; int rowSize = (2 * width + 3) & ~ 3; // Serial.println("rowSize="); // Serial.println(rowSize); lgfx::bitmap_header_t bmpheader; bmpheader.bfType = 0x4D42; bmpheader.bfSize = rowSize * height + sizeof(bmpheader); bmpheader.bfOffBits = sizeof(bmpheader); bmpheader.biSize = 40; bmpheader.biWidth = width; bmpheader.biHeight = height; bmpheader.biPlanes = 1; bmpheader.biBitCount = 16; bmpheader.biCompression = 3; file.write((std::uint8_t*)&bmpheader, sizeof(bmpheader)); std::uint8_t buffer[rowSize]; memset(&buffer[rowSize - 4], 0, 4); for (int yy = height - 1; yy >= 0; yy--) { lcd.readRect(0, yy, width, 1, (lgfx::rgb565_t*)buffer); file.write(buffer, rowSize); } file.close(); Serial.println("BMP_end"); result = true; lcd.setBrightness(200); //バックライトの明るさを戻す } else { Serial.print("error:file open failure\n"); } // return result; } void wifi_start(){ // We start by connecting to a WiFi network Serial.println(); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected."); Serial.println("IP address: "); Serial.println(WiFi.localIP()); delay(1000); // NTPサーバと時刻を同期 configTime(JST, 0, "ntp.nict.jp", "time.google.com", "ntp.jst.mfeed.ad.jp"); // adjust inner clock // 最初に初期化関数を呼び出します。 getLocalTime(&timeinfo); // get date and time from M5 inner clock // getLocalTime(&timeInfo); // date and time for file naming dateStr = (String)(timeinfo.tm_year + 1900) + "-" + (String)(timeinfo.tm_mon + 1) + "-" + (String)timeinfo.tm_mday; timeStr = (String)timeinfo.tm_hour + "_" + (String)timeinfo.tm_min + "_" + (String)timeinfo.tm_sec; delay(1000); // WiFi.mode(WIFI_OFF); // 2022-08-15 https://www.mgo-tec.com/blog-entry-m5stack-yahoo-weather-news-scrolle-watch-message.html }