Ich möchte auf einem ESP32-2432S028 den aktuellen Bitcoincurs anzeigen, dazu habe ich folgenden code erstellt.
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <TFT_eSPI.h> // Bibliothek für das ESP32 SYD Display
// WLAN-Zugangsdaten
const char* ssid = "TP-LINK_F4E7";
const char* password = "123AFCAFC1";
// API-URL
const char* bitcoinApiUrl = "https://api.coindesk.com/v1/bpi/currentprice/BTC.json";
// TFT-Display initialisieren
TFT_eSPI tft = TFT_eSPI();
void setup() {
Serial.begin(115200);
// Display initialisieren
tft.init();
tft.setRotation(1); // Je nach Ausrichtung des Displays
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.setTextSize(2);
// WLAN verbinden
tft.setCursor(0, 0);
tft.println("Verbinde mit WLAN...");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("WLAN-Verbindung wird hergestellt...");
tft.print(".");
}
tft.println("\nWLAN verbunden!");
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin(bitcoinApiUrl);
int httpResponseCode = http.GET();
if (httpResponseCode == 200) { // Erfolgreiche Anfrage
String payload = http.getString();
Serial.println(payload);
// JSON-Daten parsen
DynamicJsonDocument doc(2048);
DeserializationError error = deserializeJson(doc, payload);
if (!error) {
// Bitcoin-Kurs in USD abrufen
float bitcoinPrice = doc["bpi"]["USD"]["rate_float"];
Serial.println("Bitcoin-Kurs in USD: " + String(bitcoinPrice));
// Kurs auf dem Display anzeigen
tft.fillScreen(TFT_GREEN);
tft.setCursor(0, 0);
tft.println("BTC/USD:");
tft.setTextSize(3);
tft.println(String(bitcoinPrice, 2));
} else {
Serial.println("JSON-Parsing-Fehler");
}
} else {
Serial.println("HTTP-Fehler: " + String(httpResponseCode));
}
http.end();
} else {
Serial.println("WLAN getrennt!");
}
delay(60000); // Aktualisierung alle 60 Sekunden
}
Der Kurs wird ordentlich abgefragt. Leider bleibt das display schwarz. Welche Pinbelegung muss ich in der User_Setup.h angeben?