ccarman602

OLED Girls Who Code logo with NodeMCU

Jun 3rd, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * This combines code from the OLED display of the "Girls Who Code" logo
  3.  * with code to use the NodeMCU.
  4.  *
  5.  * The easiest way to set up the OLED with a NodeMCU is to place the NodeMCU onto a
  6.  * breadboard so that it takes up holes b1-b15 and i1-i15 on the breadboard with the
  7.  * micro USB port pointing "up" (it should hang over the edge of the breadboard), and
  8.  * then plug the OLED pins into holes a9-a15, so that the "CS" pin on the OLED matches
  9.  * up with the "D0" pin on the NodeMCU (at the "bottom", near the squiggly copper wifi
  10.  * antenna). OLED pin "VCC" should match up with the "3V3" pin on the NodeMCU, and
  11.  * OLED pin "GND" should match up with the "GND" pin on the NodeMCU.
  12.  *
  13.  * In the Arduino IDE, make sure go to Tools > Board and select "NodeMCU 1.0",
  14.  * otherwise it won't work!
  15.  *
  16.  * If you want to make your own bitmap (black & white) images, the maximum size for
  17.  * the 0.96" OLED is 128 pixels wide by 32 pixels tall. Use this online tool to convert
  18.  * your graphics:
  19.  * https://javl.github.io/image2cpp/
  20.  */
  21.  
  22. #include <SPI.h>
  23. #include <Wire.h>
  24. #include <Adafruit_GFX.h>
  25. #include <Adafruit_SSD1306.h>
  26.  
  27. // If using software SPI (the default case):
  28. #define OLED_CS    D0
  29. #define OLED_DC    D1
  30. #define OLED_RESET D2
  31. #define OLED_MOSI  D3 // aka "D1" on the OLED
  32. #define OLED_CLK   D4 // aka "D0" on the OLED
  33. Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
  34.  
  35. #define LOGO_GWC_HEIGHT 32
  36. #define LOGO_GWC_WIDTH  128
  37. const unsigned char logo_gwc_bmp[] PROGMEM = {
  38.   // 'girls_who_code_logo_128x64, 128x64px
  39.   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  40.   0xff, 0xff, 0xff, 0xff, 0xbf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  41.   0xff, 0xff, 0xff, 0xfe, 0xef, 0xff, 0xff, 0xff, 0xff, 0xf2, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff,
  42.   0xff, 0xff, 0xff, 0xfe, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xf7, 0xbf, 0xff, 0xff, 0xff, 0xff, 0xff,
  43.   0xff, 0xff, 0xff, 0xfe, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xf7, 0xbf, 0xff, 0xff, 0xff, 0xff, 0xff,
  44.   0xff, 0xff, 0xff, 0xfe, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xf7, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff,
  45.   0xff, 0xff, 0xff, 0xfe, 0xef, 0xff, 0xff, 0xff, 0xff, 0xf7, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff,
  46.   0xff, 0xf7, 0xff, 0xfe, 0xcf, 0xff, 0xff, 0xff, 0xff, 0xf6, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  47.   0xff, 0xff, 0xff, 0xfe, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xf5, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  48.   0xff, 0xff, 0xef, 0xfe, 0xbf, 0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  49.   0xc0, 0xf7, 0xe0, 0xfe, 0x7f, 0x87, 0xff, 0xcf, 0xbe, 0xf4, 0x7f, 0x0f, 0xff, 0xff, 0xff, 0xff,
  50.   0x3c, 0xe7, 0xee, 0xfe, 0xff, 0x7b, 0xff, 0xaf, 0x3e, 0x13, 0xbe, 0xf6, 0x7f, 0xff, 0xff, 0xff,
  51.   0x7c, 0xc7, 0xde, 0xfc, 0x7c, 0xfb, 0xff, 0x67, 0x3c, 0xf7, 0xbc, 0xf2, 0x7f, 0xff, 0xff, 0xff,
  52.   0x3c, 0xb7, 0xbf, 0x73, 0x3b, 0x73, 0x7f, 0xf6, 0x19, 0xf7, 0xb8, 0xf6, 0x7f, 0xff, 0xff, 0xff,
  53.   0xc6, 0x78, 0xff, 0x8f, 0xcf, 0x8b, 0xff, 0xf9, 0xc7, 0xf7, 0xc7, 0x1e, 0x7f, 0xff, 0xff, 0xff,
  54.   0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xff,
  55.   0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xff,
  56.   0xf6, 0xf8, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x1f, 0xc0, 0x00, 0x1e, 0x7f, 0x00, 0x00, 0x00,
  57.   0xec, 0xf9, 0xff, 0xff, 0xff, 0xe7, 0xff, 0xff, 0x9f, 0xdf, 0xff, 0xfe, 0x7f, 0x3f, 0xff, 0xfc,
  58.   0xdc, 0xf9, 0xff, 0xff, 0xff, 0xe7, 0xff, 0xff, 0x9f, 0xdf, 0xff, 0xfe, 0x7f, 0x3f, 0xff, 0xfc,
  59.   0xdc, 0xf9, 0xff, 0xff, 0xff, 0xe7, 0xff, 0xff, 0x9f, 0xdf, 0xff, 0xfe, 0x7f, 0x3f, 0x00, 0x00,
  60.   0xdd, 0xf9, 0xff, 0xff, 0xff, 0xe7, 0xff, 0xff, 0x9f, 0xdf, 0xff, 0xfe, 0x7f, 0x3f, 0xff, 0xff,
  61.   0xc9, 0xf9, 0xff, 0xff, 0xff, 0xe7, 0xff, 0xff, 0x9f, 0xdf, 0xff, 0xfe, 0x7f, 0x3f, 0xff, 0xff,
  62.   0xff, 0xf9, 0xff, 0xff, 0xff, 0xe7, 0xff, 0xff, 0x9f, 0xdf, 0xff, 0xfe, 0x7f, 0x3f, 0xff, 0xff,
  63.   0xff, 0xf9, 0xff, 0xff, 0xff, 0xe7, 0xff, 0xff, 0x9f, 0xdf, 0xff, 0xfe, 0x7f, 0x3f, 0xff, 0xff,
  64.   0xff, 0xf9, 0xff, 0xff, 0xff, 0xe7, 0xff, 0xff, 0x9f, 0xdf, 0xff, 0xfe, 0x7f, 0x3f, 0xff, 0xff,
  65.   0xff, 0xf9, 0xff, 0xff, 0xff, 0xe7, 0xff, 0xff, 0x9f, 0xdf, 0xff, 0xfe, 0x7f, 0x3f, 0xff, 0xff,
  66.   0xff, 0xf9, 0xff, 0xff, 0xff, 0xe7, 0xff, 0xff, 0x9f, 0xdf, 0xff, 0xfe, 0x7f, 0x3f, 0xff, 0xff,
  67.   0xff, 0xf9, 0xff, 0xff, 0xff, 0xe3, 0xff, 0xff, 0x9f, 0xcf, 0xff, 0xfe, 0x7f, 0x3f, 0xff, 0xff,
  68.   0xff, 0xff, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x1f, 0xc0, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00,
  69.   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  70.   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
  71. };
  72.  
  73. #define SSD1306_LCDHEIGHT 64
  74. #if (SSD1306_LCDHEIGHT != 64)
  75. #error("Height incorrect, please fix Adafruit_SSD1306.h!");
  76. #endif
  77.  
  78. void setup() {
  79.   Serial.begin(9600);
  80.  
  81.   display.begin(SSD1306_SWITCHCAPVCC);
  82.   display.clearDisplay();
  83. }
  84.  
  85. void loop() {
  86.   // display the Girls Who Code logo!
  87.   display.drawBitmap(0, 0, logo_gwc_bmp, LOGO_GWC_WIDTH, LOGO_GWC_HEIGHT, 1);
  88.   display.display();
  89.  
  90.   // invert the display so that it blinks!
  91.   display.invertDisplay(true);
  92.   delay(1000);
  93.   display.invertDisplay(false);
  94.   delay(1000);
  95. }
Add Comment
Please, Sign In to add comment