Project with 2 SSD1106/SSD1306 I2C-OLED on Teensy 3.6

Status
Not open for further replies.

Erich

Member
It works on the teensy 3.6 without Pullup-Resistors. Perhaps they are inside the OLED-Baords.
I use 2 cheap OLED-Boards with 4 Pins each, GND, VCC, SCL and SCA.
Both use the same I2C-Address but they use different I2C-Ports.

I thought that it is much more complex, but finally it was very easy to do.

Here is the code that works fine: ;) ;)


Code:
/**************************************************************************
Example to connect 2 I2C SSD1106-OLEDs to Teensy 3.6
Both OLEDs have the same size in my case 128x64 Pixels
 **************************************************************************/

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)

// Display 0 on PINs 18/19
Adafruit_SSD1306 dp0(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Display 1 on Pins 37/38
Adafruit_SSD1306 dp1(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire1, OLED_RESET);

void setup() {
  Serial.begin(9600);
  
  // Perhaps these lines are not needed, I have only tested with these
  Wire.setSDA(15);
  Wire.setSCL(19);
  Wire1.setSDA(37);
  Wire1.setSCL(38);

  if(!dp1.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 Display1 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }
  
  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!dp0.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 Display 0 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }

  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.
  dp0.display();
  delay(200); // Pause for 2 seconds
  dp0.clearDisplay();

  dp1.display();
  delay(200); // Pause for 2 seconds
  // Clear the buffer
  dp1.clearDisplay();

delay(1000);

  // Draw a single pixel in white
  dp0.drawPixel(10, 10, WHITE);
  dp1.drawPixel(10, 10, WHITE);

  // Show the display buffer on the screen. You MUST call display() after
  // drawing commands to make them visible on screen!
  dp0.display();
  dp1.display();
  delay(200);
  // display.display() is NOT necessary after every single drawing command,
  // unless that's what you want...rather, you can batch up a bunch of
  // drawing operations and then update the screen all at once by calling
  // display.display(). These examples demonstrate both approaches...


  testdrawchar();      // Draw characters of the default font

  testdrawstyles();    // Draw 'stylized' characters

  dp0.clearDisplay();
  dp1.clearDisplay();
}

void loop() {
}


void testdrawchar(void) {
  dp0.clearDisplay();
  dp0.setTextSize(1);      // Normal 1:1 pixel scale
  dp0.setTextSize(1);      // Normal 1:1 pixel scale
  dp0.setTextColor(WHITE); // Draw white text
  dp0.setCursor(0, 0);     // Start at top-left corner
  dp0.cp437(true);         // Use full 256 char 'Code Page 437' font

  // Not all the characters will fit on the display. This is normal.
  // Library will draw what it can and the rest will be clipped.
  for(int16_t i=0; i<256; i++) {
    if(i == '\n') dp0.write(' ');
    else          dp0.write(i);
  }

  dp0.display();
  delay(20);

  dp1.clearDisplay();
  dp1.setTextSize(1);      // Normal 1:1 pixel scale
  dp1.setTextSize(1);      // Normal 1:1 pixel scale
  dp1.setTextColor(WHITE); // Draw white text
  dp1.setCursor(0, 0);     // Start at top-left corner
  dp1.cp437(true);         // Use full 256 char 'Code Page 437' font

  // Not all the characters will fit on the display. This is normal.
  // Library will draw what it can and the rest will be clipped.
  for(int16_t i=0; i<256; i++) {
    if(i == '\n') dp1.write(' ');
    else          dp1.write(i);
  }

  dp1.display();
  delay(200);

}

void testdrawstyles(void) {

  // Change Display 0
  dp0.clearDisplay();

  dp0.setTextSize(1);             // Normal 1:1 pixel scale
  dp0.setTextColor(WHITE);        // Draw white text
  dp0.setCursor(0,0);             // Start at top-left corner
  dp0.println(F("Display 0 works!"));

  dp0.setTextColor(BLACK, WHITE); // Draw 'inverse' text
  dp0.println(3.141592);

  dp0.setTextSize(2);             // Draw 2X-scale text
  dp0.setTextColor(WHITE);
  dp0.print(F("0x")); 
  dp0.println(0xDEADBEEF, HEX);

  dp0.display();
  delay(200);


  // Same on Display 1
  dp1.clearDisplay();

  dp1.setTextSize(1);             // Normal 1:1 pixel scale
  dp1.setTextColor(WHITE);        // Draw white text
  dp1.setCursor(0,0);             // Start at top-left corner
  dp1.println(F("Display 1 works!"));

  dp1.setTextColor(BLACK, WHITE); // Draw 'inverse' text
  dp1.println(3.141592);

  dp1.setTextSize(2);             // Draw 2X-scale text
  dp1.setTextColor(WHITE);
  dp1.print(F("0x")); 
  dp1.println(0xDEADBEEF, HEX);

  dp1.display();
  delay(2000);
  
}
/*
void testdrawpot1(void) {
  // draw outer ring
  dp0.
  // draw marker on pot
  dp0.
  
}
*/

I dropped the code here because there where no running examples with code available.
Perhaps add this to the examples.
 
Last edited:
Status
Not open for further replies.
Back
Top