Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

TCA9548A ISSUE? OR CODE ISSUE?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

TCA9548A ISSUE? OR CODE ISSUE?

by 09ZX6R on Fri Apr 03, 2020 2:17 am

So iv been going out of my mind trying to figure this out, iv had 2 other arduino coders (amateur at best) go over it, and the code verifies with no errors!! i have 2 oled displays (128x64 1.3") connected to a TCA9548A on the sd0/sc0 and sd1/sc1 bus lines.. i have the multiplexer connected to an UNO via sda and scl on a4 & a5.. power and grounds are all shared..(see pic attached)
this issue i have is that 1 screen will show all the data requested on bus SD1/SC1 but the screen on SD0/SC0 shows only a white screen... i checked wiring, and the code at least 20Xs and even swapped the screens, made no difference...can anyone go thru my code and tell me what i screwed up ? or is it a hardware issue ? also if it can be made simpler, please advise....
Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH1106.h>

#if (SH1106_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SH1106.h!");
#endif

#define OLED_RESET 4

// Create an object for each OLED display
Adafruit_SH1106 display0(OLED_RESET);
Adafruit_SH1106 display1(OLED_RESET);


//-------------------TPS data begin -------------------------
const float referenceVolts = 5.0;        // the default reference on a 5 volt board
const int TPSPin = A0;                // signal from Sensor is connected to analog pin 0
float battv;                             // floated for decimal useage
float percent;                           // floated for decimal useage
int TPSMin = 95;
int TPSMax = 950;
//----------------------END TPS data-------------------------------

//---------------------boost data begin----------------------------
const int BoostPin = A1;                //reads from analog input pin 1
const float ReferenceVolts = 5.0;   // the default reference on a 5 volt board
float PSI;
float Volts;
int BoostMin = 0;   // change this to adjust low reading   // integer of sensed voltage
int BoostMax = 1023;  // change this to adjust high reading   // integer of sensed voltage
                      // use the serial monitor to get sensor integers
//----------------------END boost data------------------------------------


void TCA9548A(uint8_t bus)       //multiplexer commanded to transmit
{
  Wire.beginTransmission(0x70);  // TCA9548A address is 0x70
  Wire.write(1 << bus);          // send byte to select bus
  Wire.endTransmission();
}
void setup()
{
  //Serial.begin(9600);  // initialize serial communication at 9600 bits per second:

  Wire.begin();  // Start Wire library for I2C
 
  // Set multiplexer to channel 0 and initialize OLED-0 with I2C addr 0x3C
  TCA9548A(0);
  display0.begin(SH1106_SWITCHCAPVCC, 0x3C);

  // Set multiplexer to channel 1 and initialize OLED-1 with I2C addr 0x3C
  TCA9548A(1);
  display1.begin(SH1106_SWITCHCAPVCC, 0x3C);
 
  display0.display();   // turns off splash screen when commented out
  delay(4000);
 
  display1.display();   // turns off splash screen when commented out
  delay(4000);

  // Clear the buffer.
  display0.clearDisplay();
  display1.clearDisplay();

  // boot TPS text display
  display0.setTextSize(2);
  display0.setTextColor(WHITE);
  display0.setCursor(45, 0);
  display0.println("TPS");
  display0.setCursor(5, 18);
  display0.println("MONITOR v1");
  display0.setTextSize(1);
  display0.setTextColor(WHITE);
  display0.setCursor(0, 50);
  display0.println("By Johnathan Oey");
  display0.display();
  delay (4000);

  //  Clear the buffer.
  display0.clearDisplay();

  // boot BOOST text display
  display1.setTextSize(2);
  display1.setTextColor(WHITE);
  display1.setCursor(10, 0);
  display1.println("BOOST PSI");
  display1.setTextSize(1);
  display1.setCursor(40, 18);
  display1.println("MONITOR v1");
  display1.setCursor(0, 50);
  display1.println("By Johnathan Oey");
  display1.display();
  delay (4000);

  //  Clear the buffer.
  display1.clearDisplay();
}

void loop()
{
  /* DIAGNOSTICS section is for value reading only.
     comment out this section and line 22 when diagnostics are done. */
 
            // DIAGNOSTICS
//  int sensorValue = analogRead(A0);              // read the input on analog pin 0
//  Serial.print ("Integer Value ");               // print out the values name on the serial monitor
//  Serial.println(sensorValue);                   // print out the value you read on the serial monitor as an integer
//
//  float voltage = sensorValue * (5.0 / 1023.0);  // convert the analog reading to a voltage
//  Serial.print ("volts ");                       // print out the values name on the serial monitor
//  Serial.println(voltage);                       // print out the value you read on the serial monitor in volts
//  delay(500);                                    // delay in between reads for stability
            // END OF DIAGNOSTICS

  // text TPS display
  display0.setTextSize(1);
  display0.setTextColor(WHITE);
  display0.setCursor(32, 0);
  display0.println("TPS MONITOR");
  display0.setCursor(0, 14);
  display0.println("Volts");
  display0.setCursor(0, 30);
  display0.println("Percent");
  display0.display();

  checkbatt();
  display0.setTextSize(2);
  display0.setTextColor(WHITE, BLACK);
  display0.setCursor(40, 10);
  display0.print (battv);
  display0.println("v");

  Percent();
  display0.setTextSize(3);
  display0.setTextColor(WHITE, BLACK);
  display0.setCursor(35, 40);
  display0.print (percent, 0);
  display0.println(" % ");
//----------------END TPS---------------

// text BOOST display
  display1.setTextSize(2);
  display1.setTextColor(WHITE);
  display1.setCursor(35, 0);
  display1.println("BOOST");
  display1.display();

  Pressure();
  display1.setTextSize(3);
  display1.setTextColor(WHITE, BLACK);
  display1.setCursor(20, 35);
  display1.print(PSI);
  display1.setTextSize(2);
  display1.setCursor(92, 40);
  display1.print("psi");
//---------------END BOOST-----------------
}

void checkbatt()
{
  battv = (analogRead(TPSPin) / 1023.0) * referenceVolts;           // read the value from A0 Sensor monitoring pin
                                                                       // Divides by 1023 to get an integer, then multiplies by the ref voltage.
}
void Percent()
{
  percent = map(analogRead(TPSPin), TPSMin, TPSMax, 0, 100);            // reconfigures the voltage low and high readings at pin A0 to be integer percent(%) from 0 - 100%
}
void Pressure()
{
  Volts = (analogRead (BoostPin) / 1023.0) * ReferenceVolts;                 // read the value from A1 Sensor monitoring pin
                                                                             // Divides by 1023 to get an integer, then multiplies by the ref voltage.
  PSI = map(analogRead(BoostPin), BoostMin, BoostMax, 0, 14.7);            // reconfigures the voltage low and high readings at pin A1 to be actual boost readings
}
Attachments
TCA9548A WIRED.png
TCA9548A WIRED.png (14.47 KiB) Viewed 38 times

09ZX6R
 
Posts: 12
Joined: Wed Oct 28, 2015 4:20 am

Re: TCA9548A ISSUE? OR CODE ISSUE?

by adafruit_support_bill on Fri Apr 03, 2020 5:30 am

The last call you make to your TCA9548A() function is in setup. And that is to select channel 1. Since you never change it again, all of your display output will be directed to channel 1.

adafruit_support_bill
 
Posts: 78633
Joined: Sat Feb 07, 2009 10:11 am

Re: TCA9548A ISSUE? OR CODE ISSUE?

by 09ZX6R on Fri Apr 03, 2020 11:25 am

ok i see that now,

but how to do i make the multiplexer call both screens all the time? seems like i can only call one at a time? every code iv found out there shows 2 or more oleds displaying info from 1 sensor. so they call the channel fot the sensor then display split data on 2 screens..
my setup is 1 potentiometer reading on 1 screen as well as a 2nd potentiometer reading on a 2nd screen both running non stop..

09ZX6R
 
Posts: 12
Joined: Wed Oct 28, 2015 4:20 am

Re: TCA9548A ISSUE? OR CODE ISSUE?

by adafruit_support_bill on Fri Apr 03, 2020 11:36 am

To talk to a device, you need to enable the multiplexer channel that the device is connected to. Normally, you would select one device at a time.

If you want to talk to multiple channels at the same time, you need to enable both channels on the multiplexer. Keep in mind that this is not guaranteed to work with all devices since i2c is a serial protocol and the devices may not respond with exactly the same data or with the same timing.

Multiplexer channel selection is a simple 8-bit bitmap, with the low order bit corresponding to channel 0. To enable all channels, you can write 0xFF. To enable just channels 0 and 1 you would write 0x03.

https://cdn-shop.adafruit.com/datasheets/tca9548a.pdf

adafruit_support_bill
 
Posts: 78633
Joined: Sat Feb 07, 2009 10:11 am

Re: TCA9548A ISSUE? OR CODE ISSUE?

by 09ZX6R on Fri Apr 03, 2020 12:22 pm

ok how and where do i write that into the code?

09ZX6R
 
Posts: 12
Joined: Wed Oct 28, 2015 4:20 am

Re: TCA9548A ISSUE? OR CODE ISSUE?

by 09ZX6R on Mon Apr 06, 2020 8:49 pm

ok so i rewrote the code and by doing so i now get both screens to display.. however, they dont do the correct functions.. by that i mean, they are both supposed to show a bootup screen but only 1 will.. then they are both to show some version information, but only 1 will, then the 2nd screen will suddenly show all the data at the same time that both screens are supposed to individually have and then the 1st screen will do the same...so now, i have 2 screens showing the same info and its overlaying all the info..

in the progression of how it should be
screen 1 & 2 == show bootup screen
screen 1 & 2 == show version info
screen 1 == show specific data to TPS
screen 2== show specific data to BOOST

screen 1 == known as display0
screen 2== known as display1

all connections show to be correct and working since the multiplexer is now turning on channel 0 and 1.. but the info is not displaying correctly...

thoughts?

before, the code i posted only allowed 1 channel on the multiplexer to work... so i fixed that.. so heres the new code...
please be kind, im new to coding and this has been a long learning curve for me as i have no real help..

Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>             //i2c library
#include <Adafruit_GFX.h>     // graphics library
#include <Adafruit_SH1106.h>  //oled library

#if (SH1106_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SH1106.h!");
#endif

#define OLED_RESET 4

// Create an object for each OLED display
Adafruit_SH1106 display0(OLED_RESET);
Adafruit_SH1106 display1(OLED_RESET);

void TCA9548A(uint8_t bus)
{
  Wire.beginTransmission(0x70);  // TCA9548A address is 0x70
  Wire.write(1 << bus);          // send byte to select bus
  Wire.endTransmission();
}
void displayBatt(float battv) {
  display0.setTextSize(2);
  display0.setTextColor(WHITE, BLACK);
  display0.setCursor(40, 10);
  display0.print (battv);
  display0.println("v");
}
void displayPercent(float percent){
  display0.setTextSize(3);
  display0.setTextColor(WHITE, BLACK);
  display0.setCursor(35, 40);
  display0.print (percent, 0);
  display0.println(" % ");
}
//-------------------TPS data begin -------------------------
const float referenceVolts = 5.0;        // the default reference on a 5 volt board
const int TPSPin = A0;                   // signal from Sensor is connected to analog pin 0
int TPSMin = 95;
int TPSMax = 950;
//----------------------END TPS data-------------------------------
//-----------------------START BOOST DATA----------------------------
void displayBoost(float PSI) {
  display1.setTextSize(2);
  display1.setTextColor(WHITE, BLACK);
  display1.setCursor(40, 10);
  display1.print (PSI);
  display1.println("psi");
}
const int BoostPin = A1;                //reads from analog input pin 1
const float ReferenceVolts = 5.0;   // the default reference on a 5 volt board
int BoostMin = 0;   // change this to adjust low reading   // integer of sensed voltage
int BoostMax = 1023;  // change this to adjust high reading   // integer of sensed voltage
// use the serial monitor to get sensor integers
//----------------------END boost data------------------------------------

void setup()
{
  Wire.begin();  // Start Wire library for I2C

  // Set multiplexer to channel 0 and initialize OLED-0 with I2C addr 0x3C
  TCA9548A(0);
  display0.begin(SH1106_SWITCHCAPVCC, 0x3C);
  display0.display();   // turns off splash screen when commented out
  delay(4000);
  display0.clearDisplay();   // Clear the buffer.
 
  // Set multiplexer to channel 1 and initialize OLED-1 with I2C addr 0x3C
  TCA9548A(1);
  display1.begin(SH1106_SWITCHCAPVCC, 0x3C);
  display1.display();   // turns off splash screen when commented out
  delay(4000);
  display1.clearDisplay();
 
     // boot TPS text display
  display0.setTextSize(2);
  display0.setTextColor(WHITE);
  display0.setCursor(45, 0);
  display0.println("TPS");
  display0.setCursor(5, 18);
  display0.println("MONITOR v1");
  display0.setTextSize(1);
  display0.setTextColor(WHITE);
  display0.setCursor(0, 50);
  display0.println("By Johnathan Oey");
  display0.display();
  delay (3000);

  //  Clear the buffer.
  display0.clearDisplay();

  // boot BOOST text display
  display1.setTextSize(2);
  display1.setTextColor(WHITE);
  display1.setCursor(10, 0);
  display1.println("BOOST PSI");
  display1.setTextSize(1);
  display1.setCursor(40, 18);
  display1.println("MONITOR v1");
  display1.setCursor(0, 50);
  display1.println("By Johnathan Oey");
  display1.display();
  delay (3000);

  //  Clear the buffer.
  display1.clearDisplay();
}
void loop()
{
  // text TPS display
  display0.setTextSize(1);
  display0.setTextColor(WHITE);
  display0.setCursor(32, 0);
  display0.println("TPS MONITOR");
  display0.setCursor(0, 14);
  display0.println("Volts");
  display0.setCursor(0, 30);
  display0.println("Percent");
  display0.display();

  float battv = (analogRead(TPSPin) / 1023.0) * referenceVolts;           // read the value from A0 Sensor monitoring pin
  // Divides by 1023 to get an integer, then multiplies by the ref voltage.
  float Percent = map(analogRead(TPSPin), TPSMin, TPSMax, 0, 100);            // reconfigures the voltage low and high readings at pin A0 to be integer percent(%) from 0 - 100%

TCA9548A(0);
  displayBatt(battv);
  displayPercent(Percent);
  display0.display();

// text BOOST display
  display1.setTextSize(2);
  display1.setTextColor(WHITE);
  display1.setCursor(35, 0);
  display1.println("BOOST");
  display1.display();

  float PSI = map(analogRead(BoostPin), BoostMin, BoostMax, 0, 14.7);
 
  TCA9548A(1);
  displayBoost(PSI);
  display1.display();
 }

09ZX6R
 
Posts: 12
Joined: Wed Oct 28, 2015 4:20 am

Re: TCA9548A ISSUE? OR CODE ISSUE?

by adafruit_support_bill on Mon Apr 06, 2020 9:19 pm

To talk to a device, you need to select the multiplexer channel that the device is connected to. The code above does some switching of channels. But not everywhere that it needs to. So display0 output is sometimes directed to channel 1 and display1 output is sometimes directed to channel 0.

Starting with your setup code:
This code selects channel zero and initializes display0.
Code: Select all | TOGGLE FULL SIZE
  // Set multiplexer to channel 0 and initialize OLED-0 with I2C addr 0x3C
  TCA9548A(0);
  display0.begin(SH1106_SWITCHCAPVCC, 0x3C);
  display0.display();   // turns off splash screen when commented out
  delay(4000);
  display0.clearDisplay();   // Clear the buffer.

And this code does the same for channel1 & display1
Code: Select all | TOGGLE FULL SIZE
  // Set multiplexer to channel 1 and initialize OLED-1 with I2C addr 0x3C
  TCA9548A(1);
  display1.begin(SH1106_SWITCHCAPVCC, 0x3C);
  display1.display();   // turns off splash screen when commented out
  delay(4000);
  display1.clearDisplay();


But here you are trying to write to display0 while the multiplexer is still on channel 1:
Code: Select all | TOGGLE FULL SIZE
 
     // boot TPS text display
  display0.setTextSize(2);
  display0.setTextColor(WHITE);
  display0.setCursor(45, 0);
  display0.println("TPS");
  display0.setCursor(5, 18);
  display0.println("MONITOR v1");
  display0.setTextSize(1);
  display0.setTextColor(WHITE);
  display0.setCursor(0, 50);
  display0.println("By Johnathan Oey");
  display0.display();
  delay (3000);

  //  Clear the buffer.
  display0.clearDisplay();


Moving on to your loop code, you start writing to display0 without selecting a channel on the multiplexer. Channel 1 is the last one selected in both setup and in previous iterations of the loop, so you are actually writing to channel 1.
Code: Select all | TOGGLE FULL SIZE
  // text TPS display
  display0.setTextSize(1);
  display0.setTextColor(WHITE);
  display0.setCursor(32, 0);
  display0.println("TPS MONITOR");
  display0.setCursor(0, 14);
  display0.println("Volts");
  display0.setCursor(0, 30);
  display0.println("Percent");
  display0.display();


Then here you select channel 0 and write to display0. But go on to write to display1 without first changing back to channel 1:
Code: Select all | TOGGLE FULL SIZE
TCA9548A(0);
  displayBatt(battv);
  displayPercent(Percent);
  display0.display();

// text BOOST display
  display1.setTextSize(2);
  display1.setTextColor(WHITE);
  display1.setCursor(35, 0);
  display1.println("BOOST");
  display1.display();


Finally, you select channel 1 and write to display1 again.
Code: Select all | TOGGLE FULL SIZE
  TCA9548A(1);
  displayBoost(PSI);
  display1.display();

So channel 1 is still selected when you enter the loop again.

adafruit_support_bill
 
Posts: 78633
Joined: Sat Feb 07, 2009 10:11 am

Re: TCA9548A ISSUE? OR CODE ISSUE?

by adafruit_support_bill on Mon Apr 06, 2020 9:24 pm

If your display uses an in-memory frame buffer, and you want to replicate the exact same thing to both, you can simplify things by only creating one display instance. Then you can perform all of your printing to the common buffer and only change the multiplexer channel for the calls to display();

Code: Select all | TOGGLE FULL SIZE
     // boot TPS text display
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(45, 0);
  display.println("TPS");
  display.setCursor(5, 18);
  display.println("MONITOR v1");
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 50);
  display.println("By Johnathan Oey");
  // display on channel 0
  TCA9548A(0);
  display.display();
  // and the same thing on channel 1
  TCA9548A(1);
  display.display();

adafruit_support_bill
 
Posts: 78633
Joined: Sat Feb 07, 2009 10:11 am

Re: TCA9548A ISSUE? OR CODE ISSUE?

by 09ZX6R on Mon Apr 06, 2020 9:43 pm

ok so if im understanding you correctly, i need to call the channel before commanding something to display for each display.. and i have to do that for every command to display?

09ZX6R
 
Posts: 12
Joined: Wed Oct 28, 2015 4:20 am

Re: TCA9548A ISSUE? OR CODE ISSUE?

by 09ZX6R on Tue Apr 07, 2020 1:59 am

as for the in frame memory, i dont know.. its a standard OLED.. just like the SSD1306 OLEDs but older.. (SH1106) chip.

im tryin to reconfigure the code,, but its not working out..
i try calling the channel before each section of command, but it made no difference..

09ZX6R
 
Posts: 12
Joined: Wed Oct 28, 2015 4:20 am

Re: TCA9548A ISSUE? OR CODE ISSUE?

by adafruit_support_bill on Tue Apr 07, 2020 6:21 am

ok so if im understanding you correctly, i need to call the channel before commanding something to display for each display.. and i have to do that for every command to display?

Yes. You can't send a command to a device unless its channel is selected on the multiplexer.

as for the in frame memory, i dont know.. its a standard OLED.. just like the SSD1306 OLEDs but older.. (SH1106) chip.

The SSD1306 uses a 1K in-memory frame buffer.

i try calling the channel before each section of command, but it made no difference..

Please post your current code and describe the symptoms precisely.

adafruit_support_bill
 
Posts: 78633
Joined: Sat Feb 07, 2009 10:11 am

Re: TCA9548A ISSUE? OR CODE ISSUE?

by 09ZX6R on Tue Apr 07, 2020 10:57 pm

Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>             //i2c library
#include <Adafruit_GFX.h>     // graphics library
#include <Adafruit_SH1106.h>  //oled library

#if (SH1106_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SH1106.h!");
#endif

#define OLED_RESET 4

// Create an object for each OLED display
Adafruit_SH1106 display0(OLED_RESET);
Adafruit_SH1106 display1(OLED_RESET);

void TCA9548A(uint8_t bus)
{
  Wire.beginTransmission(0x70);  // TCA9548A address is 0x70
  Wire.write(1 << bus);          // send byte to select bus
  Wire.endTransmission();
}
void displayBatt(float battv) {
  display0.setTextSize(2);
  display0.setTextColor(WHITE, BLACK);
  display0.setCursor(40, 10);
  display0.print (battv);
  display0.println("v");
}
void displayPercent(float percent){
  display0.setTextSize(3);
  display0.setTextColor(WHITE, BLACK);
  display0.setCursor(35, 40);
  display0.print (percent, 0);
  display0.println(" % ");
}
//-------------------TPS data begin -------------------------
const float referenceVolts = 5.0;        // the default reference on a 5 volt board
const int TPSPin = A0;                   // signal from Sensor is connected to analog pin 0
int TPSMin = 95;
int TPSMax = 950;
//----------------------END TPS data-------------------------------
//-----------------------START BOOST DATA----------------------------
void displayBoost(float PSI) {
  display1.setTextSize(2);
  display1.setTextColor(WHITE, BLACK);
  display1.setCursor(40, 10);
  display1.print (PSI);
  display1.println("psi");
}
const int BoostPin = A1;                //reads from analog input pin 1
const float ReferenceVolts = 5.0;   // the default reference on a 5 volt board
int BoostMin = 0;   // change this to adjust low reading   // integer of sensed voltage
int BoostMax = 1023;  // change this to adjust high reading   // integer of sensed voltage
// use the serial monitor to get sensor integers
//----------------------END boost data------------------------------------

void setup()
{
  Wire.begin();  // Start Wire library for I2C

  // Set multiplexer to channel 0 and initialize OLED-0 with I2C addr 0x3C
  TCA9548A(0);
  display0.begin(SH1106_SWITCHCAPVCC, 0x3C);
  display0.display();   // turns off splash screen when commented out
  delay(4000);
  display0.clearDisplay();   // Clear the buffer.
 
  // Set multiplexer to channel 1 and initialize OLED-1 with I2C addr 0x3C
  TCA9548A(1);
  display1.begin(SH1106_SWITCHCAPVCC, 0x3C);
  display1.display();   // turns off splash screen when commented out
  delay(4000);
  display1.clearDisplay();

  TCA9548A(0);
      // boot TPS text display
  display0.setTextSize(2);
  display0.setTextColor(WHITE);
  display0.setCursor(45, 0);
  display0.println("TPS");
  display0.setCursor(5, 18);
  display0.println("MONITOR v1");
  display0.setTextSize(1);
  display0.setTextColor(WHITE);
  display0.setCursor(0, 50);
  display0.println("By Johnathan Oey");
  display0.display();
  delay (3000);

  //  Clear the buffer.
  display0.clearDisplay();

  TCA9548A(1);
  // boot BOOST text display
  display1.setTextSize(2);
  display1.setTextColor(WHITE);
  display1.setCursor(10, 0);
  display1.println("BOOST PSI");
  display1.setTextSize(1);
  display1.setCursor(40, 18);
  display1.println("MONITOR v1");
  display1.setCursor(0, 50);
  display1.println("By Johnathan Oey");
  display1.display();
  delay (3000);

  //  Clear the buffer.
  display1.clearDisplay();
}
void loop()
{
  TCA9548A(0);
  // text TPS display
  display0.setTextSize(1);
  display0.setTextColor(WHITE);
  display0.setCursor(32, 0);
  display0.println("TPS MONITOR");
  display0.setCursor(0, 14);
  display0.println("Volts");
  display0.setCursor(0, 30);
  display0.println("Percent");
  display0.display();

  float battv = (analogRead(TPSPin) / 1023.0) * referenceVolts;           // read the value from A0 Sensor monitoring pin
  // Divides by 1023 to get an integer, then multiplies by the ref voltage.
  float Percent = map(analogRead(TPSPin), TPSMin, TPSMax, 0, 100);            // reconfigures the voltage low and high readings at pin A0 to be integer percent(%) from 0 - 100%

  TCA9548A(0);
  displayBatt(battv);
  displayPercent(Percent);
  display0.display();

  TCA9548A(1);
// text BOOST display
  display1.setTextSize(2);
  display1.setTextColor(WHITE);
  display1.setCursor(35, 0);
  display1.println("BOOST");
  display1.display();

  float PSI = map(analogRead(BoostPin), BoostMin, BoostMax, 0, 14.7);
 
  TCA9548A(1);
  displayBoost(PSI);
  display1.display();
 }


