/*
Inverter Stats Demo
-------------------
This demo shows how to display some example inverter stats on the TFT screen:
- Battery State of Charge (SoC)
- Power (W)
- Action (e.g., "Charging", "Discharging")
- Grid Power (W)
It uses the TFT_eSPI library for the display and Adafruit_FT6206 for the
capacitive touchscreen (though the touchscreen isn't actively used here for input).
Connections & Libraries:
- TFT_eSPI should be configured in your "User_Setup.h" (or the default TFT_eSPI config).
- FT6206 uses hardware I2C.
Note:
- Replace the random-value placeholders with real data from your inverter system.
*/
#include <TFT_eSPI.h> // TFT display library
#include <SPI.h> // For the TFT display
#include <Wire.h> // For FT6206 (capacitive touch)
#include <Adafruit_FT6206.h>
// Create the touchscreen object (hardware I2C SCL/SDA)
Adafruit_FT6206 ctp = Adafruit_FT6206();
// Create the display object (TFT_eSPI)
TFT_eSPI tft = TFT_eSPI(); // Default pins based on your setup in User_Setup.h
// Just for demonstration: dummy variables to store inverter stats
int batterySoC = 0; // Battery State of Charge (0-100%)
float inverterPower = 0.0f; // Current inverter power in Watts
String action = "Idle"; // Could be "Charging", "Discharging", etc.
int gridPower = 0; // Grid Power in Watts
unsigned long lastUpdate = 0; // Timer to update stats periodically
const unsigned long updateInterval = 2000; // 2-second update interval
// A small helper to randomly pick between two strings
String pickAction() {
if (random(0, 2) == 0) {
return "Charging";
} else {
return "Discharging";
}
}
void setup() {
Serial.begin(115200);
Serial.println("Inverter Stats Demo");
// Initialize the TFT display
tft.init();
tft.setRotation(1); // Adjust as needed for your screen orientation
tft.fillScreen(TFT_BLACK);
// Initialize the capacitive touchscreen (optional if you want to use touch)
if (!ctp.begin(40)) {
Serial.println("Couldn't start FT6206 touchscreen controller.");
// Not critical if we don't care about touch in this demo
} else {
Serial.println("Capacitive touchscreen started.");
}
// Draw a title bar or some header
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.setTextSize(2);
tft.setCursor(10, 10);
tft.println("Inverter Stats");
// Draw some static labels (just once)
tft.setTextSize(2);
tft.setCursor(10, 50);
tft.print("Battery SoC: ");
tft.setCursor(10, 80);
tft.print("Inverter Pwr:");
tft.setCursor(10, 110);
tft.print("Action: ");
tft.setCursor(10, 140);
tft.print("Grid Power: ");
// Seed random numbers (for demo)
randomSeed(analogRead(0));
}
void loop() {
// If you were using the touchscreen, you could check if (ctp.touched()) and handle input
unsigned long currentMillis = millis();
// Update the stats every 'updateInterval' milliseconds
if (currentMillis - lastUpdate >= updateInterval) {
lastUpdate = currentMillis;
// Replace these with real data from your inverter
batterySoC = random(0, 101); // 0-100%
inverterPower = random(0, 5001); // 0-5000 W
action = pickAction(); // "Charging" or "Discharging"
gridPower = random(0, 3001); // 0-3000 W
// Now update the display
displayStats();
}
// Other code can go here
}
// Function to update stats on screen
void displayStats() {
// We'll just overwrite old values by printing with background color = black
// Battery SoC
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.setTextSize(2);
tft.setCursor(150, 50);
tft.print(" "); // Clear old data by printing some spaces
tft.setCursor(150, 50);
tft.printf("%3d%%", batterySoC);
// Inverter Power
tft.setCursor(150, 80);
tft.print(" ");
tft.setCursor(150, 80);
tft.printf("%.0f W", inverterPower);
// Action
tft.setCursor(150, 110);
tft.print(" ");
tft.setCursor(150, 110);
tft.print(action);
// Grid Power
tft.setCursor(150, 140);
tft.print(" ");
tft.setCursor(150, 140);
tft.printf("%d W", gridPower);
}