ADS1115 Readout and displaying values on OLED display (via multiplexer)

I am trying to read out an analog digital converter (ADS1115; all three channels) via a multiplexer (TCA9548A) and then display the values, after a conversion to a pressure, on one of three OLED (SSD1306) displays. All components work by themselves. The ADC (ADS1115) was tested separately and so were the displays.
The multiplexer also works. When I run a "scanner" sketch, it recognizes the four devices on the multiplexer.
My code also works to show text on the displays. But as soon as I add the part of the code where the ADS is read, the displays just show me white dots. I assume that I am making a fairly simple mistake. Probably the Arduino does not "remember" the read out value while I change the I2C bus and then address the display.
I am new to programming. So if you have any helpful tips, I would be very grateful!

//I2C Communication
#include <Wire.h>

//Display
#include <SPI.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>

//Analog Digital Converter
#include <Adafruit_ADS1X15.h>
Adafruit_ADS1115 ads;     

//Display
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);


//Voltage reading Channel 1
float truevoltage1;
float pressure_mbar1;
float truepressure1;


//Voltage reading Channel 2
float truevoltage2;
float pressure_mbar2;
float truepressure2;


//Voltage reading Channel 3
float truevoltage3;
float pressure_mbar3;
float truepressure3;


// 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.print(bus);
}
 
  
void setup() {
  Serial.begin(9600);

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

  //Initialise ADS1115 
  TCA9548A(2);
  ads.setGain(GAIN_TWOTHIRDS);

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

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

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


}

void loop() {
  int16_t adc0, adc1, adc2, adc3;
  float volts0, volts1, volts2, volts3;

 //Read Voltage Sensor 1 (Penning Gauge IKR_251)
  TCA9548A(2);
  adc1 = ads.readADC_SingleEnded(1);
  volts1 = ads.computeVolts(adc1);
  truevoltage1=volts1*2;
  pressure_mbar1=pow(10,(truevoltage1-10.5));
  
 //Write Pressure 1 to Display 1
  TCA9548A(3);
  display.clearDisplay();

  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(45, 50);
  display.println("mbar");
  
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(45, 10);
  display.println(pressure_mbar1);
  display.display(); 

 //Read Voltage Sensor 2 (Pirani Gauge PSG-500-S)
  adc2 = ads.readADC_SingleEnded(2);
  volts2 = ads.computeVolts(adc2);
  truevoltage2=volts2*2;
  pressure_mbar2=pow(10,((truevoltage2-6.143)/1.286));

 //Write Pressure 2 to Display 2
  TCA9548A(4);
  display.clearDisplay();

  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(45, 50);
  display.println("mbar");
  
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(45, 10);
  display.println(pressure_mbar2);
  display.display(); 
  
//Read Voltage Sensor 3 (Pirani Gauge PCR260)
  adc3 = ads.readADC_SingleEnded(3);
  volts3 = ads.computeVolts(adc3);
  truevoltage3=volts3*2;
  pressure_mbar3=pow(10,(truevoltage3-5.5));
  
//Write Pressure 2 to Display 2
  TCA9548A(5);
  display.clearDisplay();

  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(45, 50);
  display.println("mbar");
  
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(45, 10);
  display.println(pressure_mbar3);
  display.display(); 
  
  delay(500)
}

Once the devices are tested and shown to work individually, start adding the bits together one by one, testing as you go.

Test just the ADC and one OLED display, and make sure that works, before adding the multiplexer. Test that combination before adding additional displays.

State which Arduino you are using. An Uno will probably not be able to handle 3 displays due to memory issues.

Thanks for the answer! I use an Arduino UNO. The sketch only uses about 58% of the memory. I would also have an Arduino Mega available.
I have been putting it together piece by piece. As soon as I include the ADS1115 and then change the bus on the multiplexer to show it on the display, I don't get a meaningful reading.
So I suspect it is because of this piece of code:


 //Read Voltage Sensor 1 (Penning Gauge IKR_251)
  TCA9548A(2);
  adc1 = ads.readADC_SingleEnded(1);
  volts1 = ads.computeVolts(adc1);
  truevoltage1=volts1*2;
  pressure_mbar1=pow(10,(truevoltage1-10.5));
  
 //Write Pressure 1 to Display 1
  TCA9548A(3);
  display.clearDisplay();

  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(45, 50);
  display.println("mbar");
  
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(45, 10);
  display.println(pressure_mbar1);
  display.display(); 

That can be totally misleading, as memory for the screen is usually allocated on the fly, and can simply fail without an error message.

But i was able to use the UNO to drive the three displays with a code I found on the internet. And I just tried it with the mega and it shows the same problem.

Then memory may not be the problem. But your "do everything at once" approach is certainly not working.

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