Boot-Problem: LilyGO TTGO-S3 Touch
-
Hello,
depending on the place I am, I boot by- PC-USB
- Li-Ion-Accu
- 230V-Power supply for USB devices
- USB-Powerbank
The example "HotHead" works in all 4 cases.
My temperature sketch only runs on PC-USB-connector. I used the setup constellation from "HotHead":
#define PIN_POWER_ON 15 // LCD and battery Power Enable
#define PIN_LCD_BL 38 // BackLight enable pin (see Dimming.txt)void setup() {
pinMode(PIN_POWER_ON, OUTPUT); // triggers the LCD backlight
pinMode(PIN_LCD_BL, OUTPUT); // BackLight enable pin
delay(100);
digitalWrite(PIN_POWER_ON, HIGH);
digitalWrite(PIN_LCD_BL, HIGH);
...
} -
HotHead here!
So, the HotHead sketch works on battery, yes?
Could you post your temperature code here so I could run it on my LilyGO T-Display S3 ?
-Terry -
Hello teastain2,
Board: "esp32 by Espressif Systems Version 2.0.9 INSTALLED"
The code is too long to submit. I deleted uncommented lines & the loop!
/*
// Default color definitions
#define TFT_BLACK 0x0000 // 0, 0, 0
#define TFT_NAVY 0x000F // 0, 0, 128
#define TFT_DARKGREEN 0x03E0 // 0, 180, 0
#define TFT_DARKCYAN 0x03EF // 0, 128, 128
#define TFT_MAROON 0x7800 // 128, 0, 0
#define TFT_PURPLE 0x780F // 128, 0, 128
#define TFT_OLIVE 0x7BE0 // 128, 128, 0
#define TFT_LIGHTGREY 0xD69A // 211, 211, 211
#define TFT_DARKGREY 0x7BEF // 128, 128, 128
#define TFT_BLUE 0x001F // 0, 0, 255
#define TFT_GREEN 0x07E0 // 0, 255, 0
#define TFT_CYAN 0x07FF // 0, 255, 255
#define TFT_RED 0xF800 // 255, 0, 0
#define TFT_MAGENTA 0xF81F // 255, 0, 255
#define TFT_YELLOW 0xFFE0 // 255, 255, 0
#define TFT_WHITE 0xFFFF // 255, 255, 255
#define TFT_ORANGE 0xFDA0 // 255, 180, 0
#define TFT_GREENYELLOW 0xB7E0 // 180, 255, 0
#define TFT_PINK 0xFE19 // 255, 192, 203 //Lighter pink, was 0xFC9F
#define TFT_BROWN 0x9A60 // 150, 75, 0
#define TFT_GOLD 0xFEA0 // 255, 215, 0
#define TFT_SILVER 0xC618 // 192, 192, 192
#define TFT_SKYBLUE 0x867D // 135, 206, 235
#define TFT_VIOLET 0x915C // 180, 46, 226
*/// TTGO S3 R8 mit OnBoard ST7789 1,19inch LCD 170x320 mit MCP9808- / KY-001- / AHT10- / BME680- / AHT25- / DS18B20-Temperatursensor-Modul
//************************************
//* Achtung:
//* Die Datei "User_Setup.h" aus "TFT_eSPI" wurde wie folgt geändert:
//* #define ST7789_DRIVER// Werkzeuge/Boardverwalter...: "esp32 by Espressif Systems Version 2.0.9 INSTALLED"
// Näheres siehe "ESP32-error 'rtc_gpio_desc' was not declared in this scope.doc"
//************************************
/*- Angegeben sind nur die Änderungen zur Standardkonfiguration, Näheres steht im Dokument (s. u.):
Setting Value Board ESP32S3 Dev Module USB Firmware MSC On Boot Disabled Flash Mode QIO 80MHz Flash Size 16MB (128Mb) Events Run On Core 1 Partition Scheme Huge APP (3MB No OTA/1MB SPIFFS) Erase All Flash Before... Disabled USB Mode Hardware CDC and JTAG Arduino Runs On Core 1 JTAG Adapter Integrated USB JTAG CPU Frequency 240MHz (WiFi) PSRAM OPI PSRAM USB CDC On Boot Enabled Upload Mode UART0 / Hardware CDC Upload Speed 921600 Core Debug Level None USB DFU On Boot Enabled (Requires USB-OTG Mode) */
// Achtung: Auf die Board-Parameter achten -> "ESP32-TTGO S3 ESP-32, ST7789 LCD 170x320 anschließen & Boardparameter.doc"!
// Klappt: Werte für Testversion:
// "ESP32S3 Dev Module": 352493 Bytes (11%) des Programm-RAMs. Globale Variablen: 22040 Bytes (6%) des dynamischen Speichers//******* Initialisierungen ******
// Für den MCP9808
#include <Wire.h>
#include "Adafruit_MCP9808.h" // Adafruit_MCP9808_Library und Adafruit_BusIO-1.2.0
// Create the MCP9808 temperature sensor object
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();// Für das Display
#define LeftButton 0
#define RightButton 14
#define PIN_POWER_ON 15
#define PIN_LCD_BackLight 38
#include <TFT_eSPI.h> // TFT_eSPI-TTGO-S3
#include <SPI.h>
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h// Für den KY-001
#include <OneWire.h> // OneWire-master-2.3.7
#include <DallasTemperature.h> // Arduino-Temperature-Control-Library-master
// Hier wird der Eingangspin deklariert, an den das Sensormodul angeschlossen wird
#define KY001_Signal_PIN 2
// Bibliotheken werden konfiguriert
OneWire oneWire(2); // An Pin 2 vom TTGO
DallasTemperature sensors(&oneWire);// Für den AHT10
#include <AHTxx.h> // "AHTxx-main" aus "AHTxx-main (ASAIR).zip"
AHTxx aht10(AHT10_ADDRESS_X39, AHT1x_SENSOR); //sensor address, sensor type// Für den BME680
#include <Adafruit_Sensor.h> // Adafruit_Sensor-master
#include "Adafruit_BME680.h" // Adafruit_BME680-master#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME680 bme; // I2C 0x77// Für den AHT25
// #include <AHTxx.h> // "AHTxx-main" aus "AHTxx-main (ASAIR).zip", siehe "Für den AHT10"
AHTxx aht25(AHTXX_ADDRESS_X38, AHT2x_SENSOR); //sensor address, sensor type// Für den DS18B20, entspricht dem KY-001 und dessen Libraries
// Hier wird kein Eingangspin deklariert, die Sensoren werden per Software abgefragt.// Für den BMP280
#include <Arduino.h>
#include <Wire.h>
#include <BMx280I2C.h> // BMx280MI//create a BMx280I2C object using the I2C interface with I2C Address 0x76
BMx280I2C BMP280(0x76);// Für den INA226
// #include <Wire.h> // Bereits eingebunden// Für die Batterie-Anzeige:
#define BATT_X 0 // X coordinate for battery message/indicator
#define BATT_Y 208 // Y coordinate for battery message/indicator
#define BATT_W 90 // width of battery indicator
#define BATT_H 19 // height of battery indicator
#define BattV_LOW 3.3 // voltage considered to be low battery
#define BATTV_MAX 4.1 // maximum voltage of battery
#define BATTV_MIN 3.2 // what we regard as an empty battery
#define BATT_ALERT_THRESHOLD 2 // how many times we read low battery before sending alert
#define BATT_INTERVAL 1 // No. times through loop between battery readings
#define SummerPin 13 // Pin für Summer
#define DarkRED 0xA800 // Rot 810nm
#define BattV_Ok_color TFT_CYAN // BatterieSpannung Ok
#define BattV_75_color TFT_GREEN // BatterieSpannung unter 75%
#define BattV_50_color TFT_YELLOW // BatterieSpannung unter 50%
#define BattV_40_color TFT_ORANGE // BatterieSpannung unter 40%
#define BattV_30_color TFT_RED // BatterieSpannung unter 30%
#define BattV_20_color DarkRED // BatterieSpannung unter 20%
#define Temperatur_color TFT_ORANGE //
#define Feuchte_color TFT_GREENYELLOW
#define LuftDruck_color TFT_SKYBLUE //String Version = "09g";
int dx1 = 58; // x-Position für die ":"-Ausgabe auf Display
int dx2 = 70; // x-Position für die Datenausgabe auf Display
int dx3 = 140; // x-Position für die Einheitenausgabe auf Display
int dx4 = 105; // x-Position für die Messgenauigkeitsausgabe auf Display
int StartPosY = 16; // Startzeile für die Datenausgabe auf Display
int FontNr = 2; // Nr. des verwendeten Fonts
int TextSize = 1; // Größe des verwendeten Fonts
int sensorCount; // Anzahl der DS18B20- / KY-001-Sensoren
int Text2Hoehe; // TextHoehe des Fonts 2
uint8_t BattV_Prozent; // battery level, in percentage
uint8_t LowBattCounter; // no. times we've seen a low battery
bool ButtonStatus; // Flag, to show the right-/left-Botton Status
bool Display_On; // Flag, Display is on
bool Testversion=false;// Testversion hat viele Ausgaben auf Ser. Monitor
float BatteryVolts; // battery-Spannung in Volt
float BatteryAmps; // battery level, in Ampere
float TTGO_Volts; // TTGO-Spannung in Volt, ist wegen des StromShunts kleiner als BatteryVolts
float rShunt = 0.1; // Shunt Widerstand festlegen, hier 0.1 Ohm
float Tmin = 200; // Extremwertspeicher, 200: Viel zu hohen Wert vorgeben
float Tmax =-200; // Extremwertspeicher
float rFmin = 100; // Extremwertspeicher, 100: Viel zu hohen Wert vorgeben
float rFmax = 0; // Extremwertspeicher
long StartMillis, Millis1, Millis2, Millis3, Millis4, Millis5, Millis6; // Für Zeitmesungen
long Millis; // Für Werteschleife
long MessWerteZaehler = 1;
const int INA226_ADDR = 0x40; // A0 und A1 auf GND -> Adresse 40 Hex; auf Seite 18 im Datenblattvoid setup() {
Serial.begin(9600);
Wire.begin(43, 44); // Ohne diese Festlegung funktioniert der I2C-Bus nicht!
delay(200); // Wichtig, damit nachfolgender Text ausgegeben wird.while (!Serial); //waits for serial terminal to be open, necessary in newer arduino boards.
Serial.println("\nTemperaturmessung mit MCP9808, KY-001, AHT10, BME680, AHT25, DS18B20 und TTGO S3.");
Serial.print("Version: "); Serial.println(Version);// Display & Button werden initialisiert
Display_On = true;
pinMode(PIN_POWER_ON, OUTPUT); // enables battery power and LCD backlight
pinMode(PIN_LCD_BackLight, OUTPUT); // controls the LCD backlight
pinMode(LeftButton, INPUT); // Left button pulled up, push = 0
pinMode(RightButton, INPUT); // Right button pulled up, push = 0
digitalWrite(PIN_POWER_ON, HIGH); // Sonst funktioniert Betrieb über Batterie nicht!
digitalWrite(PIN_LCD_BackLight, Display_On);tft.init();
tft.setRotation(0); // Hochformat
tft.fillScreen(TFT_BLACK); // Display löschen
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.setCursor( 0, 0, 1); // Font = 1
tft.setTextSize(2); tft.println("Wetterdaten");
tft.setTextSize(1); tft.setTextFont(FontNr);
Text2Hoehe = tft.fontHeight(FontNr); // FontNr = 2 --> Text2Hoehe = 16, ist aber zu viel!
Text2Hoehe = 13;tft.setTextColor(TFT_GREENYELLOW, TFT_BLACK);
tft.setTextSize(1);
tft.setCursor(0,310, 1); tft.println("Right Button: Display on/off");
tft.setCursor(0, 20, 1); tft.println("Initialisierung:");
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.setCursor(0, 30, 1); tft.println("MCP9808:");// Sensor MCP9808 wird initialisiert
// Make sure the sensor is found, you can also pass in a different i2c
// address with tempsensor.begin(0x19) for example, also can be left in blank for default address use
// Also there is a table with all addres possible for this sensor, you can connect multiple sensors
// to the same i2c bus, just configure each sensor with a different address and define multiple objects for that
// A2 A1 A0 address
// 0 0 0 0x18 this is the default address
// 0 0 1 0x19
// 0 1 0 0x1A
// 0 1 1 0x1B
// 1 0 0 0x1C
// 1 0 1 0x1D
// 1 1 0 0x1E
// 1 1 1 0x1F
if (!tempsensor.begin(0x18)) {
//Serial.println("Couldn't find MCP9808! Check wiring & address!");
tft.setTextColor(TFT_RED, TFT_BLACK);
tft.setCursor(50, 30, 1); tft.println("Error");
tft.setTextColor(TFT_GREEN, TFT_BLACK);
//while (1);
} else {
tft.setCursor(50, 30, 1); tft.println("Ok");
}
// Serial.println("Found MCP9808!");
tempsensor.setResolution(3); // sets the resolution mode of reading, the modes are defined in the table bellow:
// Mode Resolution SampleTime
// 0 0.5°C 30 ms
// 1 0.25°C 65 ms
// 2 0.125°C 130 ms
// 3 0.0625°C 250 ms// Sensor KY-001 wird initialisiert
sensors.begin(); //Starten der Kommunikation mit dem Sensor
//sensorCount = sensors.getDS18Count(); //Lesen der Anzahl der angeschlossenen Temperatursensoren.
sensorCount = sensors.getDeviceCount(); //Lesen der Anzahl der angeschlossenen Temperatursensoren.// Sensor AHT10 wird initialisiert
tft.setCursor(0, 40, 1); tft.println("AHT10 :");
if (aht10.begin() != true) {
//Serial.println(F("AHT10 not connected or fail to load calibration coefficient!")); //(F()) save string to flash & keeps dynamic memory free
tft.setTextColor(TFT_RED, TFT_BLACK);
tft.setCursor(50, 40, 1); tft.println("Error");
tft.setTextColor(TFT_GREEN, TFT_BLACK);
delay(1000);
} else {
//Serial.println(F("AHT10 OK"));
tft.setCursor(50, 40, 1); tft.println("Ok");
}// Für den BME680
tft.setCursor(0, 50, 1); tft.println("BME680 :");
//Serial.print(F("BME680 test: "));
if (!bme.begin()) {
//Serial.println("Could not find a valid BME680 sensor, check wiring & address!");
tft.setTextColor(TFT_RED, TFT_BLACK);
tft.setCursor(50, 50, 1); tft.println("Error");
tft.setTextColor(TFT_GREEN, TFT_BLACK);
//while (1);
} else {
//Serial.println(F("Found!"));
tft.setCursor(50, 50, 1); tft.println("Ok");
}
// Set up oversampling and filter initialization
bme.setTemperatureOversampling(BME680_OS_8X);
bme.setHumidityOversampling(BME680_OS_2X);
bme.setPressureOversampling(BME680_OS_4X);
bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
bme.setGasHeater(320, 150); // 320*C for 150 ms// Sensor AHT25 wird initialisiert
tft.setCursor(0, 60, 1); tft.println("AHT25 :");
if (aht25.begin() != true) {
//Serial.println(F("AHT2x not connected or fail to load calibration coefficient!")); //(F()) save string to flash & keeps dynamic memory free
tft.setTextColor(TFT_RED, TFT_BLACK);
tft.setCursor(50, 60, 1); tft.println("Error");
tft.setTextColor(TFT_GREEN, TFT_BLACK);
delay(1000);
} else {
//Serial.println(F("AHT25 OK"));
tft.setCursor(50, 60, 1); tft.println("Ok");
}// Für den BMP280
tft.setCursor(0, 70, 1); tft.println("BMP280 :");
if (!BMP280.begin()) {
//Serial.println("'begin()' failed. Check your BMP280 Interface and I2C Address.");
tft.setTextColor(TFT_RED, TFT_BLACK);
tft.setCursor(50, 70, 1); tft.println("Error");
tft.setTextColor(TFT_GREEN, TFT_BLACK);
//while (1);
} else {
tft.setCursor(50, 70, 1); tft.println("Ok");
//if (BMP280.isBME280()) Serial.println("Sensor is a BME280");
//else Serial.println("Sensor is a BMP280");
tft.setCursor(10, 80, 1);
if (BMP280.isBME280()) tft.println("Sensor is a BME280");
else tft.println("Sensor is a BMP280");
}//reset sensor to default parameters.
BMP280.resetToDefaults();//by default sensing is disabled and must be enabled by setting a non-zero
//oversampling setting.
//set an oversampling setting for pressure and temperature measurements.
BMP280.writeOversamplingPressure(BMx280MI::OSRS_P_x16);
BMP280.writeOversamplingTemperature(BMx280MI::OSRS_T_x16);
//if sensor is a BME280, set an oversampling setting for humidity measurements.
if (BMP280.isBME280()) BMP280.writeOversamplingHumidity(BMx280MI::OSRS_H_x16);// INA226 wird initialisiert
// Configuration Register Standard Einstellung 0x4127, hier aber 16 Werte Mitteln > 0x4427
// 0x4427 = 100 010 000 100 111
// Bits 0- 2: Operating Mode: 111 = Shunt and Bus, Continuous
// Bits 3– 5: Shunt Voltage Conversion Time: 100 = 1.1 ms
// Bits 6– 8: Bus Voltage Conversion Time: 000 = 140 μs
// Bits 9–11: Averaging Mode: 010 = 16 AVERAGES
// Bits 12–14: Festgelegt: 100
writeRegister(0x00, 0x4427); // 1.1ms Volt und Strom A/D-Wandlung, Shunt und VBus continoustft.setTextColor(TFT_RED, TFT_BLACK);
tft.setCursor(40,100, 1); tft.println("Reading Sensors ...");
delay(3000); // Anzeige der Initialisierung abwarten
//BatteryVolts = 3.4; // Für Testzwecke
} // Ende setup// ---------------------------------------------------------------------------------------
// Funktion für den INA226
static void writeRegister(byte reg, word value) {
Wire.beginTransmission(INA226_ADDR);
Wire.write(reg);
Wire.write((value >> & 0xFF);
Wire.write(value & 0xFF);
Wire.endTransmission();
}// Funktion für den INA226
static word readRegister(byte reg) {
word res = 0x0000;
Wire.beginTransmission(INA226_ADDR);
Wire.write(reg);
if (Wire.endTransmission() == 0) {
if (Wire.requestFrom(INA226_ADDR, 2) >= 2) {
res = Wire.read() * 256;
res += Wire.read();
}
}
return res;
}// ---------------------------------------------------------------------------------------
void printBatteryLevel() {
//Serial.println("printBatteryLevel()!!!!!!!!!!!!!");
tft.setTextFont(FontNr);
tft.setTextSize(1);
tft.setCursor(BATT_X, BATT_Y);
tft.fillRect(BATT_X, BATT_Y, TFT_WIDTH, BATT_H, TFT_BLACK); // clear "Bar"
if(BatteryVolts > BattV_LOW) {
// Draw outline box
tft.drawRect(BATT_X, BATT_Y, BATT_W + 2, BATT_H, TFT_WHITE);
// Draw the power level bar
int Y2 = (BattV_Prozent * BATT_W)/100;
switch (BattV_Prozent) {
case 0 ... 19: tft.fillRect(BATT_X + 1, BATT_Y + 1, Y2, BATT_H-2, BattV_20_color); break;
case 20 ... 29: tft.fillRect(BATT_X + 1, BATT_Y + 1, Y2, BATT_H-2, BattV_30_color); break;
case 30 ... 39: tft.fillRect(BATT_X + 1, BATT_Y + 1, Y2, BATT_H-2, BattV_40_color); break;
case 40 ... 49: tft.fillRect(BATT_X + 1, BATT_Y + 1, Y2, BATT_H-2, BattV_50_color); break;
case 50 ... 74: tft.fillRect(BATT_X + 1, BATT_Y + 1, Y2, BATT_H-2, BattV_75_color); break;
case 75 ... 100: tft.fillRect(BATT_X + 1, BATT_Y + 1, Y2, BATT_H-2, BattV_Ok_color); break;
default: tft.fillRect(BATT_X + 1, BATT_Y + 1, Y2, BATT_H-2, BattV_Ok_color); break;
}char buf[4]; sprintf(buf, "%i%%", BattV_Prozent); tft.setTextColor(BattV_Ok_color); if(BattV_Prozent < 75) tft.setTextColor(BattV_75_color); if(BattV_Prozent < 50) tft.setTextColor(BattV_50_color); if(BattV_Prozent < 40) tft.setTextColor(BattV_40_color); if(BattV_Prozent < 30) tft.setTextColor(BattV_30_color); if(BattV_Prozent < 20) tft.setTextColor(BattV_20_color); tft.setCursor(BATT_W + 20, BATT_Y - 0, 1); // Font 1 tft.print(buf); // "BattV_Prozent" rechts vom "Bar" ausgeben LowBattCounter = 0; // Reset tft.setTextColor(TFT_MAGENTA); tft.setCursor(3, BATT_Y + 6, 1); tft.print(F("Battery-Level")); // Font 1
// } else if(battv == 0) {
// /** Shows 0 when charging /
// low_batt_counter = 0; // reset
// batt_warning_sent = false; // reset
// tft.drawBitmap(BATT_X, BATT_Y, charge_symbol, CHARGE_SYMBOL_WIDTH, CHARGE_SYMBOL_HEIGHT, 1);
} else { / LOW BATTERY ! /
Serial.println("** LOW BATTERY ! ");
// we don't want to send a warning every time we arrive here because the reading could
// be transient. So we insist on getting BATT_ALERT_THRESHOLD number of consecutive
// warnings before sending an alert.
LowBattCounter++;
Serial.print("LowBattCount.2: "); Serial.println(LowBattCounter);
Serial.print("BattAlertThr.2: "); Serial.println(BATT_ALERT_THRESHOLD);
if(LowBattCounter >= BATT_ALERT_THRESHOLD) {
Serial.println("send an alert!***************");
// send an alert
tone(SummerPin, 3000); delay(500); noTone(SummerPin); // 500ms 3000Hz-Ton
LowBattCounter = 0;
}
// tft.setCursor(5, BATT_Y - 2, 2); tft.print(F("Low Battery"));
// tft.setCursor(3, BATT_Y + 3, 1); tft.print(F("Low Battery")); // Font 1
tft.setTextColor(TFT_RED, TFT_BLACK);
tft.setCursor(3, BATT_Y + 6, 1); tft.print(F("Low Battery")); // Font 1
// Draw outline box
tft.drawRect(BATT_X, BATT_Y, BATT_W + 2, BATT_H, TFT_WHITE);
}
tft.setCursor(BATT_W + 20, BATT_Y +10, 1); // Font 1
tft.print(BatteryVolts, 2); tft.print("V"); // "BatteryVolts" rechts vom "Bar" ausgeben
} // Ende printBatteryLevel() -
@dirk Well, Dirk that sketch has 'a lot of moving parts'!
My troubleshooting approach is run my HotHead sketch and see if it will run on battery.
If 'yes' then we must assume that one of your many sensors are drawing too much current and lowering the Vinput.
Can you measure the battery voltage with a meter as you unplug the USB and switch to battery. (This may require a push of the little black Reset button to restart it.
-Terry