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.

Re: TCA9548A ISSUE? OR CODE ISSUE?

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

ok so the data is constantly changing
the refresh rate change i have no idea how to do
and arnt i already clearing the areas that are changing? ie the boot up screen, the text changes, and the data?

goin back to your previous post:

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();

how do i implement this? i tried do comment out the display0 and display 1 sections that had info to display, and pasted that code above into it.. it didnt work.. ill post code of how i had it soon...im at work..

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 4:57 pm

the refresh rate change i have no idea how to do

Add a delay in your loop.
how do i implement this?

I posted the code for you, If it doesn't work, it may not be compatible with the displays you are using.

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

Re: TCA9548A ISSUE? OR CODE ISSUE?

by 09ZX6R on Wed Apr 08, 2020 5:01 pm

oh ok the delay is simple enough

as for the code u gave, when i added it, it says that display.display is not declared in the scope

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 5:12 pm

Yes. You need to declare just one display called 'display' instead of declaring 'display0' and 'display1'

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

Re: TCA9548A ISSUE? OR CODE ISSUE?

by 09ZX6R on Wed Apr 08, 2020 5:23 pm

like this?
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 display(OLED_RESET);
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(4);
  display1.setTextColor(WHITE, BLACK);
  display1.setCursor(50, 30);
  display1.print (PSI, 0);
  display1.println(" ");
}
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(2000);
  display1.clearDisplay();

// boot TPS text display
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(45, 0);
  display.println("TPS/BOOST");
  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();
 
  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(35, 0);
  display1.println("BOOST");
  display1.setCursor(5, 18);
  display1.println("MONITOR v1");
  display1.setTextSize(1);
  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.setTextSize(1);
  display1.setTextColor(WHITE);
  display1.setCursor(100, 45);
  display1.println("psi");
  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 5:28 pm

You need to replace all of the 'display0' and 'display1' with just 'display'.

And there is no need to print all of the data twice. Just print it once, then display it to both channels as in the code I posted.

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

Re: TCA9548A ISSUE? OR CODE ISSUE?

by 09ZX6R on Wed Apr 08, 2020 6:43 pm

like this???

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 display(OLED_RESET);
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(4);
  display1.setTextColor(WHITE, BLACK);
  display1.setCursor(50, 30);
  display1.print (PSI, 0);
  display1.println(" ");
}
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(2000);
  //display1.clearDisplay();

// boot TPS text display
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(45, 0);
  display.println("TPS/BOOST");
  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();
   
  delay (4000);
  display.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(35, 0);
//  display1.println("BOOST");
//  display1.setCursor(5, 18);
//  display1.println("MONITOR v1");
//  display1.setTextSize(1);
//  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.setTextSize(1);
  display1.setTextColor(WHITE);
  display1.setCursor(100, 45);
  display1.println("psi");
  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 7:06 pm

like this???

No. You still have display0 and display1 and all the redundant code.

But looking at the code you posted earlier that you said mostly works, I don't thing the single display strategy will work for you because there are some differences between what you are displaying on the two displays.

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

Please be positive and constructive with your questions and comments.