Help with 2 TCA9548A Multiplexers for 10 OLEDS

Hi there,

I need some help with my Arduino code - I'd like to use 2 TCA9548A Multiplexers to run 10 OLED screens and 2 LCDs.

I have 1 Multiplexer working with 5 OLED screens on it and 1 LCD but I don't know how to connect the second Multiplexer to run the same 5 OLED and 1 LCD.

I have the second Multiplexer with A0 connected to VIN so it has the address 0x71 but it's not working...

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <LiquidCrystal_I2C.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
#define OLED_RESET     4

#define I2C_ADDR 0x27
LiquidCrystal_I2C lcd1(I2C_ADDR, 20, 4);
LiquidCrystal_I2C lcd2(I2C_ADDR, 20, 4);

void displayLCD(int channel, LiquidCrystal_I2C &LCD, long value);

Adafruit_SSD1306 display1(OLED_RESET);
Adafruit_SSD1306 display2(OLED_RESET);
Adafruit_SSD1306 display3(OLED_RESET);
Adafruit_SSD1306 display4(OLED_RESET);
Adafruit_SSD1306 display5(OLED_RESET);

Adafruit_SSD1306 display6(OLED_RESET);
Adafruit_SSD1306 display7(OLED_RESET);
Adafruit_SSD1306 display8(OLED_RESET);
Adafruit_SSD1306 display9(OLED_RESET);
Adafruit_SSD1306 display10(OLED_RESET);


// Select I2C BUS
void TCA9548A(uint8_t bus){
  Wire.beginTransmission(0x70);  // TCA9548A address
  Wire.write(1 << bus);          // send byte to select bus
  Wire.endTransmission();
  Serial.println(bus);
}

void TCA9548A_2(uint8_t bus2){
  Wire.beginTransmission(0x71);  // TCA9548A address
  Wire.write(1 << bus2);          // send byte to select bus
  Wire.endTransmission();
  Serial.println(bus2);
}


void setup() {
  Serial.begin(115200);

  // Start I2C communication with the Multiplexer
  Wire.begin();

  // Init OLED display on bus number 2 (display 1)
  TCA9548A(2);
  if(!display1.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  } 
  // Clear the buffer
  display1.clearDisplay();

  // Init OLED display on bus number 3
  TCA9548A(3);
  if(!display2.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  } 
  // Clear the buffer
  display2.clearDisplay();

  // Init OLED display on bus number 4
  TCA9548A(4);
  if(!display3.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  } 
  // Clear the buffer
  display3.clearDisplay();

  // Init OLED display on bus number 5
  TCA9548A(5);
  if(!display4.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  } 
  // Clear the buffer
  display4.clearDisplay();

  TCA9548A(6);
  if(!display5.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  } 
  // Clear the buffer
  display5.clearDisplay();


  TCA9548A_2(2);
  if(!display6.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  } 
  // Clear the buffer
  display6.clearDisplay();

  // Init OLED display on bus number 3
  TCA9548A_2(3);
  if(!display7.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  } 
  // Clear the buffer
  display7.clearDisplay();

  // Init OLED display on bus number 4
  TCA9548A_2(4);
  if(!display8.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  } 
  // Clear the buffer
  display8.clearDisplay();

  // Init OLED display on bus number 5
  TCA9548A_2(5);
  if(!display9.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  } 
  // Clear the buffer
  display9.clearDisplay();

  TCA9548A_2(6);
  if(!display10.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  } 
  // Clear the buffer
  display10.clearDisplay();

  

  // Init LCDs
  TCA9548A(7);
  lcd1.begin();
  lcd1.backlight();
  lcd1.clear();

  TCA9548A(1);
  lcd2.begin();
  lcd2.backlight();
  lcd2.clear();
    
   
}
 
