티스토리 뷰

반응형

Using the SSD1306 128x64 OLED Display with Arduino and Source Code

In this article, we'll go through the process of using the SSD1306 128x64 OLED display with an Arduino board. We'll start by connecting the display to the board and configuring the required libraries, and then move on to writing the code to display text and graphics on the display.

Connecting the Display

The first step in using the SSD1306 128x64 OLED display with an Arduino board is to connect the display to the board. The display typically requires five connections to the board: power, ground, SCL (clock), SDA (data), and a reset pin.

The connections for a typical setup are as follows:

  • VCC (power) to 3.3V on the Arduino
  • GND (ground) to GND on the Arduino
  • SCL (clock) to A5 on the Arduino
  • SDA (data) to A4 on the Arduino
  • RST (reset) to any digital pin on the Arduino

Configuring the Required Libraries

Once the display is connected to the board, the next step is to configure the required libraries. The most common library used with the SSD1306 display is the Adafruit SSD1306 library, which can be installed via the Arduino Library Manager.

Once the library is installed, you'll need to include it in your code using the following line:

#include <Adafruit_SSD1306.h>

Writing the Code

With the display connected and the required libraries installed, the final step is to write the code to display text and graphics on the display.

The code to display text and graphics on the display is as follows:

#include <Adafruit_SSD1306.h>

// create an instance of the Adafruit_SSD1306 class
Adafruit_SSD1306 display(128, 64, &Wire, -1);

void setup() {
  // initialize the display
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.display();

  // display text on the display
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("Hello, world!");
  display.display();
}

void loop() {
  // do nothing
}

Conclusion

In this article, we've gone through the process of using the SSD1306 128x64 OLED display with an Arduino board. By following these steps, you'll be able to easily display text and graphics on the display, making it a useful tool for a wide range of applications.

Whether you're building a weather station, a clock, or any other project that requires a display, the SSD1306 128x64 OLED display is a versatile and reliable choice. So if you're looking to add a display to your next Arduino project, be sure to consider the SSD1306 128x64 OLED display.

반응형