OLED I2c Display With Arduino

407,563

170

96

About: Computer geek who stumbled upon arduino and electronics in general a while ago.

Intro: OLED I2c Display With Arduino

In this instructable I will show you how to connect and test a 0.96" i2c OLED display module to an arduino.

Parts:

  • Breadboard and hookup wires
  • Arduino (using a nano v3 5v 16mhz clone in this case)
  • External power supply (regulated 5v)
  • The OLED i2c display

I bought my display around 6 months ago, and I can’t seem to find the exact display on ebay now, but searching for “0.96 ssd1306 i2c OLED” shows a whole lot of similar displays. Other sites, like adafruit, got the same displays if you prefer to shop there.

Step 1: Connecting Your Display

The display is connected by utilizing the i2c pins on your arduino.

Which pins to use for this differs on some arduino models, but on the UNO and NANO you use pin A4 (SDA) and A5 (SCL). If you’re using another arduino, google the pinout and look for SDA and SCL pins. (For example, google “arduino mega pinout”, and check the images).

I first attempted to power my display from my arduinos 5v. This worked, but only halfway – the display fired up, and started cycling the demos in the sketch we will see later on, and then froze after a few seconds.

I then powered my display from my external 5v supply (with common ground to the arduino), which did the trick – the display is now working properly.

The connections from the display:

  • VCC to external 5v
  • GND to external GND
  • SCL to arduino pin A5 (or the SCL pin for your arduino)
  • SDA to arduino pin A4 (or the SDA pin for your arduino)
  • arduino GND pin to external psu GND

Arduino is connected to the computer via an USB cable. The USB powers the arduino.

Step 2: I2c Scanner

To start out, we need to find out the i2c address of the display. To
accomplish this, I use a quick i2c scanner uploaded to the arduino. The scanner code can be found on http://playground.arduino.cc/Main/I2cScanner.
Copy and paste the code into your arduino IDE, build and upload, and fire up your serial monitor. If your display are connected, powered and working, you will get an address back from the scanner (in serial monitor). My display shows up at address 0x3C.

Step 3: Libraries

