Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Tarantula3DIYables
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?

BeginnerProtip23,474
TCA9548A I2C Multiplexer Module - with Arduino and NodeMCU

Things used in this project

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

67 projects • 85 followers
There were 1000+ sperms but I was the fastest one..
DIYables

DIYables

0 projects • 80 followers
I would like to invite you to join and add your projects to DIYables platform https://www.hackster.io/diyables

Comments