Wiring & Test

We will demonstrate using this display with an Arduino UNO compatible. If you are using a 3V logic device you can skip the level shifter and connect direct from the microcontroller to display. You can also use another kind of level shifter if you like.

Any microcontroller with I2C + 1 pin or 4 or 5 pins can be used, but we recommend testing it out with an UNO before you try a different processor.

SPI Wiring

Don't forget you have to set the display to SPI mode, see the Assembly step on how to do that!

Since this is a SPI-capable display, we can use hardware or 'software' SPI. To make wiring identical on all Arduinos, we'll begin with 'software' SPI. The following pins should be used:

  • Connect Pin #1 to common power/data ground line (black wires)
  • Connect Pin #2 to the 3V power supply on your Arduino. (red wires)
  • Skip pin #3
  • Connect Pin #4 (DC) to digital #8 via the level shifter (white wires) any pin can be used later
  • Connect Pin #7 (SCLK) to digital #13 via the level shifter (blue wires) any pin can be used later
  • Connect Pin #8 (DIN) to digital #11 via the level shifter (green wires) any pin can be used later
  • Skip pins #9-14
  • Connect Pin #15 (CS) to digital #10 via the level shifter (yellow wires) any pin can be used later
  • Connect Pin #16 (RST) to digital #9 via the level shifter (orange wires) any pin can be used later

Later on, once we get it working, we can adjust the library to use hardware SPI if you desire, or change the pins to any others.

Level Shifter Wiring

You will also want to power the HC4050 level shifter by connecting pin #1 to 3V (the red wire) and pin #8 to ground (the black wire)

3.3V Capacitor

We also include a 220uF capacitor with your order because we noticed that the 3V line can fluctuate a lot when powered via an Arduino's 3.3V regulator. We really recommend installing it. Clip the leads on this capacitor and connect the negatve pin to GND and the positive pin to 3V

Download Adafruit_SSD1305 library

To begin reading sensor data, you will need to download Adafruit_SSD1305 from our github repository. You can do that by visiting the github repo and manually downloading or, easier, just click this button to download the zip

Rename the uncompressed folder Adafruit_SSD1305 and check that the Adafruit_SSD1305 folder contains Adafruit_SSD1305.cpp and Adafruit_SSD1305.h

Place the Adafruit_SSD1305 library folder your arduinosketchfolder/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.

We also have a great tutorial on Arduino library installation at: http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use

Installing Adafruit_GFX

You'll also need to download the 'underlying' graphics support library that does all the lines, text, rectangle drawing for you. You can grab it from  https://github.com/adafruit/Adafruit-GFX-Library 

Or click on the button below and follow the same instructions you did for the Adafruit_SSD1305 library. Uncompress and rename the folder to Adafruit_GFX (contains Adafruit_GFX.cpp and .h). Then place them inside your Arduino libraries folder and restart the Arduino IDE. If this is all unfamiliar, we have a tutorial introducing Arduino library concepts and installation.

Restart the IDE!

Adjust display size

Before you compile and run the demo, you'll need to make sure you have the library configured to the right size. Open up the Adafruit_SSD1305.h file in your ArduinoSketchFolder/libraries/Adafruit_SSD1305 folder and look for the lines that have:

#define SSD1305_128_32
//#define SSD1305_128_64

If you are running a 128x32 display, leave the second line commented

If you are running a 128x64 size display, comment the first line and uncomment the second one. Then save the file

Running the Demo

After restarting the Arduino software, you should see a new example folder called Adafruit_SSD1305 and inside, an example called ssd1305test

Now upload the sketch to your Arduino. That's pretty much it! You should see immediate update of the display.

If nothing shows up at all, make sure you have your wiring correct, we have a diagram above you can use. Also, check that you converted the module to "SPI" mode (see the Assembly) step on how to do that

Changing Pins

Now that you have it working, there's a few things you can do to change around the pins.

