Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sonoff TH10/16 #476

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions platformio.ini
Expand Up @@ -68,6 +68,7 @@ monitor_filters = esp32_exception_decoder, time
[common:esp8266]
platform = espressif8266
lib_ignore = WiFiNINA, Adafruit TinyUSB Library
board_build.filesystem = littlefs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am curious - why is this flag required for the sonoff_th but not for the huzzah ESP8266?

Copy link
Contributor Author

@tyeth tyeth Sep 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe it is required for both. I couldn't push the filesystem image (platformIO) for the ESP8266 huzzah without this, I kept forgetting as it was part of my stash with secrets data file. Maybe I've got something configured wrong, but I think it was defaulting to spiffs rather than littlefs. I did the initial sonoff work just before the huzzah arrived later in the day and I was then able to get the secrets across and see debug with both sonoff + huzzah and moved the line to the common:esp8266 definition instead of the sonoff one.
I'll try to check on a fresh machine at some point soon.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't push the filesystem image (platformIO) for the ESP8266 huzzah without this, I kept forgetting as it was part of my stash with secrets data file. Maybe I've got something configured wrong, but I think it was defaulting to spiffs rather than littlefs

Interesting! Could you try in the near the board define, USE_LITTLEFS too?


; ESP32-x Boards ;

Expand Down Expand Up @@ -181,6 +182,13 @@ extends=common:esp8266
board = huzzah
build_flags = -DARDUINO_ESP8266_ADAFRUIT_HUZZAH

; Sonoff TH16 ESP8266
; https://wiki.iteadstudio.com/images/3/39/Sonoff_TH10A%2816A%29_schmatic.pdf
[env:sonoff_th]
extends=common:esp8266
board = sonoff_th
build_flags = -DESP8266_SONOFF_TH

; SAMD51 Boards ;

; Adafruit PyPortal M4
Expand Down
5 changes: 5 additions & 0 deletions src/Wippersnapper_Boards.h
Expand Up @@ -132,6 +132,11 @@
#define USE_LITTLEFS
#define USE_STATUS_LED
#define STATUS_LED_PIN 0
#elif defined(ARDUINO_ESP8266_SONOFF_TH)
#define BOARD_ID "sonoff-th"
#define USE_LITTLEFS
#define USE_STATUS_LED
#define STATUS_LED_PIN 13 // pull down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this pin pulled down by default?

#elif defined(ARDUINO_FEATHER_ESP32)
#define BOARD_ID "feather-esp32"
#define USE_LITTLEFS
Expand Down
6 changes: 3 additions & 3 deletions src/components/digitalIO/Wippersnapper_DigitalGPIO.cpp
Expand Up @@ -82,7 +82,7 @@ void Wippersnapper_DigitalGPIO::initDigitalPin(
#endif

// Initialize LOW
#if defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH)
#if defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH) || defined(ESP8266_SONOFF_TH)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This applies to every ifdef like this, would we want to detect the ESP8266 arch instead of individual boards? Both boards we're using here (and elsewhere) seem to take the same pinout/pd resistor

// The Adafruit Feather ESP8266's built-in LED is reverse wired so setting
// the pin LOW will turn the LED on.
digitalWrite(STATUS_LED_PIN, !0);
Expand Down Expand Up @@ -213,10 +213,10 @@ void Wippersnapper_DigitalGPIO::digitalWriteSvc(uint8_t pinName, int pinValue) {
#endif

// Write to the GPIO pin
#if defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH)
#if defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH) || defined(ESP8266_SONOFF_TH)
// The Adafruit Feather ESP8266's built-in LED is reverse wired so setting the
// pin LOW will turn the LED on.
if (pinName == 0)
if (pinName == STATUS_LED_PIN)
digitalWrite(pinName, !pinValue);
else
digitalWrite(pinName, pinValue);
Expand Down
6 changes: 3 additions & 3 deletions src/components/statusLED/Wippersnapper_StatusLED.cpp
Expand Up @@ -78,7 +78,7 @@ void initStatusLED() {
pinMode(STATUS_LED_PIN, OUTPUT);

// Turn off LED initially
#if defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH)
#if defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH) || defined(ESP8266_SONOFF_TH)
analogWrite(STATUS_LED_PIN, 255);
#elif defined(ARDUINO_ARCH_ESP32)
WS._pwmComponent->attach(STATUS_LED_PIN, LEDC_BASE_FREQ, LEDC_TIMER_12_BIT);
Expand Down Expand Up @@ -305,7 +305,7 @@ void statusLEDFade(uint32_t color, int numFades = 3) {
}

// Turn status LED off
#if not defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH)
#if not(defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH) && defined(ESP8266_SONOFF_TH))
setStatusLEDColor(BLACK);
#else
// The Adafruit Feather ESP8266's built-in LED is reverse wired
Expand Down Expand Up @@ -399,7 +399,7 @@ void statusLEDBlink(ws_led_status_t statusState) {
while (blinkNum > 0) {
setStatusLEDColor(ledColor);
delay(100);
#if defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH)
#if defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH) || defined(ESP8266_SONOFF_TH)
// The Adafruit Feather ESP8266's built-in LED is reverse wired
setStatusLEDColor(BLACK ^ 1);
#else
Expand Down
2 changes: 1 addition & 1 deletion src/provisioning/littlefs/WipperSnapper_LittleFS.cpp
Expand Up @@ -13,7 +13,7 @@
*
*/
#if defined(ARDUINO_FEATHER_ESP32) || \
defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH) || \
defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH) || defined(ESP8266_SONOFF_TH) || \
defined(ARDUINO_ADAFRUIT_FEATHER_ESP32_V2) || \
defined(ARDUINO_ADAFRUIT_QTPY_ESP32_PICO) || \
defined(ARDUINO_ADAFRUIT_QTPY_ESP32C3)
Expand Down