as for the symptoms, its the same as before. nothing changed

aslo i tried to do the suggestion of using the memory frame buffer to display the same info to both screens but it didnt work.. not sure if i didnt call it correctly or what but i went back to the code above till i can get it to communicate correctly, then ill tackle that idea.

09ZX6R
 
Posts: 12
Joined: Wed Oct 28, 2015 4:20 am

Re: TCA9548A ISSUE? OR CODE ISSUE?

by adafruit_support_bill on Wed Apr 08, 2020 6:10 am

The multiplexer logic looks OK now. But you are not clearing the buffers between iterations of the loop, so you will probably have new data overwriting the old.

adafruit_support_bill
 
Posts: 78633
Joined: Sat Feb 07, 2009 10:11 am

Re: TCA9548A ISSUE? OR CODE ISSUE?

by 09ZX6R on Wed Apr 08, 2020 3:45 pm

ok so i added the lines to clear the buffers for each command.. It now displays mostly correct... however now the data to show is flickering...all the titles/ text is good and solid... but the live data isnt..
Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>             //i2c library
#include <Adafruit_GFX.h>     // graphics library
#include <Adafruit_SH1106.h>  //oled library

#if (SH1106_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SH1106.h!");
#endif

#define OLED_RESET 4

// Create an object for each OLED display
Adafruit_SH1106 display0(OLED_RESET);
Adafruit_SH1106 display1(OLED_RESET);

void TCA9548A(uint8_t bus)
{
  Wire.beginTransmission(0x70);  // TCA9548A address is 0x70
  Wire.write(1 << bus);          // send byte to select bus
  Wire.endTransmission();
}
void displayBatt(float battv) {
  display0.setTextSize(2);
  display0.setTextColor(WHITE, BLACK);
  display0.setCursor(40, 10);
  display0.print (battv);
  display0.println("v");
}
void displayPercent(float percent){
  display0.setTextSize(3);
  display0.setTextColor(WHITE, BLACK);
  display0.setCursor(35, 40);
  display0.print (percent, 0);
  display0.println(" % ");
}
//-------------------TPS data begin -------------------------
const float referenceVolts = 5.0;        // the default reference on a 5 volt board
const int TPSPin = A0;                   // signal from Sensor is connected to analog pin 0
int TPSMin = 95;
int TPSMax = 950;
//----------------------END TPS data-------------------------------
//-----------------------START BOOST DATA----------------------------
void displayBoost(float PSI) {
  display1.setTextSize(2);
  display1.setTextColor(WHITE, BLACK);
  display1.setCursor(25, 30);
  display1.print (PSI);
  display1.println("psi");
}
const int BoostPin = A1;                //reads from analog input pin 1
const float ReferenceVolts = 5.0;   // the default reference on a 5 volt board
int BoostMin = 0;   // change this to adjust low reading   // integer of sensed voltage
int BoostMax = 1023;  // change this to adjust high reading   // integer of sensed voltage
// use the serial monitor to get sensor integers
//----------------------END boost data------------------------------------

void setup()
{
  Wire.begin();  // Start Wire library for I2C

  // Set multiplexer to channel 0 and initialize OLED-0 with I2C addr 0x3C
  TCA9548A(0);
  display0.begin(SH1106_SWITCHCAPVCC, 0x3C);
  display0.display();   // turns off splash screen when commented out
  delay(2000);
  display0.clearDisplay();   // Clear the buffer.
 
  // Set multiplexer to channel 1 and initialize OLED-1 with I2C addr 0x3C
  TCA9548A(1);
  display1.begin(SH1106_SWITCHCAPVCC, 0x3C);
  display1.display();   // turns off splash screen when commented out
  delay(4000);
  display1.clearDisplay();

  TCA9548A(0);
      // boot TPS text display
  display0.setTextSize(2);
  display0.setTextColor(WHITE);
  display0.setCursor(45, 0);
  display0.println("TPS");
  display0.setCursor(5, 18);
  display0.println("MONITOR v1");
  display0.setTextSize(1);
  display0.setTextColor(WHITE);
  display0.setCursor(0, 50);
  display0.println("By Johnathan Oey");
  display0.display();
  delay (3000);

  //  Clear the buffer.
  display0.clearDisplay();

  TCA9548A(1);
  // boot BOOST text display
  display1.setTextSize(2);
  display1.setTextColor(WHITE);
  display1.setCursor(10, 0);
  display1.println("BOOST PSI");
  display1.setTextSize(1);
  display1.setCursor(40, 18);
  display1.println("MONITOR v1");
  display1.setCursor(0, 50);
  display1.println("By Johnathan Oey");
  display1.display();
  delay (3000);

  //  Clear the buffer.
  display1.clearDisplay();
}
void loop()
{
  TCA9548A(0);
  // text TPS display
  display0.setTextSize(1);
  display0.setTextColor(WHITE);
  display0.setCursor(32, 0);
  display0.println("TPS MONITOR");
  display0.setCursor(0, 14);
  display0.println("Volts");
  display0.setCursor(0, 30);
  display0.println("Percent");
  display0.display();


  float battv = (analogRead(TPSPin) / 1023.0) * referenceVolts;           // read the value from A0 Sensor monitoring pin
  // Divides by 1023 to get an integer, then multiplies by the ref voltage.
  float Percent = map(analogRead(TPSPin), TPSMin, TPSMax, 0, 100);            // reconfigures the voltage low and high readings at pin A0 to be integer percent(%) from 0 - 100%

  TCA9548A(0);
 
  displayBatt(battv);
  displayPercent(Percent);
  display0.display();
  //  Clear the buffer.
  display0.clearDisplay();

  TCA9548A(1);
// text BOOST display
  display1.setTextSize(2);
  display1.setTextColor(WHITE);
  display1.setCursor(35, 0);
  display1.println("BOOST");
  display1.display();

  float PSI = map(analogRead(BoostPin), BoostMin, BoostMax, 0, 14.7);
 
  TCA9548A(1);
  displayBoost(PSI);
  display1.display();
  //  Clear the buffer.
  display1.clearDisplay();
 }

09ZX6R
 
Posts: 12
Joined: Wed Oct 28, 2015 4:20 am

Re: TCA9548A ISSUE? OR CODE ISSUE?

by adafruit_support_bill on Wed Apr 08, 2020 3:51 pm

There are many ways to optimize display operations to minimize the flicker.

The simplest would be to simply slow down your refresh rate.
A little more sophisticated method is to only refresh when the data actually changes.
And, if you are feeling really ambitious, you can clear only the areas of the screen that are changing.

adafruit_support_bill
 
Posts: 78633
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.