void loop() {

  
  // Write to OLED on bus number 2
  TCA9548A(2);
  display1.setTextSize(1);
  display1.setTextColor(WHITE);
  display1.setCursor(0, 12);
  display1.println("LOVE");
  display1.setTextSize(2);
  display1.setTextColor(WHITE);
  display1.setCursor(78, 8);
  display1.print("89");
  display1.setCursor(116,8);
  display1.println("%");
  display1.display(); 
  
  // Write to OLED on bus number 3
  TCA9548A(3);
  display2.setTextSize(1);
  display2.setTextColor(WHITE);
  display2.setCursor(0, 12);
  display2.println("HAPPINESS");
  display2.setTextSize(2);
  display2.setTextColor(WHITE);
  display2.setCursor(78, 8);
  display2.print("95");
  display2.setCursor(116,8);
  display2.println("%");
  display2.display(); 
  
  // Write to OLED on bus number 4
  TCA9548A(4);
  display3.setTextSize(1);
  display3.setTextColor(WHITE);
  display3.setCursor(0, 12);
  display3.println("SADNESS");
  display3.setTextSize(2);
  display3.setTextColor(WHITE);
  display3.setCursor(78, 8);
  display3.print("12");
  display3.setCursor(116 ,8);
  display3.println("%");
  display3.display(); 

  // Write to OLED on bus number 5
  TCA9548A(5);
  display4.setTextSize(1);
  display4.setTextColor(WHITE);
  display4.setCursor(0, 12);
  display4.println("DISAPPOINTMENT");
  display4.setTextSize(2);
  display4.setTextColor(WHITE);
  display4.setCursor(89, 8);
  display4.print("11");
  display4.setCursor(116 ,8);
  display4.println("%");
  display4.display(); 

  // Write to OLED on bus number 5
  TCA9548A(6);
  display5.setTextSize(1);
  display5.setTextColor(WHITE);
  display5.setCursor(0, 12);
  display5.println("ANGER");
  display5.setTextSize(2);
  display5.setTextColor(WHITE);
  display5.setCursor(78, 8);
  display5.print("100");
  display5.setCursor(116,8);
  display5.println("%");
  display5.display();

  TCA9548A(2);
  display6.setTextSize(1);
  display6.setTextColor(WHITE);
  display6.setCursor(0, 12);
  display6.println("LOVE");
  display6.setTextSize(2);
  display6.setTextColor(WHITE);
  display6.setCursor(78, 8);
  display6.print("89");
  display6.setCursor(116,8);
  display6.println("%");
  display6.display(); 
  
  // Write to OLED on bus number 3
  TCA9548A(3);
  display7.setTextSize(1);
  display7.setTextColor(WHITE);
  display7.setCursor(0, 12);
  display7.println("HAPPINESS");
  display7.setTextSize(2);
  display7.setTextColor(WHITE);
  display7.setCursor(78, 8);
  display7.print("95");
  display7.setCursor(116,8);
  display7.println("%");
  display7.display(); 
  
  // Write to OLED on bus number 4
  TCA9548A(4);
  display8.setTextSize(1);
  display8.setTextColor(WHITE);
  display8.setCursor(0, 12);
  display8.println("SADNESS");
  display8.setTextSize(2);
  display8.setTextColor(WHITE);
  display8.setCursor(78, 8);
  display8.print("12");
  display8.setCursor(116 ,8);
  display8.println("%");
  display8.display(); 

  // Write to OLED on bus number 5
  TCA9548A(5);
  display9.setTextSize(1);
  display9.setTextColor(WHITE);
  display9.setCursor(0, 12);
  display9.println("DISAPPOINTMENT");
  display9.setTextSize(2);
  display9.setTextColor(WHITE);
  display9.setCursor(89, 8);
  display9.print("11");
  display9.setCursor(116 ,8);
  display9.println("%");
  display9.display(); 

  // Write to OLED on bus number 5
  TCA9548A(6);
  display10.setTextSize(1);
  display10.setTextColor(WHITE);
  display10.setCursor(0, 12);
  display10.println("ANGER");
  display10.setTextSize(2);
  display10.setTextColor(WHITE);
  display10.setCursor(78, 8);
  display10.print("100");
  display10.setCursor(116,8);
  display10.println("%");
  display10.display();

  delay(100);

}
  

I was wondering if I could have some help with this?

Thanks so much,
Tigris

Run the i²c scanner sketch to verify that you have the two multiplexers on the addresses you want.

Wow! I got a headache. Your program needs the use of arrays. It seems to me that on 5 OLED + 1 LCD you show the same as on the other 5 OLED + 1 LCD. If so why do you need a second TCA9548A?

Depending on the display and LCD, there may be data read back from the display, so that would prevent running in parallel. Not sure if any OLED can be read back, but some libraries do read from the LCD controller registers.

The OLED usually has a way to set the I2C address to either 0x3C or 0x3D, that would allow two displays on each bus of the TCA9548A. Same for the LCD, although the common I2C backpack used for LCDs allows for eight different addresses. There really is no need to run the LCD through the TCA9548A.

