Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
SSD1306 dual I2C display - can't write independently #923
I am running two SSD1306 128x64 OLEDs on a single I2C bus with separate addresses (0x3C and 0x3D). They work as listed in issue #434.
In this case, the intention is to write ABC to display-1 (left, I2C 0x3C), and DEF to display-2 (right, I2C 0x3D). It only works after I uncomment the dright.clearBuffer() line, but that should not be necessary. The right display gets the content from the left display as well, even though that wasn't intended.
After adding in debug code, I believe that drawing data updates always happen to both display buffers together instead of each individually. I added following serial line debugging code to see the data content of both buffers.
Serial debug output:
It looks as if writing data to either display updates both displays buffer content. Is there a way to separate the buffers to enable the displays to work fully independent? For larger code, a display only gets partially updated, and they can't be cleared together.
Just as reference, this is how I solved it: I simply made a 2nd copy of the original template, setup function, and buffer allocation function, and it worked right away. Not very elegant but simple and effective, especially at a 2:00 AM deadline
In C:\Users\root\Documents\Arduino\libraries\U8g2\src I updated the following four files: u8g2lib.h, u8g2.h, setup.cpp and u8g2_d_memory.c
The working Arduino code looks as follows:
The independent display updates now work like a charm. :-) Sensor data gets updated in each respective display, one display continuously runs the clock. Thanks @olikraus for the library!
P.S. For library update, I think adding another constructor type may be the way to go. The new constructor could add a display ID argument (e.g. 1..4). The setup function checks if that arg exists, and then calls further buffer allocation functions as needed. This would keep all existing code working exactly "as-is".