Advertisement
JonD1988

128x32 OLED

Sep 10th, 2021
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //This is a highly modified version of the Example sketch available by clicking in the Arduino IDE File -> Examples -> Adafruit SSD1306 -> OLED_featherwing
  2. //To get this to work you need to follow the instructions in the first review by calBear at
  3. //https://www.amazon.com/SSD1306-Self-Luminous-Display-Compatible-Raspberry/dp/B08LYL7QFQ/ref=sr_1_3?dchild=1&keywords=128x64%2BOLED&qid=1627471545&sr=8-3&fbclid=IwAR2lzvpr5-noXW7rSlxwR5lF8OPrLJmvdJVk6vPRBobZDewJUZnqU1lXoSg&th=1
  4. //I have these instructions saved in an OLED Research.docx file
  5.  
  6. //Read this article to understand what all of these buttons are from
  7. //Source 1 - https://learn.adafruit.com/adafruit-oled-featherwing/usage
  8. //Source 2 - https://lastminuteengineers.com/oled-display-arduino-tutorial/ - very useful article that explains the sketch below
  9.  
  10. //#include <SPI.h> //Only used in the serial version of the OLED - not needed for I2C version
  11. #include <Wire.h>
  12. #include <Adafruit_GFX.h>
  13. #include <Adafruit_SSD1306.h>
  14.  
  15. Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire);
  16.  
  17. // OLED FeatherWing buttons map to different pins depending on board:
  18. //This mapping is for the Arduino's ATMega328P processor
  19. //#define BUTTON_A  9 - Not needed since not using this Adafruit board mentioned in Source 1
  20. //#define BUTTON_B  6 - Not needed since not using this Adafruit board mentioned in Source 1
  21. //#define BUTTON_C  5 - Not needed since not using this Adafruit board mentioned in Source 1
  22.  
  23. void setup() {
  24.   Serial.begin(9600);
  25.  
  26.   Serial.println("OLED FeatherWing test");
  27.   // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  28.   display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32
  29.  
  30.   Serial.println("OLED begun");
  31.  
  32.   // Show image buffer on the display hardware.
  33.   // Since the buffer is intialized with an Adafruit splashscreen
  34.   // internally, this will display the splashscreen.
  35.   display.display();
  36.   delay(1000);
  37.  
  38.   // Clear the buffer.
  39.   display.clearDisplay();
  40.   display.display();
  41.  
  42.   Serial.println("IO test");
  43.  
  44.   //pinMode(BUTTON_A, INPUT_PULLUP);
  45.   //pinMode(BUTTON_B, INPUT_PULLUP);
  46.   //pinMode(BUTTON_C, INPUT_PULLUP);
  47.  
  48.   // text display tests
  49.   display.setTextSize(1);
  50.   display.setTextColor(SSD1306_WHITE);
  51.   display.setCursor(0,0);
  52.   //display.print("Connecting to SSID\n'adafruit':");
  53.   //display.print("connected!");
  54.   //display.println("IP: 10.0.1.23");
  55.   //display.println("Sending val #0");
  56.   display.println("Hello! My name is ");
  57.   display.print("Jonathan DeWitt");
  58.   display.setCursor(0,0);
  59.   display.display(); // actually display all of the above
  60. }
  61.  
  62. void loop() {
  63.   //if(!digitalRead(BUTTON_A)) display.print("A");
  64.   //if(!digitalRead(BUTTON_B)) display.print("B");
  65.   //if(!digitalRead(BUTTON_C)) display.print("C");
  66.   //delay(10);
  67.   //yield();
  68.   //display.display();
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement