Sorry if this is the wrong spot, seemed like it could fit into several places.
Where to begin… This started on a nodeMCU and moved to a photon mostly because I’ve had a lot of trouble with reliability and consistency with the esp8266 platform and not to knock Adafruit (I love their stuff), but the ‘help’ I got there was a bit of a mix between dangling the carrot in front of the rabbit, and I’m doing something weird… go away. It didn’t help that I was getting frustrated and it turned into a rant (which I’ll try not to do here).
Anyhoot…
Details details… Particle Photon with an Adafruit TCA9548A and 3 (it was 4 till I cracked the screen on one) of the cheap-o i2c SSD1306 128x64 oled screens.
What works - a single screen. I was able to get 2 screen going on the esp8266 when I set their addresses (0x3C and 0x3D), but that gets me 2 screens - thus the muxer. I’m assuming the same will work with the photon, but the problem of more than 2 screens is still present, so I skipped from 1 screen straight to the muxer (is that even the right name?)
I can verify that each screen works (one of them is set to 0x3D, the others 0x3C).
I’ve beat my head against library imports as I’d been trying to bring in @rickkas7 's TCA9548-RK library (even created my own repo for it) but it was always complaining that I didn’t own the library - why that matters, I’m not sure since it was going to my private stuffs. In the end I gave up and just added the .h and .cpp files straight to the project.
I can scan the i2c bus and see both the TCA and the screens using the following (I actually was able to import @rickkas7 's library, but I had to change EVERY reference to -RK to -JJ to get it to stop complaining about ownership - otherwise it’s identical, at least as of today: TCA9548A-RK ):
#include <TCA9548A-JJ.h>
TCA9548A mux(Wire, 0);
byte error, address;
int nDevices;
void setup()
{
Serial.begin(115200);
mux.begin();
mux.setChannel(0);
delay(2000);
for(int i = 0; i < 8; i++)
{
mux.setChannel(i);
Serial.print("Channel: ");
Serial.println(i);
nDevices = 0;
for(address = 1; address < 127; address++ )
{
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknown error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
{
Serial.println("No I2C devices found\n");
}
else
{
Serial.println("done\n");
}
}
}
void loop()
{
}
A little borrowed code from somewhere… anyway, I get this (which seems correct - truncated everything after ch 2):
Channel: 0
I2C device found at address 0x3C !
I2C device found at address 0x70 !
done
Channel: 1
I2C device found at address 0x3D !
I2C device found at address 0x70 !
done
Channel: 2
I2C device found at address 0x3C !
I2C device found at address 0x70 !
done
I suspect I got the order wrong in some spot which is why 0x70 keeps showing up as its the address of the TCA board, but I didn’t bother fixing it as it told me what I needed to know - stuff’s there. On Adafruit’s site, they have some instructions that differ a bit from RK’s, but when I ran it it would put the Photon into SOS mode - with 5 flashes which I believe is essentially user error aka PEBKAC… couldn’t figure it out. I took the code from RK’s libs and some examples elsewhere (and have tried a variety of combos (this is already getting long so I’ll skip those bits unless they come up). Here’s the code I’ve simplified just to get something on the screen (which still doesn’t work):
#include <Adafruit_GFX.h>
#include "Adafruit_SSD1306.h"
#include "TCA9548A-RK.h"
TCA9548A mux(Wire, 0);
#define OLED_RESET D4
Adafruit_SSD1306 display0(OLED_RESET);
Adafruit_SSD1306 display1(OLED_RESET);
Adafruit_SSD1306 display2(OLED_RESET);
void setup()
{
Serial.begin(115200);
delay(2000);
Serial.println("Begin Mux");
mux.begin();
delay(1000);
Serial.println("mux begun");
Serial.println("Set Disp0");
mux.setChannel(0);
display0.begin(0x70);//3C?
display0.display();
delay(1500);
Serial.println("Set Disp1");
mux.setChannel(1);
display1.begin(0x70);//3D?
display1.display();
delay(1500);
Serial.println("Set Disp2");
mux.setChannel(2);
display2.begin(0x70);//3C?
display2.display();
delay(2000);
Serial.println("Displays set, doing stuff...");
doTheStuff();
Serial.println("Stuff done");
}
void doTheStuff()
{
Serial.println("Set Ch0, do stuff");
mux.setChannel(0);
display0.clearDisplay();
display0.setTextSize(2);
display0.setTextColor(BLACK, WHITE);
display0.setCursor(0,30);
display0.clearDisplay();
display0.println("Hello OLED");
display0.display();
Serial.println("Set Ch1, do stuff");
mux.setChannel(1);
display1.clearDisplay();
display1.setTextSize(2);
display1.setTextColor(BLACK, WHITE);
display1.setCursor(0,30);
display1.clearDisplay();
display1.println("Hello OLED");
display1.display();
Serial.println("Set Ch2, do stuff");
mux.setChannel(2);
display2.clearDisplay();
display2.setTextSize(2);
display2.setTextColor(BLACK, WHITE);
display2.setCursor(0,30);
display2.clearDisplay();
display2.println("Hello OLED");
display2.display();
Serial.println("Done with the stuff");
delay(2000);
}
void loop()
{
doTheStuff();
}
I don’t like using delays, but for the sake of testing I figured it’d be fine. I’m not sure if I’ve either misunderstood the syntax, or the addressing or what - I feel like I should have to specify the i2c address of the displays per channel as well, but the examples indicate otherwise (though I tried it anyway with no luck).
Regarding the Adafruit libs at the top, I added the SSD1306 lib to the project directly like I did with the TCA lib (i.e. in the tabs), but not the GFX lib - I added that the “normal” way. The reason being that I had tried the Adafruit_mfGFX lib first as it would appear to have more usage, but didn’t seem to change anything useful.
Anyway, I’m stuck. Sorry that was a lot, happy to provide more details if I missed something.