Modular ESP Firmware - OLED - Source
Jump to navigation
Jump to search
A nifty little test program...
platformio.ini
1 [env]
2 platform = espressif8266
3 ; For now, let's stick with the 8266 family MCUs
4
5 framework = arduino
6
7 monitor_speed = 115200
8 ; I like my serial comms fast. (Without this line you get the default of 9600)
9
10 build_flags =
11 -D DEBUG ; This is just plain handy. Use it to turn debugging output on/off...
12 ; -D DEBUG0 ; Show extra WiFi Debug info
13
14 lib_deps =
15 Adafruit GFX Library
16 Adafruit SSD1306
17 Adafruit BusIO
18 ; PubSubClient
19 ; Adafruit NeoPixel
20
21 [env:esp07]
22 platform = espressif8266
23 board = esp07
24 framework = arduino
main.cpp
1 #include <Wire.h>
2 #include <Adafruit_GFX.h>
3 #include <Adafruit_SSD1306.h>
4 #include <Fonts/FreeMonoBold12pt7b.h>
5 #include <Fonts/FreeMonoBold9pt7b.h>
6
7 #define SCREEN_WIDTH 128 // OLED display width, in pixels
8 #define SCREEN_HEIGHT 64 // OLED display height, in pixels
9
10 // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
11 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
12
13 void setup()
14 {
15 Serial.begin(115200);
16
17 if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
18 { // Address 0x3D for 128x64
19 Serial.println(F("SSD1306 allocation failed"));
20 for (;;)
21 ;
22 }
23 delay(2000);
24 display.clearDisplay();
25
26 display.dim(true);
27
28 display.setFont(&FreeMonoBold12pt7b);
29
30 display.setTextSize(1);
31 display.setTextColor(WHITE);
32 display.setCursor(0, 15);
33 // Display static text
34 display.println("ColdStuff");
35 display.display();
36
37 }
38 int X = 0;
39
40 void loop()
41 {
42 display.setFont(&FreeMonoBold9pt7b);
43
44 display.setTextSize(1);
45
46 display.setCursor(2, 30);
47 display.println("Beer: 7.3");
48
49 display.setCursor(2, 50);
50 display.println("Food: -13.1");
51
52 X++;
53 if (X > 128)
54 {
55 X = 0;
56 }
57 display.drawPixel(X, 63, WHITE);
58 display.drawPixel(X-1, 63, BLACK);
59 delay(20);
60 display.display();
61 }