In the setup section, we initialize the display with begin() methode. Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1) Otherwise use -1 to use the Arduino reset pin to reset the display. If your display has a separate reset pin connect that pin to the Arduino and use that pin number here. &Wire is used because we are using the I2C communication protocol. Then we create a display object with a previously defined width and height. #define SCREEN_WIDTH 128 // OLED display width, in pixels In case you use different size OLEDs change the value accordingly. Here we are using a 128×64 pixel so we set the width 128 and height 64. Then you need to define OLED height and width. Though you don’t need Adafruit GFX library for this particular code but it will be required later. If you use an SPI OLED display use the SPI library.Īdafruit_SSD1306 library is used to control SSD1306 OLED displays and Adafruit_GFX library is used for graphical functionality like drawing points, lines, circles, etc. The Wire library is used for the I2C communication protocol. Upload the code to the Arduino board and your display will look like this:- Explaining the codeįirst, you need to import the necessary library. In this section, you will learn how to print text and numbers in the display.įirst, I will give an example then I will explain how the code works.Īrduino OLED Code to Print Text and Numbers #include Īdafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1) The Adafruit SSD1306 library has several functions to print text and numbers to the OLED display. #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)Īdafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET) ĭisplay.begin(SSD1306_SWITCHCAPVCC, 0x3C) // initialize with the I2C addr 0x3Cĭisplay.clearDisplay() // Clear the bufferįillDisplay() // Fills the display line by lineįor (int j = 0 j Examples > Adafruit SSD1306 and select the example for your display. #define SCREEN_HEIGHT 64 // OLED display height, in pixels If any pixel was damaged you can identify it. It will fill all the pixels of your OLED line by line. Upload the below code to your Arduino board. Testing the OLEDĪfter wiring the OLED display with the Arduino and installing the necessary library you need to check if everything is working perfectly. You MUST call display() function after print() or draw to make them visible on screen!ĭtCursor() – Sets the cursor at positions x, y.ĭtTextSize() – Sets the size of the text.ĭisplay.print() – Prints letter or number.ĭisplay.drawPixel(x,y, color) – plot a pixel in the x,y coordinates. This will initialize the display with the I2C address 0x3C, and SSD1306_SWITCHCAPVCC will generate a display voltage of 3.3V internally.ĭisplay.clearDisplay() – Clears the display buffer.ĭisplay.display() – will print on the screen from available data on the display ram. This 1KB memory is divided into eight pages, from PAGE0 to PAGE7, which are used for monochrome 128×64 dot matrix displays.ĭisplay.begin(SSD1306_SWITCHCAPVCC, 0x3C) It holds the bit pattern to be displayed on the screen. The size of the RAM is 128 x 64 bits (8,192 bits or 1KB). The SSD1306 controller has a bit-mapped static RAM called GDDRAM ( Graphic Display Data RAM ). So you don’t need any extra power circuitry.Ī regular 0.96-inch OLED display requires a 3.3v to 5v power supply and uses about 20mA current. And a charge pump circuit to obtain a higher voltage for the display. To meet these two different power requirements there is an onboard voltage regulator which takes an input voltage from 1.8v and 6v and provides a stable 3.3v output voltage. The SSD1306 OLED driver requires 1.65v to 3.3v whereas the display needs 7v to 15v. So you have to select between speed and pins according to your project’s needs. I2C protocol only needs 2 pins to communicate with a microcontroller whereas SPI protocol requires a minimum of 5 to 6 pins. It can communicate using both I2C and SPI protocols. The SSD1306 controller has an internal RAM of 128×64 pixels. There are various different display controllers available in the market – SSD1306, SSD1327, SH1106, etc.
0 Comments
Leave a Reply. |