Definitely, although this may only be test code and the actual information displayed may vary greatly. Also makes it much easier to put the data for each display in a struct.

Which Arduino board are you using? DO NOT connect to VIN - that is an input for powering the board, and if you are using it to power the Arduino will be at a higher voltage than should be connected to the OLED display.

I interpreted @tigrisli 's post to mean A0 and Vin of the multiplexer board, not the Arduino board. Most of these boards are clones of the Adafruit design, which does not contain a regulator, so "Vin" pin might have been better named "Vcc". It can take 1.8-5V. connecting A0 to Vcc should change the i²c address.

Ah, didn't think of the labeling on the OLED itself.

Do need to know which Arduino board this will be running on, the display buffers for the ten displays will need 5120 bytes of memory, plus a little overhead for each display (looks like about 64 bytes per display when I add an additional display). There was a recent post of someone who was driving multiple displays through an I2C multiplexer, but they only defined a single display and reused the single buffer for all the displays.

The multiplexer, not the oled!

Seems I'm all confused.

Good point about ram memory, though. Looks like @tigrisli defines an object per oled, which reportedly works with 5 oleds on one multiplexer. That surprised me, to be honest, because the same RESET pin appears to be shared between all the oleds.

I've only used OLED displays that did not have a reset pin, so didn't notice that. It is possible to only reset on the first display initialization by adding 'false' after the I2C address in the begin() for all other displays:

    if (!display->begin(SSD1306_SWITCHCAPVCC, 0x3C, false)) {

I would guess that the OP may have copied the code from an example sketch and may not actually have a reset connection.

Oh, I can't believe I didn't see this immediately. It's the same error every beginner makes when using more than one i²c multiplexer. They don't switch off the channels on multiplexer 1 before enabling one of the channels on multiplexer 2. Therefore 2 devices with the same address visible on the bus at the same time, so neither works correctly.

I think TCA9548A(8); would disable all the channels of the first multiplexer before you enable the first channel on the second multiplexer. Don't forget to use TCA9548A_2(8) before switching back to channels of the first multiplexer.

Looking at the data sheet, writing 0x00 to the multiplexer should switch off all the outputs.

Thank you so much @PaulRB @david_2018 @flashko for replying and the help! I'm sorry for not replying sooner – I didn't receive any notifications for replies for some reason but I was able to resolve this!

Here is the final code:

#include <LiquidCrystal_I2C.h>
#include "Wire.h"
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>


#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display_OLED_1(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_2(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_3(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_4(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_5(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_6(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_7(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_8(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_9(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_10(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);



// set the LCD number of columns and rows
int lcdColumns = 16;
int lcdRows = 2;

// set LCD address, number of columns and rows
// if you don't know your display address, run an I2C scanner sketch
LiquidCrystal_I2C lcd_1(0x27, lcdColumns, lcdRows);
LiquidCrystal_I2C lcd_2(0x27, lcdColumns, lcdRows);



#define TCAADDR1 0x70
#define TCAADDR2 0x71

void tcaselect1(uint8_t i) {
  if (i > 7) return;

  Wire.beginTransmission(TCAADDR1);
  Wire.write(1 << i);
  Wire.endTransmission();
}

void tcaselect2(uint8_t i) {
  if (i > 7) return;

  Wire.beginTransmission(TCAADDR2);
  Wire.write(1 << i);
  Wire.endTransmission();
}

void tcaselect1_DISABLE() {
  Wire.beginTransmission(TCAADDR1);
  Wire.write(0);  // no channel selected
  Wire.endTransmission();
}

void tcaselect2_DISABLE() {
  Wire.beginTransmission(TCAADDR2);
  Wire.write(0);  // no channel selected
  Wire.endTransmission();
}



int Pot1_Pin = A0;
int Pot2_Pin = A1;
int Pot3_Pin = A2;
int Pot4_Pin = A3;
int Pot5_Pin = A4;
int Pot6_Pin = A5;
int Pot7_Pin = A6;
int Pot8_Pin = A7;
int Pot9_Pin = A8;
int Pot10_Pin = A9;
int Inbuilt_LED = 13;

int Pot1_ADC = 0;
int Pot2_ADC = 0;
int Pot3_ADC = 0;
int Pot4_ADC = 0;
int Pot5_ADC = 0;
int Pot6_ADC = 0;
int Pot7_ADC = 0;
int Pot8_ADC = 0;
int Pot9_ADC = 0;
int Pot10_ADC = 0;

int Pot_1_STS = 0;
int Pot_2_STS = 0;
int Pot_3_STS = 0;
int Pot_4_STS = 0;
int Pot_5_STS = 0;
int Pot_6_STS = 0;
int Pot_7_STS = 0;
int Pot_8_STS = 0;
int Pot_9_STS = 0;
int Pot_10_STS = 0;



void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Arduino Mega: Setup Stage");
  Wire.begin();

  Potentiometers_Setup_Stage();

  tcaselect2_DISABLE(); ////// Disable all ports of First I2C Multiplexer

  /* Initialise the 1st OLED */
  tcaselect1(0);

  if (!display_OLED_1.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_1 allocation failed"));
    //for (;;);
  }

  display_OLED_1.clearDisplay();

  display_OLED_1.setTextSize(1);
  display_OLED_1.setTextColor(WHITE);
  display_OLED_1.setCursor(0, 10);

  waiting();


  /* Initialise the 2nd OLED */
  tcaselect1(1);



  if (!display_OLED_2.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_2 allocation failed"));
    // for (;;);
  }

  display_OLED_2.clearDisplay();

  display_OLED_2.setTextSize(1);
  display_OLED_2.setTextColor(WHITE);
  display_OLED_2.setCursor(0, 10);

  waiting();

  /* Initialise the 3rd OLED */
  tcaselect1(2);


  if (!display_OLED_3.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_3 allocation failed"));
    // for (;;);
  }

  display_OLED_3.clearDisplay();

  display_OLED_3.setTextSize(1);
  display_OLED_3.setTextColor(WHITE);
  display_OLED_3.setCursor(0, 10);

  waiting();


  /* Initialise the 4th OLED */
  tcaselect1(3);

  if (!display_OLED_4.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_4 allocation failed"));
    //for (;;);
  }

  display_OLED_4.clearDisplay();

  display_OLED_4.setTextSize(1);
  display_OLED_4.setTextColor(WHITE);
  display_OLED_4.setCursor(0, 10);

  waiting();


  /* Initialise the 5th OLED */
  tcaselect1(4);

  if (!display_OLED_5.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_5 allocation failed"));
    // for (;;);
  }

  display_OLED_5.clearDisplay();

  display_OLED_5.setTextSize(1);
  display_OLED_5.setTextColor(WHITE);
  display_OLED_5.setCursor(0, 10);

  waiting();


  /* Initialise the 6th OLED */
  tcaselect1(5);


  if (!display_OLED_6.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_6 allocation failed"));
    // for (;;);
  }

  display_OLED_6.clearDisplay();

  display_OLED_6.setTextSize(1);
  display_OLED_6.setTextColor(WHITE);
  display_OLED_6.setCursor(0, 10);

  waiting();


  /* Initialise the 7th OLED */
  tcaselect1(6);


  if (!display_OLED_7.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_7 allocation failed"));
    // for (;;);
  }

  display_OLED_7.clearDisplay();

  display_OLED_7.setTextSize(1);
  display_OLED_7.setTextColor(WHITE);
  display_OLED_7.setCursor(0, 10);

  waiting();



  /* Initialise the 8th OLED */
  tcaselect1(7);


  if (!display_OLED_8.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_8 allocation failed"));
    //for (;;);
  }

  display_OLED_8.clearDisplay();

  display_OLED_8.setTextSize(1);
  display_OLED_8.setTextColor(WHITE);
  display_OLED_8.setCursor(0, 10);

  waiting();



  /* Initialise the 9th OLED */
  tcaselect2(0);


  if (!display_OLED_9.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_9 allocation failed"));
    // for (;;);
  }

  display_OLED_9.clearDisplay();

  display_OLED_9.setTextSize(1);
  display_OLED_9.setTextColor(WHITE);
  display_OLED_9.setCursor(0, 10);

  waiting();


  /* Initialise the 10th OLED */
  tcaselect2(1);


  if (!display_OLED_10.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_10 allocation failed"));
    // for (;;);
  }

  display_OLED_10.clearDisplay();

  display_OLED_10.setTextSize(1);
  display_OLED_10.setTextColor(WHITE);
  display_OLED_10.setCursor(0, 10);

  waiting();


  tcaselect1_DISABLE(); ////// Disable all ports of First I2C Multiplexer


  /* Initialise the 1st LCD */
  tcaselect2(2);

  // initialize LCD
  lcd_1.init();
  // turn on LCD backlight
  lcd_1.backlight();

  waiting();

  /* Initialise the 2nd LCD */
  tcaselect2(3);

  // initialize LCD
  lcd_2.init();
  // turn on LCD backlight
  lcd_2.backlight();

  waiting();
}



void loop() {
  // put your main code here, to run repeatedly:

  Potentiometers_Loop_Stage();

  /* Initialise the 1st OLED */
  tcaselect1(0);

  // Display static text
  display_OLED_1.print("Pot 1 = ");
  display_OLED_1.print(Pot_1_STS);
  display_OLED_1.display();

  waiting();

  /* Initialise the 2nd OLED */
  tcaselect1(1);

  // Display static text
  display_OLED_2.print("Pot 2 = ");
  display_OLED_2.print(Pot_2_STS);
  display_OLED_2.display();

  waiting();

  /* Initialise the 3rd OLED */
  tcaselect1(2);

  // Display static text
  display_OLED_3.print("Pot 3 = ");
  display_OLED_3.print(Pot_3_STS);
  display_OLED_3.display();

  waiting();

  /* Initialise the 4th OLED */
  tcaselect1(3);

  // Display static text
  display_OLED_4.print("Pot 4 = ");
  display_OLED_4.print(Pot_4_STS);
  display_OLED_4.display();

  waiting();

  /* Initialise the 5th OLED */
  tcaselect1(4);

  // Display static text
  display_OLED_5.print("Pot 5 = ");
  display_OLED_5.print(Pot_5_STS);
  display_OLED_5.display();

  waiting();

  /* Initialise the 6th OLED */
  tcaselect1(5);

  // Display static text
  display_OLED_6.print("Pot 6 = ");
  display_OLED_6.print(Pot_6_STS);
  display_OLED_6.display();

  waiting();

  /* Initialise the 7th OLED */
  tcaselect1(6);

  // Display static text
  display_OLED_7.print("Pot 7 = ");
  display_OLED_7.print(Pot_7_STS);
  display_OLED_7.display();

  waiting();

  /* Initialise the 8th OLED */
  tcaselect1(7);

  // Display static text
  display_OLED_8.print("Pot 8 = ");
  display_OLED_8.print(Pot_8_STS);
  display_OLED_8.display();

  waiting();

  /* Initialise the 9th OLED */
  tcaselect2(0);

  // Display static text
  display_OLED_9.print("Pot 9 = ");
  display_OLED_9.print(Pot_9_STS);
  display_OLED_9.display();

  waiting();

  /* Initialise the 10th OLED */
  tcaselect2(1);

  // Display static text
  display_OLED_10.print("Pot 10 = ");
  display_OLED_10.print(Pot_10_STS);
  display_OLED_10.display();

  waiting();


  /* Initialise the 1st LCD */
  tcaselect2(2);

  lcd_1.clear();
  // set cursor to first column, first row
  lcd_1.setCursor(0, 0);
  // print message
  lcd_1.print("Pot 10  = ");
  // set cursor to first column, second row
  lcd_1.setCursor(0, 1);
  lcd_1.print(Pot_10_STS);

  waiting();

  /* Initialise the 2nd LCD */
  tcaselect2(3);

  lcd_2.clear();
  // set cursor to first column, first row
  lcd_2.setCursor(0, 0);
  // print message
  lcd_2.print("Pot 10  = ");
  // set cursor to first column, second row
  lcd_2.setCursor(0, 1);
  lcd_2.print(Pot_10_STS);

  waiting();
}


