Oled I2C Custom pins lcdgfx library

Hello,
I'm working on a project which requires three SH1106 OLED Display. Because they have the same address, I need to use three I2C buses, and I would like to avoid adding more hardware to my project. I found that the lcdgfx library by lexus2k allows users to select SDA and SCL pins when a display object is created.
In order to test it, I simply modified one line of the SH1106 demo, which is provided with the library, to wire the display on other pins that the two default I2C pins on Arduino. Here is the line I changed : DisplaySH1106_128x64_I2C display(-1, {-1, 0x3C, 12, 13, 0});
With this code, the screen remains black. I think it has something to do with the busId parameter, but I don't know which value should be given since I work on Arduino. Here is the docs.

Does anyone have already used this library in a similar way ?

Hello,
I'm trying to use three SH1106 Oled Displays simultaneously, with different information on each display.
I've done some research and it appears that it's impossible to change the address of those displays. I would prefer to avoid using an I2C mux if a software solution is possible.

I'm using the Adafruit_SH110X library to control the displays (one by one), because I need to be able to draw shapes, not only strings. I tried many Software I2C libraries, but I can't create three different display objects associated to three different pairs of pins on the Arduino. I nearly always have an error when I'm calling the constructor of an Adafruit_SH1106G object : it requires a &Wire argument while I can only provide TwoWire, Softwire or any other object associated with the software I2C library that I try to use.

I thought about modifying existing libraries, but I don't have enough knowledge to be sure that it would work (and I also am not sure what to change exactly).

So, do you know any way to control three I2C displays that have the same address at the same time ?

IMO you'll need a library that supports multiple display objects and can switch between multiple displays on one or different bus systems. Looks quite exotic to me :frowning:

Use a software i²c library to create 2x extra i²c objects so you have 3x i²c objects in total, each using a different pair of pins. When creating the display objects, give each object one of the i²c objects.

There are drawbacks to this approach. Software i²c is slower than hardware, so those displays may update pretty slowly. Also with 3 display objects and 2 software i²c objects, you may run short of ram memory on Arduino based on atmega328 or similar.

This doesn't work, I get this error : no known conversion for argument 3 from 'SoftWire' to 'TwoWire*'

Here is the code :

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

#include <AsyncDelay.h>
#include <SoftWire.h>

#define i2c_Address 0x3c //initialize with the I2C addr 0x3C Typically eBay OLED's

SoftWire wire(13, 12);

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1   //   QT-PY / XIAO
Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, wire, OLED_RESET);



void setup() {
}

void loop() {
  display.println("test");
}

I've used a TCA9548A I2C Multiplexer to control three SSD1306 128x64 OLEDs.
Like so - TCA9548A I2C Multiplexer | The Pi Hut

I've been researching software i²c libraries and I'm coming to the conclusion that they are not going to work like we hoped.

The problem, I think, is the class structure. If "TwoWire" and "SoftWire" classes shared a common base class, and the Adafruit_SH1106G constructor would accept any object derived from that base class, it would work. But this just wasn't thought about when the classes were defined, I suspect.

So I think you may have to look at a hardware option.

One is the i²c multiplexer idea that you wanted to avoid.

Another is to choose an Arduino board with 3 i²c hardware ports. I think that, with some configuration of its SERCOM ports, an Arduino Zero compatible board based on SAMD21 chip might work.

Thanks for your answers. Using a I2C multiplexer would be the simplest option, but I've already done the CAD for my project and it would cost a bit more so I'm exploring all the software options.
I'm currently trying to use the lcdgfx library by lexus2k (GitHub - lexus2k/lcdgfx: Driver for LCD displays running on Arduino/Avr/ESP32/Linux (including Rasperry) platforms), which apparently allows the creation of a display object with custom SDA and SCL pins. I can't make it work for now, but I will create a new subject on the forum for that.

Anyway, thanks for your answers !

TOPIC MERGED.

Could you take a few moments to Learn and Use The Forum

It will help you get the best out of the forum in the future.

  • Your OS and version can be valuable information, please include it along with extra security you are using.

  • Always list the version of the IDE you are using and the board version if applicable.

  • Use quote or add error messages as an attachment NOT a picture.

  • How to insert an image into your post. ( Thanks @sterretje )

  • Add your sketch where applicable but please use CODE TAGS ( </> )

  • Add a SCHEMATIC were needed even if it is hand drawn

  • Add working links to any specific hardware as needed (NOT links to similar items)

  • Remember that the people trying to help cannot see your problem so give as much information as you can

COMMON ISSUES

  • Ensure you have FULLY inserted the USB cables.

  • Check you have a COMMON GROUND where required. ( Thanks @Perry)

  • Where possible use USB 2.0 ports or a USB 2.0 POWERED HUB to rule out USB 3.0 issues.

  • Try other computers where possible.

  • Try other USB leads where possible.

  • You may not have the correct driver installed. CH340/341 or CP2102 or FT232 VCP Drivers - FTDI

  • There may be a problem with the board check or remove your wiring first.

  • Remove any items connected to pins 0 and 1.

COMPUTER RELATED

  • Close any other serial programs before opening the IDE.

  • Ensure you turn off any additional security / antivirus just to test.

  • There may be a problem with the PC try RESTARTING it.

  • You may be selecting the wrong COM port.

  • Avoid cloud/network based installations where possible OR ensure your Network/Cloud software is RUNNING.

  • Clear your browsers CACHE.

  • Close the IDE before using any other serial programs.

  • Preferably install IDE’s as ADMINISTRATOR or your OS equivalent

ARDUINO SPECIFIC BOARDS

  • CH340/341 based clones do not report useful information to the “get board info” button.

  • NANO (Old Types) some require you to use the OLD BOOTLOADER option.

  • NANO (ALL Types) See the specific sections lower in the forum.

  • NANO (NEW Types) Install your board CORE’s.

  • Unless using EXTERNAL PROGRAMMERS please leave the IDE selection at default “AVRISP mkII”.

  • Boards using a MICRO usb connector need a cable that is both DATA and CHARGE. Many are CHARGE ONLY.

CREATE editor install locations.

  • On macOs ~/Applications/ArduinoCreateAgent-1.1/ArduinoCreateAgent.app/Contents/MacOS/config.ini

  • On Linux ~/ArduinoCreateAgent-1.1/config.ini

  • On Windows C:\Users[your user]\AppData\Roaming\ArduinoCreateAgent-1.1

Performing the above actions may help resolve your problem without further help.

Language problem ?

Try a language closer to your native language:

Thanks to all those who helped and added to this list.

If you post a link to the actual display(s) that you have bought, readers can offer accurate advice.

SH1106 can use 0x3C or 0x3D as Slave address. Only good for two displays.

  1. switch the 0x3D enable pin in software (if accessible). i.e only have one display with 0x3C at any one time.
  2. external multiplexer chip.
  3. combination e.g. HW 0x3C, HW 0x3D, SW 0x3C

Some libraries use large buffers for each display. A Uno has only got 2kB SRAM.

David.

There are several solutions.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.