Skip to content

Commit

Permalink
Support for 8266 esp01m1 + nodemcuv2
Browse files Browse the repository at this point in the history
  • Loading branch information
jekkos committed Apr 6, 2023
1 parent e675489 commit e8c1e2c
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 14 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ also set username and password inside `upload.py`, if you want to use OTA Update
Connect them like this and remember to set them in `include/constants.h` according to your board.
| LCD | ESP32 | TTGO LoRa32 |
| :----------------|:------:|:-----------:|
| GND | GND | GND |
| VCC | 5V | 5V |
| EN | GPIO26 | IO22 |
| IN | GPIO27 | IO23 |
| CLK | GPIO14 | IO02 |
| CLA | GPIO12 | IO15 |
| BUTTON one end | GPIO16 | IO21 |
| BUTTON other end | GND | GND |
| LCD | ESP32 | TTGO LoRa32 | NodeMCUv2 |
| :----------------|:------:|:-----------:|:---------:|
| GND | GND | GND | GND |
| VCC | 5V | 5V | VIN |
| EN (PIN_ENABLE) | GPIO26 | IO22 | GPIO16 D0 |
| IN (PIN_DATA) | GPIO27 | IO23 | GPIO5 D1 |
| CLK (PIN_CLOCK) | GPIO14 | IO02 | GPIO4 D2 |
| CLA (PIN_LATCH) | GPIO12 | IO15 | GPIO0 D3 |
| BUTTON one end | GPIO16 | IO21 | GPIO2 D4 |
| BUTTON other end | GND | GND | GND |
<img src="https://user-images.githubusercontent.com/86414213/205999001-6213fc4f-be2f-4305-a17a-44fdc9349069.jpg" width="60%" />
Expand Down
9 changes: 9 additions & 0 deletions include/constants.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
#pragma once

#ifdef ESP32
#define PIN_ENABLE 26
#define PIN_DATA 27
#define PIN_CLOCK 14
#define PIN_LATCH 12
#define PIN_BUTTON 16
#endif

#ifdef ESP8266
#define PIN_ENABLE 16
#define PIN_DATA 5
#define PIN_CLOCK 4
#define PIN_LATCH 0
#define PIN_BUTTON 2
#endif
// disable if you do not want to have online functionality
#define ENABLE_SERVER

Expand Down
5 changes: 5 additions & 0 deletions include/mode/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ extern int previousHour;
void clockSetup();
void clockLoop();

#ifndef ESP32
bool getLocalTime(struct tm * info, uint32_t ms = 5000);
#endif


#endif
5 changes: 5 additions & 0 deletions include/mode/weather.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

#include "constants.h"
#include <ArduinoJson.h>
#ifdef ESP32
#include <HTTPClient.h>
#endif
#ifdef ESP8266
#include <ESP8266HTTPClient.h>
#endif

#ifdef ENABLE_SERVER

Expand Down
30 changes: 27 additions & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,34 @@
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
lib_deps =
https://github.com/me-no-dev/ESPAsyncWebServer.git
bblanchon/ArduinoJson@^6.19.4
monitor_speed = 115200
; extra_scripts = upload.py
; upload_protocol = custom
; upload_url = http://192.168.178.101/update

[env:esp01_1m]
board = esp01_1m
platform = espressif8266
framework = arduino
build_type = debug
monitor_filters = esp8266_exception_decoder
lib_deps =
https://github.com/me-no-dev/ESPAsyncWebServer.git
https://github.com/vshymanskyy/Preferences.git
bblanchon/ArduinoJson@^6.21.1
monitor_speed = 115200

[env:nodemcuv2]
board = nodemcuv2
platform = espressif8266
framework = arduino
build_type = debug
monitor_filters = esp8266_exception_decoder
lib_deps =
https://github.com/me-no-dev/ESPAsyncWebServer.git
https://github.com/vshymanskyy/Preferences.git
bblanchon/ArduinoJson@^6.21.1
monitor_speed = 115200
; change MCU frequency
board_build.f_cpu = 80000000L
11 changes: 10 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#include <Arduino.h>

#ifdef ESP32
#include <WiFi.h>
#endif

#ifdef ESP8266
#include <ESP8266WiFi.h>
#endif

#include "constants.h"
#include "mode/mode.h"
Expand All @@ -15,7 +22,7 @@ void setup()
Serial.begin(115200);

pinMode(PIN_LATCH, OUTPUT);
pinMode(PIN_CLOCK, OUTPUT);
pinMode(PIN_CLOCK, OUTPUT);
pinMode(PIN_DATA, OUTPUT);
pinMode(PIN_ENABLE, OUTPUT);
pinMode(PIN_BUTTON, INPUT_PULLUP);
Expand All @@ -24,7 +31,9 @@ void setup()
#ifdef ENABLE_SERVER
// wifi
int attempts = 0;
#ifdef ESP32
WiFi.setHostname(WIFI_HOSTNAME);
#endif
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED && attempts < 7)
{
Expand Down
17 changes: 17 additions & 0 deletions src/mode/clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,21 @@ void clockLoop()
delay(60);
}

#ifndef ESP32
bool getLocalTime(struct tm * info, uint32_t ms)
{
uint32_t start = millis();
time_t now;
while((millis()-start) <= ms) {
time(&now);
localtime_r(&now, info);
if(info->tm_year > (2016 - 1900)){
return true;
}
delay(10);
}
return false;
}
#endif

#endif

0 comments on commit e8c1e2c

Please sign in to comment.