Introduction: HowTo - Esp-12F Mini WiFi Modul ESP8266 18650 Nodemcu Batterie 0.96” OLED DEMO Via Arduino GUI
Hallo,
hier möchte ich Euch zeigen wie Ihr das mit auf der Hauptplatine verbaute OLED Display benutzen/ansteuern könnt. Um es möglichst einfach zu halten, benutze ich die ARDUINO GUI zum schreiben des CODEs und zum hochladen der Firmware.
Step 1: Einstellen / Einrichten Der ARDUINO GUI
Als erstes muss das ESP8266 Board in der ARDUINO GUI verfügbar gemacht werden.
Dazu gehen wir in die Einstellungen (Datei --> Einstellungen / Bild 1) der GUI und tragen unter
"Zusätzliche Boardverwalter-URLs:" http://arduino.esp8266.com/stable/package_esp8266com_index.json
ein (Bild 2). Damit bekommen wir den benötigten Zugang zu dem passenden Boardtreiber.
Jetzt können wir den Passenden Boardtreiber installieren.
(Werkzeuge --> Board: --> Boardverwaltung / Bild 3)
- Dort im Suchfeld "esp8266" eintragen
- Dann "esp8266 by ESP8266 Community" auswählen und die aktuellste Version installieren (Bild 4)
- Die ARDUINO GUI neu starten
- Danach das passende Board auswählen (z.B.: WeMos D1 R2 & mini)
Step 2: I2C Schnittstelle Scannen
Um zu sehen an welche PINs das OLED-Display angeschlossen wurde, scannen wir zuerst die I2C-Schnittstelle. So können wir auch sehen ob noch weitere I2C-Parts angeschlossen sind.
Den Sketch (Bild 1) auf den ESP Hochladen, den "Seriellen-Monitor" öffnen und auf die Ausgabe warten. Dort könnt Ihr dann sehen, welches Device wo gefunden wurde. (Bild 2 - DigitalPIN Scan)
Das Ergebnis merken.
In diesem Fall: SDA = D1 : SCL = D2 bei Adresse 0x3c
Attachments
Step 3: Demo-Sketch Anpassen Und Auf Den ESP Hochladen
Das ist der Code für das OLED-Display DEMO
Im 5. Abschnitt findet Ihr die Stelle an der der Code ggf. modifiziert werden muss.
Also die Konfiguration für die I2C-Schnittstelle.
Aus diesem Code könnt Ihr euch auch viele Infos über die Benutzung eines OLEDs ableiten.
/**
* The MIT License (MIT) * * Copyright (c) 2016 by Daniel Eichhorn * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * *
/ Include the correct display library // For a connection via I2C using Wire include #include // for I2C Wire #include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`
// Include custom images #include "images.h"
// Initialize the OLED display using brzo_i2c // D3 -> SDA // D5 -> SCL // SSD1306 display(0x3c, D1, D2); or SSD1306 display(0x3c, 5, 4); or SSD1306 display(0x3c, GPIO5, GPIO4);
**************************************************************************************************
An der folgenden Stelle werden dann die PINs für die I2C Schnittstelle konfiguriert.
// Initialize the OLED display using Wire library SSD1306 display(0x3c, D1, D2);
***************************************************************************************************
#define DEMO_DURATION 3000 typedef void (*Demo)(void);
int demoMode = 0; int counter = 1;
void setup() { Serial.begin(9600); Serial.println("OLED_DEMO"); Serial.println("Start the DEMO");
// Initialising the UI will init the display too. display.init();
display.flipScreenVertically(); display.setFont(ArialMT_Plain_10);
}
void drawFontFaceDemo() { // Font Demo1 Serial.println("Font DEMO 1"); // create more fonts at http://oleddisplay.squix.ch/ display.setTextAlignment(TEXT_ALIGN_LEFT); display.setFont(ArialMT_Plain_10); display.drawString(0, 0, "ProMoScout"); display.setFont(ArialMT_Plain_16); display.drawString(0, 10, "ProMoScout"); display.setFont(ArialMT_Plain_24); display.drawString(0, 26, "ProMoScout"); }
void drawTextFlowDemo() { Serial.println("drawTextFlowDemo"); display.setFont(ArialMT_Plain_10); display.setTextAlignment(TEXT_ALIGN_LEFT); display.drawStringMaxWidth(0, 0, 128, "Robots are \n the Future, and the Future, is now. But don't forget the Nature" ); }
void drawTextAlignmentDemo() { Serial.println("drawTextAlignmentDemo"); // Text alignment demo display.setFont(ArialMT_Plain_10); // Schriftart und -größe einstellen
// The coordinates define the left starting point of the text display.setTextAlignment(TEXT_ALIGN_LEFT); // Text_Ausrichtung einstellen display.drawString(0, 10, "Left aligned (0,10)");
// The coordinates define the center of the text display.setTextAlignment(TEXT_ALIGN_CENTER); display.drawString(64, 22, "Center aligned (64,22)");
// The coordinates define the right end of the text display.setTextAlignment(TEXT_ALIGN_RIGHT); display.drawString(128, 33, "Right aligned (128,33)"); }
void drawRectDemo() { Serial.println("drawRectDemo"); // Draw a pixel at given position for (int i = 0; i < 10; i++) { display.setPixel(i, i); display.setPixel(10 - i, i); } display.drawRect(12, 12, 20, 20);
// Fill the rectangle display.fillRect(14, 14, 17, 17);
// Draw a line horizontally display.drawHorizontalLine(0, 40, 20);
// Draw a line horizontally display.drawVerticalLine(40, 0, 20); }
void drawCircleDemo() { Serial.println("drawCircleDemo"); for (int i=1; i < 8; i++) { display.setColor(WHITE); display.drawCircle(32, 32, i*3); if (i % 2 == 0) { display.setColor(BLACK); } display.fillCircle(96, 32, 32 - i* 3); } }
void drawProgressBarDemo() { Serial.println("drawProgressBarDemo"); int progress = (counter / 5) % 100; // draw the progress bar display.drawProgressBar(0, 32, 120, 10, progress);
// draw the percentage as String display.setTextAlignment(TEXT_ALIGN_CENTER); display.drawString(64, 15, String(progress) + "%"); }
Der folgende Link im Kommentar kann helfen ein Bild oder Logo so umzuwandeln, das es auf dem Display angezeigt werden kann ...
void drawImageDemo() { Serial.println("drawImageDemo"); // see http://blog.squix.org/2015/05/esp8266-nodemcu-how... // on how to create xbm files display.drawXbm(34, 0, Logo_width, Logo_height, Logo_bits); }
Demo demos[] = {drawFontFaceDemo, drawTextFlowDemo, drawTextAlignmentDemo, drawRectDemo, drawCircleDemo, drawProgressBarDemo, drawImageDemo}; int demoLength = (sizeof(demos) / sizeof(Demo)); long timeSinceLastModeSwitch = 0;
void loop() { // clear the display display.clear(); // draw the current demo method demos[demoMode]();
display.setTextAlignment(TEXT_ALIGN_RIGHT); display.drawString(10, 128, String(millis())); // write the buffer to the display display.display();
if (millis() - timeSinceLastModeSwitch > DEMO_DURATION) { demoMode = (demoMode + 1) % demoLength; timeSinceLastModeSwitch = millis(); } counter++; delay(10); }
Attachments
Step 4: Tools, Links Und Herkunft/Literaturhinweis
Ich möchte mich bei allen bedanken die an dem ein oder anderen Code mit gewirkt haben.
Die Grundlagen für diese Anleitung habe ich gefunden unter:
https://www.instructables.com/id/ESP8266-I2C-PORT-...
https://github.com/ThingPulse/esp8266-oled-ssd1306...
Viele Grüße
McUtty