four OLED displays with 2 i2c ports and u8g2lib

Status
Not open for further replies.

lokki

Well-known member
hi there,

i would like to have four small 128x64 OLED displays connected to my teensy 4.0 i was hoping to use i2c port 0 and 1 for that. since these cheap OLED displays can only change address from 0x7C to 0X7D i can have a maximum of two per bus.

there is a quite nice library by oli kraus, which i used in the past on an arduino (uno). apparently there is an issue with enumerating the i2c devices with teensy (as his library depends on this enumeration to talk to the 2nd hw port) here is the issue: https://github.com/olikraus/u8g2/issues/1175

i tried replacing wire.h with the teensy i2ct3.h in the library but then i get the following error in compilation:

Code:
/Arduino/libraries/U8g2_Arduino-master/src/U8x8lib.cpp:977:7: error: 'Wire' was not declared in this scope
       Wire.write((uint8_t *)arg_ptr, (int)arg_int);
       ^

so it seems i2c_t3 is not a drop in replacement.

has anybody used more then two of these ssh1106 or ssd1306 displays on a teensy 4 with two i2c ports?
it would be nice to use the u8g2lib but i am willing to use another library as well.
 
If it were me, I would try out the Adafruit library: Adafruit_SSD1306 and see if it works for you...

In theory you should be able to do something like:
Code:
#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     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_SSD1306 display2(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_SSD1306 display3(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire1, OLED_RESET);
Adafruit_SSD1306 display4(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire1, OLED_RESET);

...

void setup() {

...
  display.begin(SSD1306_SWITCHCAPVCC, 0x3D); // Address 0x3D for 128x64
  display2.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3D for 128x64
  display3.begin(SSD1306_SWITCHCAPVCC, 0x3D); // Address 0x3D for 128x64
  display4.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3D for 128x64
...
Again I have not tried some of this stuff in awhile, but hopefully that works.

As for changing from Wire to I2C_t3... Not sure if he ever completed a version that works on T4. Also you can not mix the two libraries in the same sketch...
 
If it were me, I would try out the Adafruit library: Adafruit_SSD1306 and see if it works for you...

In theory you should be able to do something like:
Code:
#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     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_SSD1306 display2(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_SSD1306 display3(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire1, OLED_RESET);
Adafruit_SSD1306 display4(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire1, OLED_RESET);

...

void setup() {

...
  display.begin(SSD1306_SWITCHCAPVCC, 0x3D); // Address 0x3D for 128x64
  display2.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3D for 128x64
  display3.begin(SSD1306_SWITCHCAPVCC, 0x3D); // Address 0x3D for 128x64
  display4.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3D for 128x64
...
Again I have not tried some of this stuff in awhile, but hopefully that works.

As for changing from Wire to I2C_t3... Not sure if he ever completed a version that works on T4. Also you can not mix the two libraries in the same sketch...

thanks for your answer... unfortunately 3 out of 4 displays use the sh1106 chip, which does not seem to be supported by this lib. i have found an adaption somewhere will check that as well. who is "he"? paul?
 
As for changing from Wire to I2C_t3... Not sure if he ever completed a version that works on T4. Also you can not mix the two libraries in the same sketch...

thanks for that as well. i found a i2c_driver_wire implementation for teensy 4 which acts as a drop-in replacement for wire.h, with that and a couple of changes to the u8g2lib it works!!! (change every instance of wire.h to i2c_driver_wire.h and disable the checking for number of i2c ports, since the teensy board config does not contain/promote them)
 
Status
Not open for further replies.
Back
Top