void Potentiometers_Setup_Stage() {
  pinMode(Pot1_Pin, INPUT);
  pinMode(Pot2_Pin, INPUT);
  pinMode(Pot3_Pin, INPUT);
  pinMode(Pot4_Pin, INPUT);
  pinMode(Pot5_Pin, INPUT);
  pinMode(Pot6_Pin, INPUT);
  pinMode(Pot7_Pin, INPUT);
  pinMode(Pot8_Pin, INPUT);
  pinMode(Pot9_Pin, INPUT);
  pinMode(Pot10_Pin, INPUT);
}


void Potentiometers_Loop_Stage() {
  Pot1_ADC = analogRead(Pot1_Pin);
  Pot2_ADC = analogRead(Pot2_Pin);
  Pot3_ADC = analogRead(Pot3_Pin);
  Pot4_ADC = analogRead(Pot4_Pin);
  Pot5_ADC = analogRead(Pot5_Pin);
  Pot6_ADC = analogRead(Pot6_Pin);
  Pot7_ADC = analogRead(Pot7_Pin);
  Pot8_ADC = analogRead(Pot8_Pin);
  Pot9_ADC = analogRead(Pot9_Pin);
  Pot10_ADC = analogRead(Pot10_Pin);

  Serial.print("Pot1_ADC = ");
  Serial.println(Pot1_ADC);
  Serial.print("Pot2_ADC = ");
  Serial.println(Pot2_ADC);
  Serial.print("Pot3_ADC = ");
  Serial.println(Pot3_ADC);
  Serial.print("Pot4_ADC = ");
  Serial.println(Pot4_ADC);
  Serial.print("Pot5_ADC = ");
  Serial.println(Pot5_ADC);
  Serial.print("Pot6_ADC = ");
  Serial.println(Pot6_ADC);
  Serial.print("Pot7_ADC = ");
  Serial.println(Pot7_ADC);
  Serial.print("Pot8_ADC = ");
  Serial.println(Pot8_ADC);
  Serial.print("Pot9_ADC = ");
  Serial.println(Pot9_ADC);
  Serial.print("Pot10_ADC = ");
  Serial.println(Pot10_ADC);


  Pot_1_STS = map(Pot1_ADC, 0, 1025 , 0 , 100);
  Pot_2_STS = map(Pot1_ADC, 0, 1025 , 0 , 100);
  Pot_3_STS = map(Pot1_ADC, 0, 1025 , 0 , 100);
  Pot_4_STS = map(Pot1_ADC, 0, 1025 , 0 , 100);
  Pot_5_STS = map(Pot1_ADC, 0, 1025 , 0 , 100);
  Pot_6_STS = map(Pot1_ADC, 0, 1025 , 0 , 100);
  Pot_7_STS = map(Pot1_ADC, 0, 1025 , 0 , 100);
  Pot_8_STS = map(Pot1_ADC, 0, 1025 , 0 , 100);
  Pot_9_STS = map(Pot1_ADC, 0, 1025 , 0 , 100);
  Pot_10_STS = map(Pot1_ADC, 0, 1025 , 0 , 100);


  Serial.print("Pot_1_STS = ");
  Serial.println(Pot_1_STS);
  Serial.print("Pot_2_STS = ");
  Serial.println(Pot_2_STS);
  Serial.print("Pot_3_STS = ");
  Serial.println(Pot_3_STS);
  Serial.print("Pot_4_STS = ");
  Serial.println(Pot_4_STS);
  Serial.print("Pot_5_STS = ");
  Serial.println(Pot_5_STS);
  Serial.print("Pot_5_STS = ");
  Serial.println(Pot_5_STS);
  Serial.print("Pot_6_STS = ");
  Serial.println(Pot_6_STS);
  Serial.print("Pot_7_STS = ");
  Serial.println(Pot_7_STS);
  Serial.print("Pot_8_STS = ");
  Serial.println(Pot_8_STS);
  Serial.print("Pot_9_STS = ");
  Serial.println(Pot_9_STS);
  Serial.print("Pot_10_STS = ");
  Serial.println(Pot_10_STS);

  waiting();

}

void waiting() {
  digitalWrite(Inbuilt_LED , HIGH);
  delay(10);
  digitalWrite(Inbuilt_LED , LOW);
  delay(10);
  digitalWrite(Inbuilt_LED , HIGH);
  delay(10);
}

Thank you all again for the help, I really appreciate it! :blush:

That's a shame, there's massive room for improvement.

I know it's definitely not the most efficient as I'm learning as I go, but will be working on improving it...

1 Like

I think it would be wise to improve your code now. It's already a headache, as was pointed out earlier. If you continue working on it in the same style, it will quickly become unmanageable!

Using arrays is the key, as already mentioned. Whenever you find yourself copying & pasting variable names or lines of code multiple times over and changing a digit in the variable name each time, you should be using an array, and using a for-loop to "iterate over the array", accessing each of the array's elements in turn. This will reduce the length of your code greatly, up to 10 times smaller in the case of your code.

For some parts of your code, this may appear a little tricky at first, but it can be done and the forum can help. For example how to make an array of oled objects or how to deal with the fact that some displays are on one multiplexer while some are in the other. There are simple answers.

1 Like

Thanks so much for the advice, I've started looking into arrays and will update as I work on it!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.