Advertisement
ccarman602

KGC Simple OLED Display with NodeMCU

Jun 3rd, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Simple OLED display code with NodeMCU
  3.  
  4. This combines the earlier "Simple OLED display code" with a NodeMCU so that it's more compact.
  5.  
  6. The easiest way to set up the OLED with a NodeMCU is to place the NodeMCU onto a
  7. breadboard so that it takes up holes b1-b15 and i1-i15 on the breadboard with the
  8. micro USB port pointing "up" (it should hang over the edge of the breadboard), and
  9. then plug the OLED pins into holes a9-a15, so that the "CS" pin on the OLED matches
  10. up with the "D0" pin on the NodeMCU (at the "bottom", near the squiggly copper wifi
  11. antenna). OLED pin "VCC" should match up with the "3V3" pin on the NodeMCU, and
  12. OLED pin "GND" should match up with the "GND" pin on the NodeMCU.
  13.  
  14. In the Arduino IDE, make sure go to Tools > Board and select "NodeMCU 1.0",
  15. otherwise it won't work!
  16. */
  17.  
  18. #include <SPI.h>
  19. #include <Wire.h>
  20. #include <Adafruit_GFX.h>
  21. #include <Adafruit_SSD1306.h>
  22.  
  23. // If using software SPI (the default case):
  24. #define OLED_CS    D0
  25. #define OLED_DC    D1
  26. #define OLED_RESET D2
  27. #define OLED_MOSI  D3 // aka "D1" on the OLED
  28. #define OLED_CLK   D4 // aka "D0" on the OLED
  29. Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
  30. #if (SSD1306_LCDHEIGHT != 32)
  31. #error("Height incorrect, please fix Adafruit_SSD1306.h!");
  32. #endif
  33.  
  34.  
  35. void setup(){
  36.   Serial.begin(9600);
  37.  
  38.   // set up the OLED display
  39.   display.begin(SSD1306_SWITCHCAPVCC);
  40.   display.clearDisplay();
  41.   display.display();
  42. }
  43.  
  44. void loop(){
  45.  
  46.   // this block displays the first screen
  47.   display.clearDisplay();
  48.   display.setTextSize(2);
  49.   display.setTextColor(WHITE);
  50.   display.setCursor(0,0);
  51.   // display.println("1234567890"); // text size 2 allows max 10 characters per line, max 2 lines
  52.   display.println("Kent Girl");
  53.   display.println("Coders :)");
  54.   display.display();
  55.   delay(2000);
  56.  
  57.   // this block displays the second screen
  58.   display.clearDisplay();
  59.   display.setTextSize(2);
  60.   display.setTextColor(WHITE);
  61.   display.setCursor(0,0);
  62.   display.println("Girls run");
  63.   display.println("the world!");
  64.   display.display();
  65.   delay(2000);
  66.  
  67.   // this block blanks the screen for 1/4-second
  68.   display.clearDisplay();
  69.   display.setTextSize(1);
  70.   display.setTextColor(WHITE);
  71.   display.setCursor(0,0);
  72.   display.display();
  73.   delay(250);
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement