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....
#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
}
