ssd1306 Oled display 128x64 spi 0.93 wiring question

I have just used an oled display 128x64 spi 0.96 inch ssd1306 and i've realised that i can connect any display pin to any arduino pin(except gnd and vcc have to connect to gnd and 5v on arduino). Do i need to connect the pin to the exact arduino pin? Why? Which pins?(except gnd and vcc). I also heard about hardware spi and software spi, what are they? How to connect hardware?

I think that it depends on the library that you use. If the library uses hardware SPI the pins SCK, MOSI, MISO are fixed and cannot be changed by the user*. If the library uses a software SPI the user should be able to choose the pins.

*Except perhaps the chip se!ect (SS).

From Adafruit_SSD1306.h

  // NEW CONSTRUCTORS -- recommended for new projects
  Adafruit_SSD1306(uint8_t w, uint8_t h, TwoWire *twi=&Wire, int8_t rst_pin=-1,
    uint32_t clkDuring=400000UL, uint32_t clkAfter=100000UL);
  Adafruit_SSD1306(uint8_t w, uint8_t h, int8_t mosi_pin, int8_t sclk_pin,
    int8_t dc_pin, int8_t rst_pin, int8_t cs_pin);
  Adafruit_SSD1306(uint8_t w, uint8_t h, SPIClass *spi,
    int8_t dc_pin, int8_t rst_pin, int8_t cs_pin, uint32_t bitrate=8000000UL);

e.g.

Adafruit_SSD1306 display(128, 64, &Wire, -1, 400000, 100000); //HW I2C
Adafruit_SSD1306 display(128, 64, OLED_MOSI, OLED_SCK, OLED_DC, OLED_RST, OLED_CS, 8000000); //SW SPI
Adafruit_SSD1306 display(128, 64, &SPI, OLED_DC, OLED_RST, OLED_CS, 8000000); //HW SPI

The HW I2C constructor means that you must use the SDA, SCL pins marked on your Arduino
The HW SPI constructor means that you must use MOSI, SCK pins on your Arduino (11,13 on a Uno)

You can use any pins for the OLED_xx arguments in the SW SPI constructor.

It is always wise to try the SW SPI constructor with new hardware first. Just make sure that your wires actually correspond to the digital pin and the label on the OLED.

When you have verified that the Software SPI works, try the HW SPI constructor. (it will be much faster)

David.

If you are unfamiliar with the pins and wiring of your SSD1306 to your Arduino you may find pictures and an explanation on my website, Arduino Bare Basics - Zonnestroompanelen in Nederland

OLED pin
GND ----> GND on Arduino
VCC -----> 3.3V on Arduino (5V works; be aware that an OLED is basicxally a 3.3V device)
SCL -----> A5 on Arduino
SDA -----> A4 on Arduino

at the end of the page on thw website is a little sketch to test your OLED display (creates 'Hello World' and a smiley)