TCA9548A multiplexer

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
leversole
 
Posts: 8
Joined: Fri Jul 02, 2021 12:23 pm

TCA9548A multiplexer

Post by leversole »

I am having some difficulty using the TCA9548 with several OLED displays...on startup, the displays (2 for now) data is mixed up, that is one display gets the others data partially and vice-versa. Once the variables change, the displays work properly, just on startup. I tried moving the tcaselect into the functions, and added a small delay, neither of which helped. Any ideas?

I have included some relevant code

Code: Select all

#include <arduino.h>
#include <XPLDirect.h> 

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH1106.h>

#include <Fonts/FreeSans24pt7b.h> 
#include <Fonts/DSEG7_Classic_Italic_24.h>

#define OLED_RESET 4

#define TCAADDR 0x70

XPLDirect Xinterface(&Serial);

Adafruit_SH1106 display(OLED_RESET);
 
 long int altitudePre;
 long int beacon;
 long int avionicsSwitchOn;

 int masterOn = 0;
 int avionicsOn = 1;

 long int com1Freq;
 long int com1StandbyFreq;

 long int nav1Freq;
 long int nav1StandbyFreq;


 String Com1Standby = String("12170") ;
 String Com1Active = String("11820") ;
 String Com2Standby = String("12170") ;
 String Com2Active = String("11820") ;

 String nav1Standby = String("12170") ;
 String nav1Active = String("11820") ;
 String nav2Standby = String("12170") ;
 String nav2Active = String("11820") ;


// 'AltutudeBlank', 60x32px
const unsigned char myBitmap [] PROGMEM = {
  0xf8, 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe1, 0xf8, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0xc3, 0xf0, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87, 0xe1, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x0f, 0xc7, 0xe1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x0f, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x7e, 0x1f, 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3f, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0xf8, 0xfe, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe1, 0xf8, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0xc3, 0xf0, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87, 0xe1, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x0f, 0xc7, 0xe1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x8f, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x7e, 0x1f, 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0xf8, 0x7e, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf1, 0xfc, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0xc3, 0xf0, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87, 0xe1, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x0f, 0xc3, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x8f, 0xe3, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x7e, 0x1f, 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0xf8, 0x7e, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xfc, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0xe1, 0xf0, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87, 0xe1, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x0f, 0xc3, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x87, 0xe3, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x3f, 0x0f, 0xc7, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00
}; 

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
    
  Serial.begin(XPLDIRECT_BAUDRATE); 
  
  Xinterface.begin("XplaneUno");   

  display.begin(SH1106_SWITCHCAPVCC, 0x3C);

  Xinterface.registerDataRef("sim/cockpit/autopilot/altitude", XPL_READ, 100, 0, &altitudePre);  
  Xinterface.registerDataRef("sim/cockpit2/switches/beacon_on", XPL_READ, 100, 0, &beacon); 
  Xinterface.registerDataRef("sim/cockpit/electrical/avionics_on", XPL_READ, 100, 0, &avionicsSwitchOn); 

  Xinterface.registerDataRef("sim/cockpit/radios/com1_freq_hz", XPL_READ, 100, 0, &com1Freq); 
  Xinterface.registerDataRef("sim/cockpit/radios/com1_stdby_freq_hz", XPL_READ, 100, 0, &com1StandbyFreq); 

  Xinterface.registerDataRef("sim/cockpit/radios/nav1_freq_hz", XPL_READ, 100, 0, &nav1Freq); 
  Xinterface.registerDataRef("sim/cockpit/radios/nav1_stdby_freq_hz", XPL_READ, 100, 0, &nav1StandbyFreq); 
}

void tcaselect(uint8_t i) {
  if (i > 7) return;
 
  Wire.beginTransmission(TCAADDR);
  Wire.write(1 << i);
  Wire.endTransmission();  
}


void loop() {
  
  Xinterface.xloop();
  
  tcaselect(0);
  writeAltitude();

  tcaselect(1);
  nav1Display();

}



User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: TCA9548A multiplexer

Post by adafruit_support_bill »

Looks like you have only declared one instance of the display. So they will all be using the same display buffer.

User avatar
leversole
 
Posts: 8
Joined: Fri Jul 02, 2021 12:23 pm

Re: TCA9548A multiplexer

Post by leversole »

I think I understand...when I have already declared OLED_RESET as 4, when I create the instance I am really creating
Adafruit_SH1106 display(4), is this correct? If so, can I create another instance and call it display(1) for example?

When I write to each buffer, would I do it like...
display(1).setCursor(26, 55);
display(1).println(F("2935"));
display(1).setCursor(52, 55);

And
display(4).setCursor(26, 55);
display(4).println(F("2935"));
display(4).setCursor(52, 55);

OR should I just name it something that makes sense, like commDisplay, and navDisplay?

Thanks
Leslie

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: TCA9548A multiplexer

Post by adafruit_support_bill »

I think I understand...when I have already declared OLED_RESET as 4, when I create the instance I am really creating
Adafruit_SH1106 display(4), is this correct?
Not really. You are just creating a single display instance and telling it that pin 4 will perform the reset.

I'd create multiple display instances with names that make sense. You can probably share the reset pin if you want them all to reset at the same time

Code: Select all

Adafruit_SH1106 commDisplay(OLED_RESET);
Adafruit_SH1106 navDisplay(OLED_RESET);

User avatar
leversole
 
Posts: 8
Joined: Fri Jul 02, 2021 12:23 pm

Re: TCA9548A multiplexer

Post by leversole »

Thanks!

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”