logo elektroda
logo elektroda
X
logo elektroda

OLED display module 0.91 SSD1306 128x32 I2C - how to run with Arduino? How to connect?

p.kaczmarek2 2457 11
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
📢 Listen (AI):
  • OLED display module 0.91 SSD1306 128x32 I2C - how to run with Arduino? How to connect?
    Today we are testing a tiny 0.91-inch OLED display based on the SSD1306 controller and offering control via I2C. The module discussed here offers a rather low resolution, at a mere 128x32, but this can easily be justified by its small price (around £5) and, of course, its small size. It will certainly be useful in many situations where we want to reduce the size of our product.
    Here I will run it with an Arduino. But first a bit of information:
    OLED display module 0.91 SSD1306 128x32 I2C - how to run with Arduino? How to connect?
    From the introduction, I guess what surprised me the most is that according to the manufacturer, this display fits an additional mobile phone display.... this must be from many years ago, anyone seen such a phone?
    OLED display module 0.91 SSD1306 128x32 I2C - how to run with Arduino? How to connect?
    The SSD1306 has an embedded 128 x 64 bit SRAM, used for pixel storage. Here we only control the pixel's light state, on or off. In addition, we can control the brightness level of the entire display. The SSD1306 has three interfaces, which we select on its pins: 8-bit 6800/8080, 3/4-line SPI and I2C. In addition, it offers a programmable horizontal and vertical scrolling effect and allows row and column remapping.
    Fortunately, we do not have to implement communication with the SSD1306 from scratch. We start the adventure by selecting a library:
    OLED display module 0.91 SSD1306 128x32 I2C - how to run with Arduino? How to connect?
    I chose the library from lexus2k.
    In the Arduino IDE it is available to install in Libraries:
    OLED display module 0.91 SSD1306 128x32 I2C - how to run with Arduino? How to connect?
    Let's try running its demo for the SSD1306:
    https://github.com/lexus2k/ssd1306/tree/master/examples/demos/ssd1306_demo
    Here is the first surprise. The example uses :
    Code: C / C++
    Log in, to see the code

    and we have a 128 by 32 display, so the above version will display unreadable text. We change to:
    Code: C / C++
    Log in, to see the code

    I connected the whole thing to the I2C lines from the Arduino, and of course ground and power too. I didn't need to give pull-up resistors to make it work, as they are already on the PCB.
    OLED display module 0.91 SSD1306 128x32 I2C - how to run with Arduino? How to connect?
    Result:



    It works, but the demo is quite substantial, so we'll try to break it down into parts and discuss.

    First - attach the header and initialise the display. You can also set the font:
    Code: C / C++
    Log in, to see the code

    Then, in a loop, you can, for example, draw text with different font styles on the position we have chosen:
    Code: C / C++
    Log in, to see the code

    Similarly, you can draw lines between two points defined as X and Y positions:
    Code: C / C++
    Log in, to see the code

    Results:
    OLED display module 0.91 SSD1306 128x32 I2C - how to run with Arduino? How to connect?
    I don't clean the screen, so lines form on the text:
    OLED display module 0.91 SSD1306 128x32 I2C - how to run with Arduino? How to connect?

    For larger text you can simply choose a larger font - e.g. ssd1306xled_font8x16 :
    Code: C / C++
    Log in, to see the code

    OLED display module 0.91 SSD1306 128x32 I2C - how to run with Arduino? How to connect?
    It's now the shapes. Let's try to make a square to start with. We have a function that draws a rectangle, its first two arguments are the coordinates of one corner and the next two are the coordinates of the opposite corner.
    Code: C / C++
    Log in, to see the code

    Result:
    OLED display module 0.91 SSD1306 128x32 I2C - how to run with Arduino? How to connect?
    NOTE: The coordinates of the second corner must be larger than the first corner. For example, if you enter the first Y larger than the second Y, the corresponding sides will not show:
    Code: C / C++
    Log in, to see the code

    OLED display module 0.91 SSD1306 128x32 I2C - how to run with Arduino? How to connect?
    This is because ssd1306_drawRect uses a from the line-drawing function:
    Code: C / C++
    Log in, to see the code

    And in turn, the line-drawing function simply uses a for loop:
    Code: C / C++
    Log in, to see the code

    But this is a plus, because everything is optimised.

    It's now a rectangle:
    Code: C / C++
    Log in, to see the code

    OLED display module 0.91 SSD1306 128x32 I2C - how to run with Arduino? How to connect?
    Now we can extend the idea and make a loading bar. Every fixed period of time we draw inside the first rectangle another increasing rectangle. We do not clear the whole screen. The first rectangle (frame) is on the screen all the time.
    Code: C / C++
    Log in, to see the code

    Result:




    There is an example of icon use in the demo code too. I have trimmed it down to a minimum for you. We define an icon as bytes, where one bit is a pixel:
    Code: C / C++
    Log in, to see the code

    In the library, the SPRITE class is used to handle this. You need to create an object of this class using ssd1306_createSprite , specifying the dimension of the icon and its data there.
    Code: C / C++
    Log in, to see the code

    The code animates it in a rather interesting and efficient way:
    Code: C / C++
    Log in, to see the code

    The whole screen is not cleaned up here, it just calls eraseTrace that is, cleaning up where the icon was before and then the icon is redisplayed via draw .



    However, eraseTrace is not ideal. In the case of overlapping icons it messes things up a bit. I created a demo with multiple moving icons to demonstrate this:
    Code: C / C++
    Log in, to see the code

    Result:



    That is, you can draw text as well as shapes, and it is also possible to animate them to some extent. For more examples, please refer to the documentation of the library used.

    Summary
    The SSD1306 proved to be very easy to use. Pixels are a little scarce here, but at this display size (and price) this is justified. An additional plus here is that this display can be used on the I2C bus with other devices. This may seem strange, but many other chips with a similar communication protocol do not support addressing, for example such a TM1637.
    Also useful here can be features that allow screen scrolling. This relieves us of the need to animate texts manually.
    I really liked this animation of the loading bar, on a classic 2x16 I have not seen this (or at least not in this form - because in the form of 'blocks' yes).
    This module is very much worthy of attention. Feel free to comment - has anyone used this 'narrow' version of the SSD1603 in a project, and if so, in which one?
    [i]PS: A related topic but in a board version with ESP8266:
    How to program ESP8266 NodeMCU V3 with OLED 0.96 128x64 SSD1306 via USB?

    Cool? Ranking DIY
    Helpful post? Buy me a coffee.
    About Author
    p.kaczmarek2
    Moderator Smart Home
    Offline 
    p.kaczmarek2 wrote 13964 posts with rating 11763, helped 630 times. Been with us since 2014 year.
  • ADVERTISEMENT
  • #2 21244539
    rjmp
    Level 9  
    On the other side of the board (pictures on ali) is a 3.3V stabiliser for the matrix logic. The power supply for the matrix (according to DS) is from 7V and it works with a 5V supply (arduino). I wonder how to supply 3.3V (short out the stabiliser).
  • ADVERTISEMENT
  • #3 21244565
    p.kaczmarek2
    Moderator Smart Home
    Information from vendors suggests that this will run normally on 3.3V:
    OLED display module 0.91 SSD1306 128x32 I2C - how to run with Arduino? How to connect?
    OLED display module 0.91 SSD1306 128x32 I2C - how to run with Arduino? How to connect?
    Helpful post? Buy me a coffee.
  • #4 21244576
    lopr_pol
    Level 32  
    These displays burn out at an express rate, also no wonder ;)
  • ADVERTISEMENT
  • #5 21244622
    austin007
    Level 17  
    >>21244576 What does burn-in look like in this oled? Do the pixels slowly darken or do they suddenly stop glowing? What is the real life expectancy of the pixels here? Technology probably similar in the 1.3" from majfriend? I was going to use for a clock, but gave up in the past in favour of an LCD precisely for fear of rapid burn-in. I used for devices where the display doesn't last long.
  • ADVERTISEMENT
  • #6 21244995
    tmf
    VIP Meritorious for electroda.pl
    p.kaczmarek2 wrote:
    information from vendors suggests that this will run normally on 3.3V:

    The problem is the lack of conversion on the control lines. 5V can whip them up.
    lopr_pol wrote:
    These displays burn out at an express rate, also no wonder

    In the OLED (matrix) note, there is data on the burn-in time. This is usually 15-50tys of hours, depending on the manufacturer. This time can be significantly extended by reducing the OLED's current. In practice, the loss of brightness is minimal, while the life extension is large.
    austin007 wrote:
    What does burn-in look like in this oled? Do the pixels slowly darken or do they suddenly stop glowing?

    There is a gradual decrease in brightness. This is not a problem as long as you do not display large homogeneous areas.
  • #7 21246012
    sq3evp
    Level 38  
    tmf wrote:

    In the note of the OLED (matrix) there are data about the lighting time. This is usually 15-50tys of hours, depending on the manufacturer.

    15k hours is 625 days (about 1 year o 8-9 months of continuous operation) of continuous illumination, almost a year, at this price it probably can be. The question is whether it makes sense to switch on the display all the time?
    50k is 2083 days, or over 5.5 years.
    Probably not too bad.
  • #8 21246271
    tmf
    VIP Meritorious for electroda.pl
    sq3evp wrote:
    I guess it's not too bad.

    If you lower the brightness it probably comes out even higher. Besides, the time is calculated up to some brightness reduction there. So OLEDs are not that bad. Readability, contrast, response time - this is where they beat LCDs.
  • #10 21246833
    coberr
    Level 20  
    these displays are so terribly small - that they are impractical...
    it only becomes apparent when you get your hands on a working display...

    i am surprised - that the Chinese are still "sticking" them in this size and resolution....
  • #11 21246975
    sq3evp
    Level 38  
    tmf wrote:
    So OLEDs are not so bad. Readability, contrast,
    response time - this is where they beat LCDs.

    This I agree - I have several devices with simple OLED displays and they beat the others.
  • #12 21247620
    gemiel
    Level 25  
    It all depends on the use of the display and the user's preferences. Since women's mechanical watches have been produced for many years with dials several millimetres in diameter, it is apparently possible to read something on them. A matter of quality of sight. After many years, I have also started to worship larger and larger displays.
    I recently had to use an ATS-20 receiver with an OLED display on a sunny day. The size of the characters can be compensated for with glasses. On the other hand, when there is a lot of ambient light, nothing can be seen on the display.
    However, these tiny displays have their advantages. They can be mounted as information displays in many small devices.
📢 Listen (AI):
ADVERTISEMENT