Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: how to define separate Wire for 2 SSD1306 OLED Display on Teensy 4.0

  1. #1
    Junior Member
    Join Date
    Feb 2020
    Posts
    2

    how to define separate Wire for 2 SSD1306 OLED Display on Teensy 4.0

    Hello,

    maybe simple question but....

    this is my source code:
    Code:
    #include <Wire.h>                     //OLED
    #include <Adafruit_SSD1306.h>         //OLED
    
    //OLED
    #define SCREEN_WIDTH 128
    #define SCREEN_HEIGHT 64
    
    int showoff = 1;
    
    Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
    Adafruit_SSD1306 display2(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
    
    void setup() {
      Serial.begin(115200);                                          
      if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {                
        Serial.println(F("OLED F"));                                 
        for(;;);                                                      
      }     
      if(!display2.begin(SSD1306_SWITCHCAPVCC, 0x3D)) {                
        Serial.println(F("OLED F"));                                 
        for(;;);                                                      
      }  
    
          display.clearDisplay();
          display.setTextSize(2);
          display.setCursor(1,0);
          display.setTextColor(SSD1306_WHITE);
          display.println(F("SCREEN 1"));
          display.display();
    
          display2.clearDisplay();
          display2.setTextSize(2);
          display2.setCursor(1,0);
          display2.setTextColor(SSD1306_WHITE);
          display2.println(F("SCREEN 2"));
          display2.display();
    
    
    }
    void loop() {
    
    }
    2 displays are already connected to 18/19 pins (SDA0/SCL0), now I want to connect 2 more displays and knowing fact that SSD1306 has only 2 addresses in selection I've figured out that I could get them connected to pins 17/16 (SDA1/SCL1)... but as I saw that need to be declared in setup (Wire.begin()). I'm fresh at this and little confused how to do it.

    Could someone help?

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    10,641
    All references for the displays on Wire1 17/16 would need to be done using Wire1 instead of Wire.

  3. #3
    Junior Member
    Join Date
    Feb 2020
    Posts
    2
    so it will work if I simply define this display as follows?

    Code:
    Adafruit_SSD1306 display3(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire1, -1);
    Adafruit_SSD1306 display4(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire1, -1);

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    10,641
    Indeed that should do it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •