SSD1306 harware SPI on Teensy 3.1

Status
Not open for further replies.

StefanPetrick

Well-known member
Adafruit_SSD1306 hardware SPI on Teensy 3.1

Hello,

I´m using the Adafruit1306 lib and a Teensy 3.1. I have an OLED module where CLK, MOSI, CS and D/C are available.

Software SPI works fine, but I didn´t get the hardware SPI working yet.

The library says

Code:
// If using software SPI (the default case):
#define OLED_MOSI   9
#define OLED_CLK   10
#define OLED_DC    11
#define OLED_CS    12
#define OLED_RESET 8
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

/* Uncomment this block to use hardware SPI
#define OLED_DC     6
#define OLED_CS     7
#define OLED_RESET  8
Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS);
*/

This part works - 2 MHz software SPI.

But how to activate hardware SPI? Which pins do I have to use? What about RESET?

This doesn´t work:

Code:
#define OLED_MOSI   9
#define OLED_CLK   10
#define OLED_DC     6
#define OLED_CS     7
#define OLED_RESET  8
Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS);

Thanks for any hint,

Stefan.
 
Last edited:
Hi Stefan,

Yes, I did drive an SSD1306 using hardware SPI.
Here is the code:
Code:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// hardware SPI on Teensy 3.1: MOSI pin 11, SCK pin 13 plus the pins defined below
#define OLED_DC    9
#define OLED_SS   10
#define OLED_RST  14
Adafruit_SSD1306 display(OLED_DC, OLED_RST, OLED_SS);

void setup() {
  display.begin(SSD1306_SWITCHCAPVCC);
  display.clearDisplay();
}

void loop() {
  display.clearDisplay();
  display.display();
  delay(200);
  for (int y = 0; y <= 8; y++) {
    display.setTextSize(1);
    display.setTextColor(1);
    display.setCursor(0, (y * 8));
    display.println("012345678901234567890");
    display.display();
    delay(200);
  }
}

I used two libraries: Adafruit_GFX and Adafruit_SSD1306.

Regards,
Paul
 
Great! Thank you, Paul!

// hardware SPI on Teensy 3.1: MOSI pin 11, SCK pin 13 plus the pins defined below

That was the information I missed. 870 fps now when doing nothing. Awesome.

Best regards,

Stefan.
 
Last edited:
With this code I was able to write and display 8192 frames in 9495 milliseconds... 862fps! Teensy running at 96MHz.
Code:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// hardware SPI on Teensy 3.1: MOSI pin 11, SCK pin 13 plus the pins defined below
#define OLED_DC    9
#define OLED_SS   10
#define OLED_RST  14
Adafruit_SSD1306 display(OLED_DC, OLED_RST, OLED_SS);

unsigned long currtime;
unsigned long prevtime;

void setup() {
  display.begin(SSD1306_SWITCHCAPVCC);
  display.clearDisplay();

  Serial.begin(115200);
  while (!Serial);  // wait for serial monitor to be opened
}

void loop() {

  currtime = millis();
  Serial.println(currtime - prevtime);
  prevtime = currtime;

  display.clearDisplay();
  for (int y = 0; y <= 64; y++) {
    for (int x = 0; x <= 128; x++) {
      display.clearDisplay();
      display.drawPixel(x, y, 1);
      display.display();
    }
  }
}

Gruesse,
Paul
 
Hallo Stephan,

Which part of the video is 100fps and which part is 650fps? Or do I misunderstand the video?
I'm wondering whether smearing is caused by the display or by some other phenomenon.
There is a statement on tearing in the datasheet http://www.waveshare.com/w/upload/9/95/SSD1306.pdf, paragraph 8.4.

I wonder at what speed the display is actually updated from the Graphics Display Data RAM. We can write very fast to the GDDRAM, but if the display is updated slower, there is no need to write so fast...

Gruesse,
Paul

PS: just checked the datasheet: the default frame frequency is set at 107 Hz.
 
Last edited:
Hello, PaulS!

Which part of the video is 100fps and which part is 650fps? Or do I misunderstand the video?

The first animation runs at 100, the others between 450 and 650. The ones which scroll everything run at 650 fps both.

I'm wondering whether smearing is caused by the display or by some other phenomenon.

I think it´s mainly caused by the video camera which captures multiple display frames in one video frame.

There is a statement on tearing in the datasheet http://www.waveshare.com/w/upload/9/95/SSD1306.pdf, paragraph 8.4.

Unfortunately the FR pin is not available at these modules.

CL and CLS would also be interesting to speed things up. Unaccessible, too. :(

I wonder at what speed the display is actually updated from the Graphics Display Data RAM. We can write very fast to the GDDRAM, but if the display is updated slower, there is no need to write so fast...

Well, I´d say it´s fine to write fast, but useless to write too often. ;)

PS: just checked the datasheet: the default frame frequency is set at 107 Hz.

Interesting! Where did you find this information? Or did you calculate it like described on page 22?

When I write 0b11110000 to 0xD5 (oscillator frequency and clock divide ratio) it looks like 125 fps. At least 1/125 s is the perfect aperture time to take a photo. That seems to be the maximum so far.

Beste Grüße,

Stefan
 
Interesting! Where did you find this information? Or did you calculate it like described on page 22?

Yes, calculated it from that formula. The Adafruit_SSD1306 code writes 0x80 to 0xD5.
Code:
  ssd1306_command(SSD1306_SETDISPLAYCLOCKDIV);            // 0xD5
  ssd1306_command(0x80);                                  // the suggested ratio 0x80
Gruesse,
Paul
 
Status
Not open for further replies.
Back
Top