Ich wollte auf einen nodemcu ein LCD-Display betreiben. Was auf dem Display steht wollte ich per Web eingeben. Hat jemand da eine idee wie das geht oder sogar ein beispiel ? Dankeschön
So in etwa, ohne Garantie (ungetestet)
1 | #include <Arduino.h> |
2 | #include <Wire.h> |
3 | #include <Adafruit_GFX.h> |
4 | #include <Adafruit_SSD1306.h> |
5 | |
6 | const char HTTP_HEADER[] PROGMEM = "<!DOCTYPE html><html lang=\"en\"><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no\"/><title>{v}</title>"; |
7 | const char HTTP_HEADER_END[] PROGMEM = "</head><body><div style='text-align:left;display:inline-block;min-width:260px;'>"; |
8 | const char HTTP_BODY_END[] PROGMEM = "</div></body></html>"; |
9 | |
10 | Adafruit_SSD1306 display(128, 64, &Wire, -1); |
11 | AsyncWebServer server(80); |
12 | |
13 | void setup() { |
14 | Serial.begin(115200); |
15 | |
16 | if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { // Address 0x3D for 128x64 |
17 | Serial.println(F("SSD1306 allocation failed")); |
18 | for(;;); // Don't proceed, loop forever |
19 | }
|
20 | display.display(); |
21 | delay(2000); // Pause for 2 seconds |
22 | |
23 | // Clear the buffer
|
24 | display.clearDisplay(); |
25 | |
26 | WiFi.begin("DeineSSID", "DeinPasswort"); |
27 | while (WiFi.status() != WL_CONNECTED) { |
28 | delay(500); |
29 | Serial.print("."); |
30 | }
|
31 | Serial.println("WiFi connected"); |
32 | Serial.println("IP address: "); |
33 | Serial.println(WiFi.localIP()); |
34 | |
35 | server.on("/", HTTP_GET, handleRoot); |
36 | server.on("/lcd", HTTP_POST, handlepostLCD); |
37 | }
|
38 | |
39 | void loop(){ |
40 | |
41 | }
|
42 | |
43 | void handleRoot(AsyncWebServerRequest *request){ |
44 | uint8_t i,j; |
45 | float money = 0.0; |
46 | |
47 | String page = FPSTR(HTTP_HEADER); |
48 | page.replace("{v}", "LCD Test"); |
49 | page += FPSTR(HTTP_HEADER_END); |
50 | |
51 | page += F("<h1>LCD Test</h1><br />"); |
52 | |
53 | page += F("<form action=\"/lcd\" method=\"post\">"); |
54 | page += F("LCD-Text: <input type=\"text\" name=\"LCDText\" value=\"\" />"); |
55 | page += F("<button type=\"submit\">Senden</button></form>"); |
56 | |
57 | |
58 | page += FPSTR(HTTP_BODY_END); |
59 | |
60 | request->send(200, "text/html",page); |
61 | }
|
62 | |
63 | void handlepostLCD(AsyncWebServerRequest *request){ |
64 | String page = FPSTR(HTTP_HEADER); |
65 | |
66 | page.replace("{v}", "LCD-Text"); |
67 | page += FPSTR(HTTP_HEADER_END); |
68 | page += F("<h1>Text an LCD gesendet</h1><br />"); |
69 | page += F("Text: "); |
70 | int params = request->params(); |
71 | for(int i=0;i<params;i++){ |
72 | AsyncWebParameter* p = request->getParam(i); |
73 | if(p->isPost()){ |
74 | if(String(p->name().c_str()) == "LCDText"){ |
75 | display.clearDisplay(); |
76 | display.println(String(p->value().c_str())); |
77 | page += p->value().c_str(); |
78 | display.display(); |
79 | }
|
80 | }
|
81 | }
|
82 | |
83 | page += FPSTR(HTTP_BODY_END); |
84 | |
85 | request->send(200, "text/html",page); |
86 | |
87 | |
88 | }
|
Timmo H. schrieb: > So in etwa, ohne Garantie (ungetestet) Uii Dankeschön erstmal aber das Display hab ich nicht. Ich hatte vor das erstmal über den Seriellen Monitor zu testen
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.