Introduction: OLED Tutorial | Convert SPI to I2C
In this tutorial, we are going to learn about OLED displays. Which can be very easily interfaced with Arduino and can display important parameters for your project, and see how to convert these screens from SPI to I2C,
So let's get started!
Step 1: Watch the Video !
If you don't want to read all the stuff You can watch my video Click Here
Step 2: SPI V/s I2C
These OLED displays come in various sizes and two different interface number one I2C which use the I2C bus of the Arduino and requires four pins to operate two for the power and the other two are SCL which is nothing but serial clock and SDA which is serial data.
Talking about SPI it is faster than I2C. But we generally prefer the I2C interface over the SPI because it requires fewer numbers of pins as compared to SPI but if you have SPI OLED you can easily convert it to I2C.
1.3 inch OLED SPI - https://www.gearbest.com/lcd-led-display-module/pp...
0.96 inch OLED I2C - https://www.gearbest.com/lcd-led-display-module/pp...
0.91 inch OLED I2C - https://www.gearbest.com/other-accessories/pp_0098...
Step 3: Convert SPI to I2C
If you flip around your display you will observe your display has indications to convert SPI to I2C (ICC means I2C). you will need to switch resistor from SPI to I2C and short the resistor path R8.
Now Vcc and the GND lines are the same but CLK will be your SCL, MOSI will be your SDA and you need to connect reset pin to Vcc and the other two pins to the GND
And now you can use the SPI OLED as I2C
Note-
not all models support conversion please check before you purchase
Step 4: Connections to Arduino
Now to interface this display to Arduino first we will need to connect the power and then connect SCL pin to SCL and the SDA pin to SDA pin of the Arduino. If you don’t know which pins you need to connect head over to the google and search I2C pins of the Arduino and here, you can see for the Arduino nano A5 is SCL and A4 is SDA. Similarly, you can do that for Arduino Uno and Arduino mega
Note:-
Add 10K pull-up resistor to SDA & SCL to avoid random Freez
Step 5: Programming
Now to display the information on OLEDs we need to program the Arduino for that, we will be using u8glib library.
Open Arduino IDE, in Sketch Tab select, Include Library then Manage Library, Now search u8glib library, scroll down and install it.
Let’s start with the Hello World program,
Here first you need to know your display model number mine is SD1306. So in program you need to uncomment your display model number in order for it to work.
In all the function first two parameters are x and y coordinates by changing them you can change the position of the text
And the third parameter for this function is text which you can change
There are several other functions which can be used to display circle or ellipse
You should check out the reference manual for the library if you want to learn more
Step 6: Thank You
If you like my work
Feel free to check out my YouTube channel for more awesome stuff:
https://www.youtube.com/c/Nematics_lab
You can also follow me on Facebook, Twitter etc for upcoming projects
https://www.facebook.com/NematicsLab/
https://www.instagram.com/nematic_yt/
https://twitter.com/Nematic_YT
Check out JLCPCB
$2 PCB Prototype (10pcs,10*10cm): https://jlcpcb.com
12 Comments
3 years ago on Introduction
Nematic,
I had success with your guide, very helpful, using a UNO or MEGA board, but I had a few differences.
My Jaycar 7 pin OLED 1.3" 128x64 worked ok on SPI. It had the following 7 pins, Gnd, Vcc, Clk, Mosi, Res, Dc, Cs. https://www.jaycar.com.au/duinotech-1-3-inch-monochrome-oled-display/p/XC3728 I then converted it from SPI to I2C. by doing the following.
I found success with only having to only wire connect the OLED SPI connections of VCC to DC, then I moved the "SPI resistor" to the I2C location and soldered into place and then I bridge the R8 resistor location with solder.
The other issue was the software. The Adafruit SH1106 software was required rather than the SSD1306 for my Jaycar OLED. At times there has been suggestions that on line 76 (see image) that the code 0x3D needs to be 0x3C, but this was not needed in my case, left software as is and Adafruit software ran ok. You still have to make sure you have SPI, Wire, Adafruit_GFX and Adafruit_SH1106 libraries installed. I recall that if you import the SH1106 it will suggest other library to be installed.
https://github.com/wonho-maker/Adafruit_SH1106.
For the Mega board the only difference between UNO is to use Pin 20 (SDA) & Pin 21 (SCL) to connect to OLED
Hope this was useful and saved someone time. Regards Chuck
4 years ago
Hello Nematic. Thank you for posting the SPI to 12C
I just received my SSD3106 and it is a new version they then the one you converted.
My 3106 is missing the R1 and R8. From your video you moved a resistor and bridged R8
I don't have a hot air gun so is it possible to add in a resistor to R1 and it looks to be a 472 ohm SDA resistor.
John
4 years ago
Hi,
Thank you. Great tutorial! Clear instructions, pictures, video and examples.
I have this 6-pin OLED display, which seems to be SPI, but the eBay seller listing it as I2C:
https://www.ebay.co.uk/itm/128X64-0-96-OLED-I2C-II...
It does not seem to have, or I cannot identify, the relevant selection resistor and pads to select between SPI and I2C. See attached image.
Can you provide some advice on how to go about converting this OLED display to I2C, if possible?
Reply 4 years ago
Mate, the one you have is called 4 wire SPI. I believe you can change it to i2c by swapping the resistors on the back of the board.
Reply 4 years ago
Your disply is I2C you dont have to do anything just use standard I2C 4 pin config
Reply 4 years ago
Hi, thanks for the response. How can you tell it is I2C? I've already tried it. I replaced an existing and working I2C 128x32 OLED display, connecting to the same pins (GND, VCC, SCL, SDA) and it did not work. So, it is either faulty or it is SPI.
4 years ago
thanks for this, its pointing me in the right direction.. however i have this OLED, do you know how i could change it to i2c?
https://www.adafruit.com/product/1431
Reply 4 years ago
This is a 16 bit oled you can't use I2C with it, but however, you can use it in 3 pin SPI mode just short BS0 jumper
4 years ago
Thanks,
it just took 5 minutes.
5 years ago
thank you thank you thank you
i have 2 of this display and they are spi and i hate spi i will try this when i go home and will post comment about the reslut
Reply 5 years ago
You hate SPI ? Physically, it's almost the same than I2C (not ICC but IIC), SPI is full duplex and doesn't need extra addressing.
Reply 5 years ago
will for beginner link me i like i2c because its only need 2 wire spi need 3 and sometime more and you can connect multi device so easy !