From 074bc99875a1be7f94b8ed071bfe6cc1ca7f8fcd Mon Sep 17 00:00:00 2001 From: Vitali Date: Fri, 17 Jul 2026 19:30:34 +0700 Subject: [PATCH] feat: sketch scaffold with I2C bus bring-up and scanner Co-Authored-By: Claude Opus 4.8 --- WeatherPredictor/WeatherPredictor.ino | 27 +++++++++++++++++++++ WeatherPredictor/config.h | 34 +++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 WeatherPredictor/WeatherPredictor.ino create mode 100644 WeatherPredictor/config.h diff --git a/WeatherPredictor/WeatherPredictor.ino b/WeatherPredictor/WeatherPredictor.ino new file mode 100644 index 0000000..9e777ab --- /dev/null +++ b/WeatherPredictor/WeatherPredictor.ino @@ -0,0 +1,27 @@ +#include +#include +#include "config.h" + +static void i2cScan() { + Serial.println(F("I2C scan:")); + byte found = 0; + for (byte addr = 1; addr < 127; addr++) { + Wire.beginTransmission(addr); + if (Wire.endTransmission() == 0) { + Serial.printf(" device at 0x%02X\n", addr); + found++; + } + } + Serial.printf(" %d device(s) found\n", found); +} + +void setup() { + Serial.begin(115200); + delay(200); + Serial.println(F("\n=== Weather Predictor booting ===")); + Wire.begin(I2C_SDA, I2C_SCL); // MUST come before any I2C driver begin() + i2cScan(); +} + +void loop() { +} diff --git a/WeatherPredictor/config.h b/WeatherPredictor/config.h new file mode 100644 index 0000000..7f70e95 --- /dev/null +++ b/WeatherPredictor/config.h @@ -0,0 +1,34 @@ +#pragma once +#include + +// ---- TFT (hardware SPI: SCK=D5, MOSI=D7) ---- +#define TFT_CS D8 +#define TFT_DC D3 +#define TFT_RST D4 +#define TFT_BLK D2 + +// ---- I2C (BMP180 + DS3231 share this bus) ---- +#define I2C_SDA D6 +#define I2C_SCL D1 +#define BMP180_ADDR 0x77 +#define DS3231_ADDR 0x68 + +// ---- Scheduler intervals (ms) ---- +// NOTE: for quick bench testing you may temporarily shrink these. +static const unsigned long SAMPLE_INTERVAL_MS = 60UL * 1000UL; // read sensor / redraw +static const unsigned long HISTORY_INTERVAL_MS = 5UL * 60UL * 1000UL; // store a history sample +static const unsigned long FLUSH_INTERVAL_MS = 15UL * 60UL * 1000UL; // flush history to flash + +// ---- History buffer ---- +static const int HISTORY_SIZE = 288; // 24 h @ 5 min +static const float TREND_THRESHOLD_HPA = 1.6f; // >|1.6| hPa / 3 h = rising/falling + +// ---- Defaults (editable via web) ---- +static const float DEFAULT_ALTITUDE_M = 150.0f; +static const int DEFAULT_TZ_OFFSET_MIN = 7 * 60; // UTC+7 +static const float DEFAULT_LAT = 54.9870f; +static const float DEFAULT_LON = 82.8730f; + +// ---- Network ---- +#define NTP_SERVER "pool.ntp.org" +#define AP_NAME "WeatherPredictor-Setup"