If you're using Hardware SPI, the CLOCK and MOSI pins are 'fixed' and cant be changed. But you can change to software SPI, which is a bit slower, and that lets you pick any pins you like. Find these lines:

      // If using software SPI, define CLK and MOSI
#define OLED_CLK 13
#define OLED_MOSI 11

// These are neede for both hardware & softare SPI
#define OLED_CS 10
#define OLED_RESET 9
#define OLED_DC 8
    

Change those to whatever you like!

Using Hardware SPI

If you want a little more speed, you can 'upgrade' to Hardware SPI. Its a bit faster, maybe 2x faster to draw but requires you to use the hardware SPI pins.

  • SPI CLK connects to SPI clock. On Arduino Uno/Duemilanove/328-based, thats Digital 13. On Mega's, its Digital 52 and on Leonardo/Due its ICSP-3 (See SPI Connections for more details)
  • SPI DATA IN connects to SPI MOSI. On Arduino Uno/Duemilanove/328-based, thats Digital 11. On Mega's, its Digital 51 and on Leonardo/Due its ICSP-4 (See SPI Connections for more details)

To enable hardware SPI, look for these lines:

// this is software SPI, slower but any pins
Adafruit_SSD1305 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

// this is for hardware SPI, fast! but fixed oubs
//Adafruit_SSD1305 display(OLED_DC, OLED_RESET, OLED_CS);

Comment out the top line and uncomment the bottom line

I2C Wiring

It is also possible to use the display in I2C mode. Its a little slower but uses way fewer pins.

Don't forget you have to set the display to I2C mode, see the Assembly step on how to do that!
Unless you are using a Metro 328 you will need to add I2C pullups on SDA and SCL! Use two 10K (or so) resistors, each one connected from SDA & SCL to 3.3V

For I2C you will need to use the hardware I2C pins on your Arduino or microcontroller. The following pins should be used:

  • Connect Pin #1 to common power/data ground line (black wires)
  • Connect Pin #2 to the 3V power supply on your Arduino. (red wires)
  • Skip pin #3
  • Connect Pin #4 (DC & I2C Addr0) to ground (black wire) to set the I2C address to 0x3C. If this is tied to 3.3V, it will set the I2C address to 0x3D
  • Connect Pin #7 (SCL) to Arduino SCL (green wire)
  • Connect Pin #8 (SDA) to Arduino SDA (blue wire)
  • Connect Pin #9 (SDA2) to Pin #8 (small blue wire)
  • Skip pins #9-15
  • Connect Pin #16 (RST) to digital #9 by using a resistive divider as shown, two resistors from 1K to 10K both the same value can be used. Any pin can be used later

While its ideal to use level shifters on the I2C pins, you can sorta get away with this on an arduino, because the I2C pins are open collector and there are very weak pullups on those two lines. If using with other I2C devices, we suggest using a 3V-logic arduino or an I2C-safe shifter.

Later on, once we get it working, we can adjust the library to use hardware SPI if you desire, or change the pins to any others.

3.3V Capacitor

We also include a 220uF capacitor with your order because we noticed that the 3V line can fluctuate a lot when powered via an Arduino's 3.3V regulator. We really recommend installing it. Clip the leads on this capacitor and connect the negatve pin to GND and the positive pin to 3V

I2C code changes

In the test code, change the top area where you define the protocol used by commenting out the software and hardware SPI and uncommenting the I2C version

// software SPI
//Adafruit_SSD1305 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
// hardware SPI
//Adafruit_SSD1305 display(OLED_DC, OLED_RESET, OLED_CS);
// I2C
Adafruit_SSD1305 display(OLED_RESET);

Everything else about the display is identical to SPI mode.

By default we use I2C address 0x3C which is what we get by connecting DC/A0 to ground. If you tie that pin to 3.3V instead, the address will be 0x3D and all you have to do is call display.begin(0x3D) to initialize with that address.

Last updated on 2017-08-21 at 03.57.02 PM Published on 2015-11-04 at 04.18.19 PM