-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does the library support multiplexers for the OLED modules? #158
Comments
Displays are managed through
For example (incomplete and untested) #include <Display/DisplayInterfaces/DisplayInterfaceSSD1306.hpp>
class MySSD1306_DisplayInterface : public SSD1306_DisplayInterface {
public:
MySSD1306_DisplayInterface(Adafruit_SSD1306 &display, uint8_t muxCh)
: SSD1306_DisplayInterface(display), muxCh(muxCh) {}
void begin() override {
selectMux();
// Initialize the Adafruit_SSD1306 display
if (!disp.begin())
FATAL_ERROR(F("SSD1306 allocation failed."), 0x1306);
// If you override the begin method, remember to call the super class method
SSD1306_DisplayInterface::begin();
}
void display() override {
selectMux();
SSD1306_DisplayInterface::display();
}
void drawBackground() override { disp.drawLine(1, 8, 126, 8, WHITE); }
private:
uint8_t muxCh;
void selectMux() {
// Implement this, use I2C to select the right multiplexer channel
Wire.write(...);
Wire.write(muxCh);
}
} display = ssd1306Display; In theory, only the |
I tried the above solution but nothing shows on display. I have tried adding Serial.print() to see whether it's selecting mux or not. But nothing works. Even tried differently initialisation
|
I don't have the necessary hardware to help you debugging, I only have a single I2C display, I always use SPI OLED displays for my projects. That being said, the first step should be to get this working without the Control Surface library. Use just the Adafruit library directly and maybe a library that controls the mux if it requires one, and do something extremely simple, like printing "1" to the first display, "2" to the second, etc., just enough to show that it's working. Once that's working, I can show you how to do the same thing using the Control Surface library. You might want to try using IO pins to drive the reset lines of the displays instead of using an RC circuit, it seems to be more reliable if you have multiple displays. First try a separate IO pin for the reset line of each OLED. The code you posted tries to initialize the displays twice, once in the Good luck! |
I have tried single initialisation too. I will remove Code for working display with mux
Sode for single display without a mux
|
In your code without Control Surface, you're calling display0.begin(SSD1306_SWITCHCAPVCC, 0x3C); But in your Control Surface code, you're calling it without any arguments: void begin() override {
selectMux();
// Initialize the Adafruit_SSD1306 display
if (!disp.begin()) // ← No arguments here
FATAL_ERROR(F("SSD1306 allocation failed."), 0x3C);
SSD1306_DisplayInterface::begin();
//SSD1306_DisplayInterface::begin(SSD1306_SWITCHCAPVCC, 0x3C);
} |
I tried this too. I am not sure it's a correct format or not.
|
I think the problem is that you forgot to call The following works for me (without a mux, both displays in the code draw to the same physical display): #include <Control_Surface.h> // Include the Control Surface library
// Include the display interface you'd like to use
#include <Display/DisplayInterfaces/DisplayInterfaceSSD1306.hpp>
// ----------------------------- MIDI Interface ----------------------------- //
USBMIDI_Interface midi;
// ----------------------------- Display setup ------------------------------ //
constexpr uint8_t SCREEN_WIDTH = 128;
constexpr uint8_t SCREEN_HEIGHT = 64;
constexpr int8_t OLED_reset = -1; // Use the external RC circuit for reset
// Instantiate the displays
Adafruit_SSD1306 ssd1306Display_L = {
SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_reset,
};
Adafruit_SSD1306 ssd1306Display_R = {
SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_reset,
};
constexpr uint8_t muxCh_L = 0; // multiplexer channel for Left Screen
constexpr uint8_t muxCh_R = 1; // multiplexer channel for Right Screen
// --------------------------- Display interface ---------------------------- //
class MySSD1306_DisplayInterface : public SSD1306_DisplayInterface {
public:
MySSD1306_DisplayInterface(Adafruit_SSD1306 &display, uint8_t muxCh)
: SSD1306_DisplayInterface(display), muxCh(muxCh) {}
void begin() override {
selectMux();
// Initialize the Adafruit_SSD1306 display
if (!disp.begin(SSD1306_SWITCHCAPVCC, 0x3C))
FATAL_ERROR(F("SSD1306 allocation failed."), 0x1306);
SSD1306_DisplayInterface::begin();
disp.setTextColor(WHITE);
disp.setTextSize(2);
}
void display() override {
selectMux();
SSD1306_DisplayInterface::display();
delay(2000); // slow down, easier to debug
}
void drawBackground() override {}
private:
uint8_t muxCh;
void selectMux() {
Wire.beginTransmission(0x70);
Wire.write(1 << muxCh);
Wire.endTransmission();
Serial.print("Selected mux:");
Serial.println(muxCh);
}
} display_L = {ssd1306Display_L, muxCh_L},
display_R = {ssd1306Display_R, muxCh_R};
// ---------------------------- Display Elements ---------------------------- //
// Simple display element that just prints some text
struct TestDisplayElement : DisplayElement {
TestDisplayElement(DisplayInterface &display, const char *message)
: DisplayElement(display), message(message) {}
void draw() override {
getDisplay().setCursor(8, 8);
getDisplay().print(message);
}
const char *message;
} dispElem_L = {display_L, "LEFT"},
dispElem_R = {display_R, "RIGHT"};
// --------------------------------- Setup ---------------------------------- //
void setup() {
Serial.begin(115200);
Wire.begin(); // This is important! Otherwise, you can't select the mux channel
Control_Surface.begin(); // Initialize Control Surface
}
// ---------------------------------- Loop ---------------------------------- //
void loop() {
Control_Surface.loop(); // Refresh all elements
} |
I knew it, it would be something small like that. Thank you so much. It's working now. |
Hello, sorry if this is not the right place to ask but I am wondering if the library supports multiplexers for the screens.
Such as a TCA9548A, basically to be able to use 4 SSD1306 OLED screens instead of 2 as used in the example.
The text was updated successfully, but these errors were encountered: