From 87a4b1ac38580acbc33365510304db7785865ea8 Mon Sep 17 00:00:00 2001 From: "Dirk O. Kaar" Date: Fri, 6 Jan 2017 14:33:12 +0100 Subject: [PATCH 1/3] Swap HIGH/LOW in Blink demo --- examples/01.Basics/Blink/Blink.ino | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/01.Basics/Blink/Blink.ino b/examples/01.Basics/Blink/Blink.ino index 637c976..5ab90ec 100644 --- a/examples/01.Basics/Blink/Blink.ino +++ b/examples/01.Basics/Blink/Blink.ino @@ -5,12 +5,14 @@ */ void setup() { - pinMode(BUILTIN_LED, OUTPUT); // initialize onboard LED as output + pinMode(LED_BUILTIN, OUTPUT); // Initialize onboard LED as output } void loop() { - digitalWrite(BUILTIN_LED, HIGH); // turn on LED with voltage HIGH - delay(1000); // wait one second - digitalWrite(BUILTIN_LED, LOW); // turn off LED with voltage LOW + digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (Note that LOW is the voltage level + // but actually the LED is on; this is because + // it is active low on the ESP-01) + delay(1000); // Wait one second + digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH delay(1000); // wait one second } From 8dc77f17bea38b46082023ed5d642b8d5ff65b51 Mon Sep 17 00:00:00 2001 From: "Dirk O. Kaar" Date: Fri, 26 Apr 2019 13:39:42 +0200 Subject: [PATCH 2/3] OLED shield example using Adafruit's library (MIT license). ePaper 2.13 shield examples copied here from LOLIN_EPD_Library, helps new users find the examples in one spot. TFT 1.4 shield examples extended with setup instructions. --- .../ssd1306_64x48_i2c/ssd1306_64x48_i2c.ino | 422 ++++++++++++++++++ .../TFT_1.4_Shield/simple/simple.ino | 10 + .../04.Shields/TFT_1.4_Shield/test/test.ino | 10 + .../graphicstest/graphicstest.ino | 258 +++++++++++ .../ePaper_2.13_Shield/simple/simple.ino | 325 ++++++++++++++ 5 files changed, 1025 insertions(+) create mode 100644 examples/04.Shields/OLED_Shield/Use_Adafruit_Library/ssd1306_64x48_i2c/ssd1306_64x48_i2c.ino create mode 100644 examples/04.Shields/ePaper_2.13_Shield/graphicstest/graphicstest.ino create mode 100644 examples/04.Shields/ePaper_2.13_Shield/simple/simple.ino diff --git a/examples/04.Shields/OLED_Shield/Use_Adafruit_Library/ssd1306_64x48_i2c/ssd1306_64x48_i2c.ino b/examples/04.Shields/OLED_Shield/Use_Adafruit_Library/ssd1306_64x48_i2c/ssd1306_64x48_i2c.ino new file mode 100644 index 0000000..6aa70a8 --- /dev/null +++ b/examples/04.Shields/OLED_Shield/Use_Adafruit_Library/ssd1306_64x48_i2c/ssd1306_64x48_i2c.ino @@ -0,0 +1,422 @@ +/************************************************************************** + +1. Setup latest Adafruit_GFX and Adafruit_SSD1306 with 64x48 patches libraries first: + + https://github.com/adafruit/Adafruit-GFX-Library + + https://github.com/dok-net/Adafruit_SSD1306 + + **************************************************************************/ + +/************************************************************************** + This is an example for our Monochrome OLEDs based on SSD1306 drivers + + Pick one up today in the adafruit shop! + ------> http://www.adafruit.com/category/63_98 + + This example is for a 64x48 size display using I2C to communicate + 3 pins are required to interface (two I2C and one reset). + + Adafruit invests time and resources providing this open + source code, please support Adafruit and open-source + hardware by purchasing products from Adafruit! + + Written by Limor Fried/Ladyada for Adafruit Industries, + with contributions from the open source community. + BSD license, check license.txt for more information + All text above, and the splash screen below must be + included in any redistribution. + **************************************************************************/ + +#include +#include +#include +#include + +#define SCREEN_WIDTH 64 // OLED display width, in pixels +#define SCREEN_HEIGHT 48 // OLED display height, in pixels + +// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) +// SCL GPIO5 +// SDA GPIO4 +#define OLED_RESET 0 // GPIO0 +Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); + +#define NUMFLAKES 10 // Number of snowflakes in the animation example + +#define LOGO_HEIGHT 16 +#define LOGO_WIDTH 16 +static const unsigned char PROGMEM logo_bmp[] = +{ B00000000, B11000000, + B00000001, B11000000, + B00000001, B11000000, + B00000011, B11100000, + B11110011, B11100000, + B11111110, B11111000, + B01111110, B11111111, + B00110011, B10011111, + B00011111, B11111100, + B00001101, B01110000, + B00011011, B10100000, + B00111111, B11100000, + B00111111, B11110000, + B01111100, B11110000, + B01110000, B01110000, + B00000000, B00110000 }; + +void setup() { + Serial.begin(9600); + + // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally + if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 64x48 + Serial.println(F("SSD1306 allocation failed")); + for(;;); // Don't proceed, loop forever + } + + // Show initial display buffer contents on the screen -- + // the library initializes this with an Adafruit splash screen. + display.display(); + delay(2000); // Pause for 2 seconds + + // Clear the buffer + display.clearDisplay(); + + // Draw a single pixel in white + display.drawPixel(10, 10, WHITE); + + // Show the display buffer on the screen. You MUST call display() after + // drawing commands to make them visible on screen! + display.display(); + delay(2000); + // display.display() is NOT necessary after every single drawing command, + // unless that's what you want...rather, you can batch up a bunch of + // drawing operations and then update the screen all at once by calling + // display.display(). These examples demonstrate both approaches... + + testdrawline(); // Draw many lines + + testdrawrect(); // Draw rectangles (outlines) + + testfillrect(); // Draw rectangles (filled) + + testdrawcircle(); // Draw circles (outlines) + + testfillcircle(); // Draw circles (filled) + + testdrawroundrect(); // Draw rounded rectangles (outlines) + + testfillroundrect(); // Draw rounded rectangles (filled) + + testdrawtriangle(); // Draw triangles (outlines) + + testfilltriangle(); // Draw triangles (filled) + + testdrawchar(); // Draw characters of the default font + + testdrawstyles(); // Draw 'stylized' characters + + testscrolltext(); // Draw scrolling text + + testdrawbitmap(); // Draw a small bitmap image + + // Invert and restore display, pausing in-between + display.invertDisplay(true); + delay(1000); + display.invertDisplay(false); + delay(1000); + + testanimate(logo_bmp, LOGO_WIDTH, LOGO_HEIGHT); // Animate bitmaps +} + +void loop() { +} + +void testdrawline() { + int16_t i; + + display.clearDisplay(); // Clear display buffer + + for(i=0; i=0; i-=4) { + display.drawLine(0, display.height()-1, display.width()-1, i, WHITE); + display.display(); + delay(1); + } + delay(250); + + display.clearDisplay(); + + for(i=display.width()-1; i>=0; i-=4) { + display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE); + display.display(); + delay(1); + } + for(i=display.height()-1; i>=0; i-=4) { + display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE); + display.display(); + delay(1); + } + delay(250); + + display.clearDisplay(); + + for(i=0; i0; i-=3) { + // The INVERSE color is used so circles alternate white/black + display.fillCircle(display.width() / 2, display.height() / 2, i, INVERSE); + display.display(); // Update screen with each newly-drawn circle + delay(1); + } + + delay(2000); +} + +void testdrawroundrect(void) { + display.clearDisplay(); + + for(int16_t i=0; i0; i-=5) { + // The INVERSE color is used so triangles alternate white/black + display.fillTriangle( + display.width()/2 , display.height()/2-i, + display.width()/2-i, display.height()/2+i, + display.width()/2+i, display.height()/2+i, INVERSE); + display.display(); + delay(1); + } + + delay(2000); +} + +void testdrawchar(void) { + display.clearDisplay(); + + display.setTextSize(1); // Normal 1:1 pixel scale + display.setTextColor(WHITE); // Draw white text + display.setCursor(0, 0); // Start at top-left corner + display.cp437(true); // Use full 256 char 'Code Page 437' font + + // Not all the characters will fit on the display. This is normal. + // Library will draw what it can and the rest will be clipped. + for(int16_t i=0; i<256; i++) { + if(i == '\n') display.write(' '); + else display.write(i); + } + + display.display(); + delay(2000); +} + +void testdrawstyles(void) { + display.clearDisplay(); + + display.setTextSize(1); // Normal 1:1 pixel scale + display.setTextColor(WHITE); // Draw white text + display.setCursor(0,0); // Start at top-left corner + display.println(F("Hello, world!")); + + display.setTextColor(BLACK, WHITE); // Draw 'inverse' text + display.println(3.141592); + + display.setTextSize(2); // Draw 2X-scale text + display.setTextColor(WHITE); + display.print(F("0x")); display.println(0xDEADBEEF, HEX); + + display.display(); + delay(2000); +} + +void testscrolltext(void) { + display.clearDisplay(); + + display.setTextSize(2); // Draw 2X-scale text + display.setTextColor(WHITE); + display.setCursor(10, 0); + display.println(F("scroll")); + display.display(); // Show initial text + delay(100); + + // Scroll in various directions, pausing in-between: + display.startscrollright(0x00, 0x0F); + delay(2000); + display.stopscroll(); + delay(1000); + display.startscrollleft(0x00, 0x0F); + delay(2000); + display.stopscroll(); + delay(1000); + display.startscrolldiagright(0x00, 0x07); + delay(2000); + display.startscrolldiagleft(0x00, 0x07); + delay(2000); + display.stopscroll(); + delay(1000); +} + +void testdrawbitmap(void) { + display.clearDisplay(); + + display.drawBitmap( + (display.width() - LOGO_WIDTH ) / 2, + (display.height() - LOGO_HEIGHT) / 2, + logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, 1); + display.display(); + delay(1000); +} + +#define XPOS 0 // Indexes into the 'icons' array in function below +#define YPOS 1 +#define DELTAY 2 + +void testanimate(const uint8_t *bitmap, uint8_t w, uint8_t h) { + int8_t f, icons[NUMFLAKES][3]; + + // Initialize 'snowflake' positions + for(f=0; f< NUMFLAKES; f++) { + icons[f][XPOS] = random(1 - LOGO_WIDTH, display.width()); + icons[f][YPOS] = -LOGO_HEIGHT; + icons[f][DELTAY] = random(1, 6); + Serial.print(F("x: ")); + Serial.print(icons[f][XPOS], DEC); + Serial.print(F(" y: ")); + Serial.print(icons[f][YPOS], DEC); + Serial.print(F(" dy: ")); + Serial.println(icons[f][DELTAY], DEC); + } + + for(;;) { // Loop forever... + display.clearDisplay(); // Clear the display buffer + + // Draw each snowflake: + for(f=0; f< NUMFLAKES; f++) { + display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, WHITE); + } + + display.display(); // Show the display buffer on the screen + delay(200); // Pause for 1/10 second + + // Then update coordinates of each flake... + for(f=0; f< NUMFLAKES; f++) { + icons[f][YPOS] += icons[f][DELTAY]; + // If snowflake is off the bottom of the screen... + if (icons[f][YPOS] >= display.height()) { + // Reinitialize to a random position, just off the top + icons[f][XPOS] = random(1 - LOGO_WIDTH, display.width()); + icons[f][YPOS] = -LOGO_HEIGHT; + icons[f][DELTAY] = random(1, 6); + } + } + } +} diff --git a/examples/04.Shields/TFT_1.4_Shield/simple/simple.ino b/examples/04.Shields/TFT_1.4_Shield/simple/simple.ino index 557eafa..9a14948 100644 --- a/examples/04.Shields/TFT_1.4_Shield/simple/simple.ino +++ b/examples/04.Shields/TFT_1.4_Shield/simple/simple.ino @@ -1,3 +1,13 @@ +/*************************************************** + +1. Setup latest Adafruit_GFX and Adafruit_ST7735 Libraries first: + + https://github.com/adafruit/Adafruit-GFX-Library + + https://github.com/adafruit/Adafruit-ST7735-Library + +****************************************************/ + #include // Core graphics library #include // Hardware-specific library #include diff --git a/examples/04.Shields/TFT_1.4_Shield/test/test.ino b/examples/04.Shields/TFT_1.4_Shield/test/test.ino index 0833509..0102550 100644 --- a/examples/04.Shields/TFT_1.4_Shield/test/test.ino +++ b/examples/04.Shields/TFT_1.4_Shield/test/test.ino @@ -1,3 +1,13 @@ +/*************************************************** + +1. Setup latest Adafruit_GFX and Adafruit_ST7735 Libraries first: + + https://github.com/adafruit/Adafruit-GFX-Library + + https://github.com/adafruit/Adafruit-ST7735-Library + +****************************************************/ + #include // Core graphics library #include // Hardware-specific library #include diff --git a/examples/04.Shields/ePaper_2.13_Shield/graphicstest/graphicstest.ino b/examples/04.Shields/ePaper_2.13_Shield/graphicstest/graphicstest.ino new file mode 100644 index 0000000..5437528 --- /dev/null +++ b/examples/04.Shields/ePaper_2.13_Shield/graphicstest/graphicstest.ino @@ -0,0 +1,258 @@ +/*************************************************** + +1. Setup latest Adafruit_GFX and LOLIN_EPD Libraries first: + + https://github.com/adafruit/Adafruit-GFX-Library + + https://github.com/wemos/LOLIN_EPD_Library + +****************************************************/ + +#include +#include + +float p = 3.1415926; + +/*D1 mini*/ +#define EPD_CS D0 +#define EPD_DC D8 +#define EPD_RST -1 // can set to -1 and share with microcontroller Reset! +#define EPD_BUSY -1 // can set to -1 to not use a pin (will wait a fixed delay) + +/*D32 Pro*/ +// #define EPD_CS 14 +// #define EPD_DC 27 +// #define EPD_RST 33 // can set to -1 and share with microcontroller Reset! +// #define EPD_BUSY -1 // can set to -1 to not use a pin (will wait a fixed delay) + +LOLIN_IL3897 EPD(250, 122, EPD_DC, EPD_RST, EPD_CS, EPD_BUSY); //hardware SPI + +// #define EPD_MOSI D7 +// #define EPD_CLK D5 +// LOLIN_IL3897 EPD(250,122, EPD_MOSI, EPD_CLK, EPD_DC, EPD_RST, EPD_CS, EPD_BUSY); //IO + + + +void setup(void) { + Serial.begin(115200); + Serial.print("Hello! EPD Test"); + + EPD.begin(); + + Serial.println("Initialized"); + + // large block of text + EPD.clearBuffer(); + EPD.fillScreen(EPD_WHITE); + testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", EPD_BLACK); + + // epd print function! + epdPrintTest(); + + // a single pixel + EPD.clearBuffer(); + EPD.drawPixel(EPD.width()/2, EPD.height()/2, EPD_BLACK); + + testtriangles(); + + // line draw test + testlines(EPD_BLACK); + + // optimized lines + testfastlines(EPD_BLACK, EPD_RED); + + testdrawrects(EPD_RED); + + testfillrects(EPD_BLACK, EPD_RED); + + EPD.fillScreen(EPD_WHITE); + testfillcircles(10, EPD_RED); + testdrawcircles(10, EPD_BLACK); + + testroundrects(); + + mediabuttons(); + + Serial.println("done"); +} + +void loop() { + delay(500); +} + +void testlines(uint16_t color) { + EPD.clearBuffer(); + EPD.fillScreen(EPD_WHITE); + for (int16_t x=0; x < EPD.width(); x+=6) { + EPD.drawLine(0, 0, x, EPD.height()-1, color); + } + for (int16_t y=0; y < EPD.height(); y+=6) { + EPD.drawLine(0, 0, EPD.width()-1, y, color); + } + + EPD.fillScreen(EPD_WHITE); + for (int16_t x=0; x < EPD.width(); x+=6) { + EPD.drawLine(EPD.width()-1, 0, x, EPD.height()-1, color); + } + for (int16_t y=0; y < EPD.height(); y+=6) { + EPD.drawLine(EPD.width()-1, 0, 0, y, color); + } + + EPD.fillScreen(EPD_WHITE); + for (int16_t x=0; x < EPD.width(); x+=6) { + EPD.drawLine(0, EPD.height()-1, x, 0, color); + } + for (int16_t y=0; y < EPD.height(); y+=6) { + EPD.drawLine(0, EPD.height()-1, EPD.width()-1, y, color); + } + + EPD.fillScreen(EPD_WHITE); + for (int16_t x=0; x < EPD.width(); x+=6) { + EPD.drawLine(EPD.width()-1, EPD.height()-1, x, 0, color); + } + for (int16_t y=0; y < EPD.height(); y+=6) { + EPD.drawLine(EPD.width()-1, EPD.height()-1, 0, y, color); + } + EPD.display(); +} + +void testdrawtext(char *text, uint16_t color) { + EPD.clearBuffer(); + EPD.setCursor(0, 0); + EPD.setTextColor(color); + EPD.setTextWrap(true); + EPD.print(text); + EPD.display(); +} + +void testfastlines(uint16_t color1, uint16_t color2) { + EPD.clearBuffer(); + EPD.fillScreen(EPD_WHITE); + for (int16_t y=0; y < EPD.height(); y+=5) { + EPD.drawFastHLine(0, y, EPD.width(), color1); + } + for (int16_t x=0; x < EPD.width(); x+=5) { + EPD.drawFastVLine(x, 0, EPD.height(), color2); + } + EPD.display(); +} + +void testdrawrects(uint16_t color) { + EPD.clearBuffer(); + EPD.fillScreen(EPD_WHITE); + for (int16_t x=0; x < EPD.width(); x+=6) { + EPD.drawRect(EPD.width()/2 -x/2, EPD.height()/2 -x/2 , x, x, color); + } + EPD.display(); +} + +void testfillrects(uint16_t color1, uint16_t color2) { + EPD.clearBuffer(); + EPD.fillScreen(EPD_WHITE); + for (int16_t x=EPD.width()-1; x > 6; x-=6) { + EPD.fillRect(EPD.width()/2 -x/2, EPD.height()/2 -x/2 , x, x, color1); + EPD.drawRect(EPD.width()/2 -x/2, EPD.height()/2 -x/2 , x, x, color2); + } + EPD.display(); +} + +void testfillcircles(uint8_t radius, uint16_t color) { + EPD.clearBuffer(); + for (int16_t x=radius; x < EPD.width(); x+=radius*2) { + for (int16_t y=radius; y < EPD.height(); y+=radius*2) { + EPD.fillCircle(x, y, radius, color); + } + } + EPD.display(); +} + +void testdrawcircles(uint8_t radius, uint16_t color) { + EPD.clearBuffer(); + for (int16_t x=0; x < EPD.width()+radius; x+=radius*2) { + for (int16_t y=0; y < EPD.height()+radius; y+=radius*2) { + EPD.drawCircle(x, y, radius, color); + } + } + EPD.display(); +} + +void testtriangles() { + EPD.clearBuffer(); + EPD.fillScreen(EPD_WHITE); + int color = EPD_BLACK; + int t; + int w = EPD.width()/2; + int x = EPD.height()-1; + int y = 0; + int z = EPD.width(); + for(t = 0 ; t <= 15; t++) { + EPD.drawTriangle(w, y, y, x, z, x, color); + x-=4; + y+=4; + z-=4; + if(t == 8) color = EPD_RED; + } + EPD.display(); +} + +void testroundrects() { + EPD.clearBuffer(); + EPD.fillScreen(EPD_WHITE); + int color = EPD_BLACK; + int i; + int t; + for(t = 0 ; t <= 4; t+=1) { + int x = 0; + int y = 0; + int w = EPD.width()-2; + int h = EPD.height()-2; + for(i = 0 ; i <= 16; i+=1) { + EPD.drawRoundRect(x, y, w, h, 5, color); + x+=2; + y+=3; + w-=4; + h-=6; + if(i == 7) color = EPD_RED; + } + color = EPD_BLACK; + } + EPD.display(); +} + +void epdPrintTest() { + EPD.clearBuffer(); + EPD.setCursor(2, 0); + EPD.fillScreen(EPD_WHITE); + EPD.setTextColor(EPD_BLACK); + EPD.setTextSize(2); + EPD.println("Hello World!"); + EPD.setTextSize(1); + EPD.setTextColor(EPD_RED); + EPD.print(p, 6); + EPD.println(" Want pi?"); + EPD.println(" "); + EPD.print(8675309, HEX); // print 8,675,309 out in HEX! + EPD.println(" Print HEX!"); + EPD.println(" "); + EPD.setTextColor(EPD_BLACK); + EPD.println("Sketch has been"); + EPD.println("running for: "); + EPD.setTextColor(EPD_RED); + EPD.print(millis() / 1000); + EPD.setTextColor(EPD_BLACK); + EPD.print(" seconds."); + EPD.display(); +} + +void mediabuttons() { + EPD.clearBuffer(); + // play + EPD.fillScreen(EPD_WHITE); + EPD.fillRoundRect(25, 10, 78, 60, 8, EPD_BLACK); + EPD.fillTriangle(42, 20, 42, 60, 90, 40, EPD_RED); + // pause + EPD.fillRoundRect(25, 90, 78, 60, 8, EPD_BLACK); + EPD.fillRoundRect(39, 98, 20, 45, 5, EPD_RED); + EPD.fillRoundRect(69, 98, 20, 45, 5, EPD_RED); + EPD.display(); +} diff --git a/examples/04.Shields/ePaper_2.13_Shield/simple/simple.ino b/examples/04.Shields/ePaper_2.13_Shield/simple/simple.ino new file mode 100644 index 0000000..5ca69a2 --- /dev/null +++ b/examples/04.Shields/ePaper_2.13_Shield/simple/simple.ino @@ -0,0 +1,325 @@ +/*************************************************** + +1. Setup latest Adafruit_GFX and LOLIN_EPD Libraries first: + + https://github.com/adafruit/Adafruit-GFX-Library + + https://github.com/wemos/LOLIN_EPD_Library + +****************************************************/ + +#include +#include + +const unsigned char gImage_num1[128] PROGMEM = { + /* 0X02,0X01,0X20,0X00,0X20,0X00, */ + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xDF, + 0xFF, + 0xF7, + 0xFF, + 0xDF, + 0xFF, + 0xF7, + 0xFF, + 0xDF, + 0xFF, + 0xF7, + 0xFF, + 0xDF, + 0xFF, + 0xE7, + 0xFF, + 0x80, + 0x00, + 0x07, + 0xFF, + 0x00, + 0x00, + 0x07, + 0xFF, + 0x00, + 0x00, + 0x07, + 0xFF, + 0xFF, + 0xFF, + 0xE7, + 0xFF, + 0xFF, + 0xFF, + 0xF7, + 0xFF, + 0xFF, + 0xFF, + 0xF7, + 0xFF, + 0xFF, + 0xFF, + 0xF7, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, +}; + +const unsigned char gImage_num2[128] PROGMEM = { + /* 0X02,0X01,0X20,0X00,0X20,0X00, */ + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xE1, + 0xFF, + 0xC7, + 0xFF, + 0xC1, + 0xFF, + 0x87, + 0xFF, + 0x99, + 0xFF, + 0x27, + 0xFF, + 0x3F, + 0xFE, + 0x67, + 0xFF, + 0x7F, + 0xFC, + 0xE7, + 0xFF, + 0x7F, + 0xF9, + 0xE7, + 0xFF, + 0x7F, + 0xF3, + 0xE7, + 0xFF, + 0x7F, + 0xE7, + 0xE7, + 0xFF, + 0x3F, + 0xCF, + 0xE7, + 0xFF, + 0x1F, + 0x1F, + 0xE7, + 0xFF, + 0x80, + 0x3F, + 0xC7, + 0xFF, + 0x80, + 0x7E, + 0x07, + 0xFF, + 0xE0, + 0xFE, + 0x1F, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, +}; + +/*D1 mini*/ +#define EPD_CS D0 +#define EPD_DC D8 +#define EPD_RST -1 // can set to -1 and share with microcontroller Reset! +#define EPD_BUSY -1 // can set to -1 to not use a pin (will wait a fixed delay) + +/*D32 Pro*/ +// #define EPD_CS 14 +// #define EPD_DC 27 +// #define EPD_RST 33 // can set to -1 and share with microcontroller Reset! +// #define EPD_BUSY -1 // can set to -1 to not use a pin (will wait a fixed delay) + +LOLIN_IL3897 EPD(250, 122, EPD_DC, EPD_RST, EPD_CS, EPD_BUSY); //hardware SPI + +// #define EPD_MOSI D7 +// #define EPD_CLK D5 +// LOLIN_IL3897 EPD(250,122, EPD_MOSI, EPD_CLK, EPD_DC, EPD_RST, EPD_CS, EPD_BUSY); //IO + +void setup() +{ + EPD.begin(); + EPD.clearBuffer(); + EPD.setTextColor(EPD_BLACK); + EPD.println("hello world!"); + // EPD.display(); + // delay(2000); + EPD.partInit(); + delay(100); +} + +void loop() +{ + // for (uint8_t i = 0; i < 4; i++) + // { + // EPD.setRotation(i); + // EPD.clearBuffer(); + + // EPD.setCursor(0,0); + // EPD.println("hello world!"); + // EPD.println(EPD.getRotation()); + // EPD.display(); + // delay(2000); + // } + + EPD.partDisplay(0, 32, gImage_num1, 32, 32); + EPD.partDisplay(0, 32, gImage_num2, 32, 32); + delay(2000); +} From c806279ff8a97530e2f0c1924e237b6cacff94ba Mon Sep 17 00:00:00 2001 From: "Dirk O. Kaar" Date: Mon, 13 May 2019 15:36:33 +0200 Subject: [PATCH 3/3] Updated examples using the SSD1306-based 64x48 OLED displays for new setup API. --- .../BH1750_OLED_test/BH1750_OLED_test.ino | 23 +++++++++++++++++-- .../HP303B_OLED_TEST/HP303B_OLED_TEST.ino | 13 +++++++++-- .../simple/simple.ino | 2 ++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/examples/04.Shields/Ambient_Light_Shield(BH1750)/BH1750_OLED_test/BH1750_OLED_test.ino b/examples/04.Shields/Ambient_Light_Shield(BH1750)/BH1750_OLED_test/BH1750_OLED_test.ino index 0d45a19..f9b7ae4 100644 --- a/examples/04.Shields/Ambient_Light_Shield(BH1750)/BH1750_OLED_test/BH1750_OLED_test.ino +++ b/examples/04.Shields/Ambient_Light_Shield(BH1750)/BH1750_OLED_test/BH1750_OLED_test.ino @@ -1,18 +1,37 @@ +//Install [claws/BH1750 Library](https://github.com/claws/BH1750) first. + #include #include #include #include +#define SCREEN_WIDTH 64 // OLED display width, in pixels +#define SCREEN_HEIGHT 48 // OLED display height, in pixels + +// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) +// SCL GPIO5 +// SDA GPIO4 #define OLED_RESET 0 // GPIO0 -Adafruit_SSD1306 display(OLED_RESET); +Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); + +/* + + BH1750 can be physically configured to use two I2C addresses: + - 0x23 (most common) (if ADD pin had < 0.7VCC voltage) + - 0x5C (if ADD pin had > 0.7VCC voltage) + + Library uses 0x23 address as default, but you can define any other address. + If you had troubles with default value - try to change it to 0x5C. +*/ BH1750 light(0x23); void setup() { Serial.begin(115200); - display.begin(SSD1306_SWITCHCAPVCC, 0x3C); + // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally + if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)); // Address 0x3C for 64x48 } diff --git a/examples/04.Shields/Barometric_Pressure_HP303B_Shield/HP303B_OLED_TEST/HP303B_OLED_TEST.ino b/examples/04.Shields/Barometric_Pressure_HP303B_Shield/HP303B_OLED_TEST/HP303B_OLED_TEST.ino index beaba78..2e0adc6 100644 --- a/examples/04.Shields/Barometric_Pressure_HP303B_Shield/HP303B_OLED_TEST/HP303B_OLED_TEST.ino +++ b/examples/04.Shields/Barometric_Pressure_HP303B_Shield/HP303B_OLED_TEST/HP303B_OLED_TEST.ino @@ -1,3 +1,5 @@ +//Install [LOLIN_HP303B_Library](https://github.com/wemos/LOLIN_HP303B_Library.git) first. + #include #include #include @@ -5,13 +7,20 @@ LOLIN_HP303B HP303B; +#define SCREEN_WIDTH 64 // OLED display width, in pixels +#define SCREEN_HEIGHT 48 // OLED display height, in pixels + +// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) +// SCL GPIO5 +// SDA GPIO4 #define OLED_RESET -1 -Adafruit_SSD1306 display(OLED_RESET); +Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); void setup() { - display.begin(SSD1306_SWITCHCAPVCC, 0x3C); + // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally + if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)); // Address 0x3C for 64x48 display.setTextColor(WHITE); //Address of the HP303B (0x77 or 0x76) diff --git a/examples/04.Shields/Barometric_Pressure_HP303B_Shield/simple/simple.ino b/examples/04.Shields/Barometric_Pressure_HP303B_Shield/simple/simple.ino index c5af294..e8489cc 100644 --- a/examples/04.Shields/Barometric_Pressure_HP303B_Shield/simple/simple.ino +++ b/examples/04.Shields/Barometric_Pressure_HP303B_Shield/simple/simple.ino @@ -1,3 +1,5 @@ +//Install [LOLIN_HP303B_Library](https://github.com/wemos/LOLIN_HP303B_Library.git) first. + #include LOLIN_HP303B HP303B;