Tarantula3
Published

TCA9548A I2C Multiplexer Module - with Arduino and NodeMCU

Did you ever get into a situation where you had to wire up two, three or more I2C sensors to your Arduino just to realize the limitation?

BeginnerProtip19,926
TCA9548A I2C Multiplexer Module - with Arduino and NodeMCU

Things used in this project

Hardware components

Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
TCA9548A
×1
Arduino UNO
Arduino UNO
×1
NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
Few 0.91 & 0.96 I2C OLED displays
×1
Jumper Cables
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

Code

I2C Scanner

Code

Untitled file

Arduino
#include "Wire.h"
#include <U8glib.h>
#define MUX_Address 0x70 // TCA9548A Encoders address

char tmp_string[8];  // Temp string to convert numeric values to string before print to OLED display
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_FAST);  // Fast I2C / TWI

// Initialize I2C buses using TCA9548A I2C Multiplexer
void tcaselect(uint8_t i2c_bus) {
    if (i2c_bus > 7) return;
    Wire.beginTransmission(MUX_Address);
    Wire.write(1 << i2c_bus);
    Wire.endTransmission(); 
}

void setup(){
	  DisplayInit(); // Initialize the displays 
}

// Initialize the displays 
void DisplayInit(){
    for (int i = 0; i < 7; i++) {
      tcaselect(i);   // Loop through each connected displays on the I2C buses  
  		u8g.firstPage();
  		do {
  			u8g.begin();  // Initialize display
  		 } while( u8g.nextPage() );
    }
}


void loop(){
    for (int i = 0; i < 7; i++) {
      tcaselect(i);

  	  u8g.firstPage();
  	  do {
    		/******** Display Something *********/
    		u8g.setFont(u8g_font_ncenB10);
        u8g.drawStr(0, 13, "Connected to:");

        itoa(i, tmp_string, 10);  
        u8g.setFont(u8g_font_ncenB18);
        u8g.drawStr(25, 50, tmp_string);
        /************************************/
  	  } while( u8g.nextPage() );
  	  delay(50);
    }
	  delay(500);
}

Credits

Tarantula3

Tarantula3

50 projects • 68 followers
There were 1000+ sperms but I was the fastest one..

Comments