Skip to content

Commit

Permalink
Merge pull request #12 from yakumo-saki/v3.2
Browse files Browse the repository at this point in the history
V3.2
  • Loading branch information
yakumo-saki authored Jan 8, 2021
2 parents bb7a375 + 345d1a8 commit 48da84b
Show file tree
Hide file tree
Showing 39 changed files with 421 additions and 211 deletions.
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
"regex": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp"
"utility": "cpp",
"deque": "cpp",
"list": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"initializer_list": "cpp"
}
}
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ if SSD1306 is connected, sensor value are displayed in SSD1306

(v3.0)
ST7789 is supported. Activate on config screen.
In setup mode, no output.
In setup mode, no output on ST7789, it's normal.

(v3.2)
ST7789 support is now ESP32 only.
Maybe I can support ST7789 on ESP8266. but not in TODO.

### http server

Expand All @@ -101,7 +105,33 @@ esptool.py write_flash 0x1000 filename.bin
```
Get binary from releases page.(not every version have binary file, sorry)

## History
## Setups I am using

* T-Display with BME280, MHZ-19B
* NodeMCU V3 V2 ESP32 with SSD1306, BME280, MH-Z19B
* NodeMCU V3 ESP8266 with BME280, MH-Z19B

## Boards I tested (at least once)

### ESP32

* LilyGO TTGO T-DISPLAY (ESP32 and ST7789 TFT)
* NodeMCU V3 V2 ESP32

### ESP8266

* D-Duino (ESP8266 and ST1306 OLED board)
* WeMos D1mini
* NodeMCU V3

## Version History

### v3.2

* Avoid using delay
* ADD: I2C scan on startup.
* BUGFIX: ESP8266: I2C not working
* DROP: ESP8266: ST7789 is not supported (because of Pin config)

### v3.1

Expand Down
4 changes: 3 additions & 1 deletion include/display_st7789.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include <Arduino.h>

// 使える使えないの判断フラグ ST7789_SUPPORTED -> define.cpp
// このフラグで呼び出される実態が空っぽなのと実装されているものに分かれる。

// ST7789V はセットアップモードをサポートしない
// これは接続されていない場合に初期化しようとしてしまうと何が起きるかわからないため
// void disp_st7789_setup_startup_screen(String ipAddr);


void disp_st7789_wifi_info(String ip, String mDNS);
void disp_st7789_normal_startup_screen(String product_long);
void disp_st7789_wait_for_reconfig_init();
Expand Down
1 change: 1 addition & 0 deletions include/i2c_scan.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void i2c_scan();
3 changes: 3 additions & 0 deletions include/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ void httplog(String msg);
void displog(String msg);
void mdnslog(String msg);
void wifilog(String msg);
void i2clog(String msg);
void stlog(String msg);
void ssdlog(String msg);
void sectionlog(String msg);
4 changes: 3 additions & 1 deletion include/main_normal.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
void init_sensors();
void setup_normal();
void loop_normal();
void loop_normal();
void read_data();
1 change: 1 addition & 0 deletions include/main_normal_mqtt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void setup_normal_mqtt();
6 changes: 6 additions & 0 deletions include/mdns_client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <Arduino.h>

// mdns.h ではないのは、 dunk mdnsのヘッダファイルが mdns.h なため

void mdns_setup();
void mdns_loop();
2 changes: 0 additions & 2 deletions include/wifi.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ void make_sure_wifi_connected();
void start_wifi_access_point();

String get_wifi_ip_addr();

bool start_mdns(String name);
29 changes: 5 additions & 24 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[platformio]
description="EnvBoyX"

[env:esp32dev]
platform = espressif32
Expand Down Expand Up @@ -49,7 +51,6 @@ build_flags =
-DLOAD_GFXFF=1
-DSMOOTH_FONT=1


[env:esp12e]
platform = espressif8266
board = esp12e
Expand All @@ -62,27 +63,7 @@ lib_deps =
wifwaf/MH-Z19@^1.5.2
sodaqmoja/Sodaq_LPS22HB@^1.0.0
ottowinter/ESPAsyncWebServer-esphome@^1.2.7
lorol/LittleFS_esp32@^1.0.0
seeed-studio/Grove - Barometer Sensor BME280@^1.0.2
build_flags =
-Os
-DCORE_DEBUG_LEVEL=2
-DUSER_SETUP_LOADED=1
-DST7789_DRIVER=1
-DTFT_WIDTH=135
-DTFT_HEIGHT=240
-DTFT_MOSI=19
-DTFT_SCLK=18
-DTFT_CS=5
-DTFT_DC=16
-DTFT_RST=23
-DTFT_BL=4
-DSPI_FREQUENCY=40000000
-DLOAD_GLCD=1
-DCGRAM_OFFSET=1
-DLOAD_FONT2=1
-DLOAD_FONT4=1
-DLOAD_FONT6=1
-DLOAD_FONT7=1
-DLOAD_GFXFF=1
-DSMOOTH_FONT=1
build_flags =
-Os
-DCORE_DEBUG_LEVEL=2
3 changes: 0 additions & 3 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ void write_config_file(File f) {

void read_config_file(File f) {
String settingId = f.readStringUntil('\n'); // 使わない
if (settingId != SETTING_ID) {
cfglog("Setting id is not equal. file=" + settingId + " code=" + SETTING_ID);
}
config.ssid = f.readStringUntil('\n');
config.password = f.readStringUntil('\n');
config.mDNS = f.readStringUntil('\n');
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions src/define.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#ifdef ESP32
#define ST7789_SUPPORTED
#endif
7 changes: 5 additions & 2 deletions src/display.cpp → src/display/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ void disp_wait_for_reconfig() {
disp_ssd1306_wait_for_reconfig_init();
}

displog("Wait for reconfigure start");
for (int i = 0; i < MAX_BAR; i++)
{
displog("Wait for reconfigure " + String(i) + " / " + String(MAX_BAR));
if (use_st7789()) {
disp_st7789_wait_for_reconfig_bar(i, MAX_BAR);
}
Expand All @@ -114,6 +114,8 @@ void disp_wait_for_reconfig() {

delay(WAIT_PER_BAR);
}
displog("Wait for reconfigure end");

}

void disp_all_initialize_complete(String ip, String mdns) {
Expand Down Expand Up @@ -178,9 +180,10 @@ void disp_set_power(bool poweron) {
}

void setup_display() {
displog("Setup");
if (use_ssd1306()) {
setup_disp_ssd1306();
} else {
displog("SSD1306 not found.");
}
if (use_st7789()) {
setup_disp_st7789();
Expand Down
File renamed without changes.
6 changes: 5 additions & 1 deletion src/display_ssd1306.cpp → src/display/display_ssd1306.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,5 +278,9 @@ void disp_ssd1306_set_power(bool poweron) {
}

void setup_disp_ssd1306() {
displog("SSD1306: Nothing to do.");
if (has_ssd1306()) {
ssdlog("Initialized.");
} else {
ssdlog("SSD1306 NOT FOUND.");
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef DENVBOY_ST7789_SUPPORT

#include <Arduino.h>

#include "global.h"
Expand Down Expand Up @@ -353,5 +355,7 @@ void setup_disp_st7789()
tft.init();
tft.setRotation(3);
tft.fillScreen(TFT_BLACK);
displog("ST7789: Nothing to do.");
}
stlog("ST7789 Initialized.");
}

#endif
30 changes: 30 additions & 0 deletions src/display/display_st7789_mock.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef ST7789_SUPPORTED

// ST7789 非サポートのボード用。呼ばれることはない。コンパイルを通すためだけのもの

#include <Arduino.h>
#include "global.h"
#include "structs.h"

void disp_st7789_wifi_info(String ip, String mDNS) {}
void disp_st7789_normal_startup_screen(String product_long) {}
void disp_st7789_wait_for_reconfig_init() {}
void disp_st7789_wait_for_reconfig_bar(int now, const int max) {}
void disp_st7789_wifi_starting(int wait_print_row) {}
void disp_st7789_all_initialize_complete(String ip, String mdns) {};
void disp_st7789_sensor_value(disp_values_t new_values, disp_values_t last_values) {};
void disp_st7789_power_off() {};

void disp_st7789_wifi_error() {};

String disp_st7789_set_brightness(int brightness) { return ""; }

/**
* 液晶のON/OFFを設定する
* @param poweron true = ONにする false = offにする
*/
void disp_st7789_set_power(bool poweron) {};

void setup_disp_st7789() {};

#endif
4 changes: 4 additions & 0 deletions src/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ String product_long = product + " Ver." + ver;
// デバイス周りの定数
// --------------------------------------------------------------------
#ifdef ESP32
// ESP32 SDA
extern const int I2C_SDA = 21;
// ESP32 SCL
extern const int I2C_SCL = 22;
#elif defined(ESP8266)
// ESP8266 SDA
extern const int I2C_SDA = 5;
// ESP8266 SCL
extern const int I2C_SCL = 4;
#endif

Expand Down
21 changes: 18 additions & 3 deletions src/i2c.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
#include <Arduino.h>
#include <Wire.h>

#include "log.h"
#include "i2c_scan.h"

bool init_i2c(int sda, int scl) {
bool ret = true;
#ifdef ESP32
return Wire.begin(sda, scl);
i2clog("Initializing ESP32 I2C SDA=" + String(sda) + " SCL=" + String(scl));
ret = Wire.begin(sda, scl);
if (ret) {
i2clog("I2C initialized.");
} else {
i2clog("error initializing I2C");
}
#endif
#ifdef ESP8266
Wire.begin(sda, scl);
return true;
i2clog("Initializing ESP8266 I2C SDA=" + String(sda) + " SCL=" + String(scl));
Wire.begin(sda, scl); // 8266のbeginは返り値がない
i2clog("I2C initialized.");
#endif

i2c_scan();

return ret;
}
45 changes: 45 additions & 0 deletions src/i2c_scan.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <Arduino.h>
#include <Wire.h>

#include "log.h"

void i2c_scan()
{

unsigned long start = millis();

byte error, address;
int nDevices = 0;
for(address = 1; address < 127; address++ )
{

Wire.beginTransmission(address);
error = Wire.endTransmission();

if (error == 0)
{
String msg = "I2C device found at address 0x";
if (address<16)
msg += "0";
msg += String(address,HEX);
msg += " " + String(address);
i2clog(msg);
nDevices++;
}
else if (error==4)
{
String msg = "Unknown error at address 0x";
if (address<16)
msg += "0";
msg += String(address,HEX);
i2clog(msg);
}
}

if (nDevices == 0) {
i2clog("No I2C devices found");
}

i2clog("i2c scan done. time = " + String(millis() - start) + " ms");

}
10 changes: 10 additions & 0 deletions src/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ void wifilog(String msg) {
real_log(msg, "WiFi");
}

void i2clog(String msg) {
real_log(msg, "I2C");
}
void ssdlog(String msg) {
real_log(msg, "SSD1306");
}
void stlog(String msg) {
real_log(msg, "ST7789");
}

void sectionlog(String msg) {
Serial.println("");
real_log(msg, "========");
Expand Down
Loading

0 comments on commit 48da84b

Please sign in to comment.