In this instructable I am using the arduino IDE (http://arduino.cc) and libraries from adafruit downloaded via github.
Link to the libraries:

I will assume you know how to download and install libraries in your arduino IDE. If not, there are tons of nice tutorials/instructions out there on how to get started with the arduino IDE and libraries.

Both libraries below needs to be installed before you are able to continue with this instructable.

https://github.com/adafruit/Adafruit_SSD1306 (SSD1306 library)

https://github.com/adafruit/Adafruit-GFX-Library (GFX library)

Step 4: Test Sketch

Now that we know our displays i2c address, we can open the example sketch in our adafruit ssd1306 library.
In your arduino IDE, check your examples menu and locate the 128×64 i2c sketch found under Adafruit SSD1306 (as shown in the picture).
Change the address of the display to whatever the scanner told you, in my case 3x0C.

Compile and upload to your arduino, give it a second, and the display should fire up and show some different display modes.

The demo sketch ends with stars that continues to fall forever. You can copy-paste from the demo sketch to use the display modes that fits your needs.

27 People Made This Project!

Recommendations

  • Audio Contest 2018

    Audio Contest 2018
  • Plastics Contest

    Plastics Contest
  • Electronics Tips & Tricks Challenge

    Electronics Tips & Tricks Challenge

96 Discussions

0
None
AlexO116

6 days ago

I have this problem, what I have to do?

IMG_20181005_132629.jpg
0
None
StevenV24

2 years ago

You said: "I first attempted to power my display from my arduinos 5v. This
worked, but only halfway – the display fired up, and started cycling the
demos in the sketch we will see later on, and then froze after a few
seconds.

I then powered my display from my external 5v supply
(with common ground to the arduino), which did the trick – the display
is now working properly".

This is somewhat strange ... some of the replyers have no problem with powering from the arduinos 5V?

7 replies
0
None
CraftKing7777StevenV24

Reply 2 years ago

Maybe they are plugging into usb 3.0 while he is using USB 2.0 which only supplies half the current of 3.0

0
None
VilleK4CraftKing7777

Reply 2 years ago

The display uses minimalistic current, and powering even from an arduino digital pin probably works, so naturally the 5V regulated or VCC would work perfect from USB 2.0.

I think Steven is correct and I'd suspect glitchy wiring if the screen froze. Probably lost the i2c mid process, and nothing to do with the power.

There's NO need to use external power for this OLED screen!

0
None
Jean0x7BEVilleK4

Reply 2 years ago

A faulty wire could certainly explain it, as well as a bugged clone can - might be both. Anyway, not stating you need an external supply, but I indeed did with this setup. Have you measured the current draw on the display?

0
None
CulturedropoutJean0x7BE

Reply 6 days ago

A day (or 2 years) late and a dollar short, but I'm using a Nano purchased via Amazon that turned out to be a clone. Running the Adafruit demo, the display current tops out at 25.3mA, and the running current with the "snowflake" display is around 6mA. I initially powered it with a bench supply, but I later connected it to the "Nano"'s 5V output and it still seems to work fine. It's hanging off a powered USB 3.0 hub, so ymmv, however. The real Nano uses an LM1117IMPX-5.0 regulator, which TI's web site specs as capable of 800mA output at 5V, so I decided to give it a try. With a bench supply feeding the Nano via the Vin pin and ground, and the USB disconnected, everything seems to work okay. Nice instructable - saved me a lot of flailing around. Thanks!

Update: Someone commented that the display is supposed to run on 3.3V. I have not confirmed that, but it seems to be as happy on 3.3V as on 5V. The only thing of note is that the 3.3V on the Nano apparently comes from the FTDI USB chip, and "Up to 50mA can be drawn from
this pin to power external logic if required." Substantially less "headroom" that with the 5V supply...

0
None
Jean0x7BECraftKing7777

Reply 2 years ago

I'm really not sure, but it might be related to the fact that I was using a nano clone (not genuine arduino), which might have a different voltage regulator, or maybe a partly broken one? I'm also considering if the lack of pull-up resistors on the i2c-line could be the reason, even thought when I changed PSU it worked fine.

0
None
VilleK4Jean0x7BE

Reply 2 years ago

The 0.08W claim for the OLED would mean it could take a maximum of around 25mA with 3.3V and less than 20mA with 5V.

I can't measure my OLED since it's soldered onto my arduino now, but I'm using SPI, which works without issues. I2C would be better, when having multiple devices, but you do need to use pull ups and set up addresses.

Pull up resistors might be the answer, for sure. Not sure if the OLED device has built in pull-ups, but you could try adding 10k ones, and see weather it makes a difference. Or if the 5V line is too noisy, add a small uF capacitor between the 5V and GND to keep the noise down.

It's quite difficult to make a crap arduino clone, so that's never been a problem for me. As long as you can run blink on it, it should pretty much do everything else too.

I'd like to know if you find the fix! =)

0
None
Jean0x7BECraftKing7777

Reply 2 years ago

That might also be something to consider - when I changed power supply, I didn't power the display from USB anymore, which might explain the change in behaviour.

0
None
FaisalMal

1 year ago

Hello,

My OLED is a just white color I want to change to different color.

Is it possible?

Thank you and wish you a nice day.

5 replies
0
None
CulturedropoutFaisalMal

Reply 6 days ago

If it's white, I'd think you could put a square of colored acetate or some other transparent tinted plastic over the display to get whatever color you want. Assuming you mean you know it's a monochrome display and you're not wanting to change colors under program control.

0
None
Alex_1998FaisalMal

Reply 1 year ago

I suppose, it is impossible. The colour is unchangeable, it defined by the used OLED type.

0
None
FaisalMalAlex_1998

Reply 1 year ago

Is there different ROLES with the same controller but different color? because as you can see up there it's blue .

0
None
Alex_1998FaisalMal

Reply 1 year ago

Yes, you are rigth. The same SSD1306 controller can supplied with blue or white monohrome display panels.

0
None
thomas30FaisalMal

Reply 1 year ago

Most of these small OLED displays can only use black and white

0
None
abhishekcshah15

9 months ago

ssd1306_128x64_i2c:54: error: #error ("Height incorrect, please fix Adafruit_SSD1306.h!");

#error ("Height incorrect, please fix Adafruit_SSD1306.h!");

^

exit status 1

#error ("Height incorrect, please fix Adafruit_SSD1306.h!");

I got this error and can't solve this. Plzz help

3 replies
0
None
EricP235abhishekcshah15

Reply 8 months ago

Thank you too for this tutorial. Unfortunatly, I had the same error than abhishekcshah15. To fix it, I erase the line, (it' only an error message, not very important for testing) ...Less than 5 minutes to test again, and it's work perfectly ! Very good, thank you again!

1
None
ThorL3

Tip 2 months ago on Step 1

Add a 1k pullup resistor on SDA and SCL and you won't need the external power supply. The built-in pullup resistors on the Atmega chip are too weak to work reliably.