Arduino Connect Multiple I2C Devices
by RonFrtek in Circuits > Arduino
18860 Views, 6 Favorites, 0 Comments
Arduino Connect Multiple I2C Devices
In this tutorial we will learn how to connect several modules with an I2C connection to arduino.
Watch the Video!
In our case we will use 4 OLED Displays as an example, but you can use any other I2C modules/sensors if you wish.
Note: 4 OLED Displays consume a bit more memory thats why we are using Arduino Mega to handle this as Arduino UNO memory is lower. Choose your Arduino,ESP,etc board according to your sensor/modules memory consumption.
What You Will Need
- Arduino Mega 2560 or any other Arduino board
Note: We are using Arduino Mega in this case because OLED Displays consume more memory and Aruino UNO would not be able to handle that. So choose your board according to your modules. - 8-Channel I2C module TCA9548A
- 4 OLED Displays (or any number of other I2C modules)
- Breadboard
- Jumper wires
- Visuino software: Download here
The Circuit
- Connect TCA9548A pin SDA to Arduino pin SDA
- Connect TCA9548A pin SCL to Arduino pin SCL
- Connect TCA9548A pin VIN to Arduino pin 5V
- Connect TCA9548A pin GND to Arduino pin GND
- Connect OLED Display1 pin VCC to Arduino pin 5V
- Connect OLED Display1 pin GND to Arduino pin GND
- Connect OLED Display1 pin SDA to TCA9548A pin SD0
- Connect OLED Display1 pin SCL to TCA9548A pin SC0
- Connect OLED Display2 pin VCC to Arduino pin 5V
- Connect OLED Display2 pin GND to Arduino pin GND
- Connect OLED Display2 pin SDA to TCA9548A pin SD1
- Connect OLED Display2 pin SCL to TCA9548A pin SC1
- Connect OLED Display3 pin VCC to Arduino pin 5V
- Connect OLED Display3 pin GND to Arduino pin GND
- Connect OLED Display3 pin SDA to TCA9548A pin SD2
- Connect OLED Display3 pin SCL to TCA9548A pin SC2
- Connect OLED Display4 pin VCC to Arduino pin 5V
- Connect OLED Display4 pin GND to Arduino pin GND
- Connect OLED Display4 pin SDA to TCA9548A pin SD3
- Connect OLED Display4 pin SCL to TCA9548A pin SC3
Start Visuino, and Select the Arduino MEGA Board Type
The Visuino: https://www.visuino.eu also needs to be installed. Download Free version or register for a Free Trial.
Start Visuino as shown in the first picture Click on the "Tools" button on the Arduino component (Picture 1) in Visuino When the dialog appears, select "Arduino Mega 2560" as shown on Picture 2
In Visuino Add,Set & Connect Components
- Add TCA9548A component
- Add 4x OLED Display components
Step1:
- Select each oled Display component and in the properties window set width, height, display type
- Double click on the "DisplayOLED1" component and in the Elements, drag "Draw Text" to the left side
- In the properties window set size to 3, text to OLED1
- Close the Elements window.
Repeat Steap1 for other Display components.
Connection:
Connect "DisplayOLED1" pin I2C Out to "I2CSwitch1" > I2C 0
Connect "DisplayOLED2" pin I2C Out to "I2CSwitch1" > I2C 1
Connect "DisplayOLED2" pin I2C Out to "I2CSwitch1" > I2C 2
Connect "DisplayOLED3" pin I2C Out to "I2CSwitch1" > I2C 3
Note: In case you are using others modules/sensors as well then just connect their I2C pins the same way.
Generate, Compile, and Upload the Arduino Code
In Visuino, at the bottom click on the "Build" Tab, make sure the correct port is selected, then click on the "Compile/Build and Upload" button.
Play
If you power the Arduino module, the OLED Displays will start to show the text.
Congratulations! You have completed your project with Visuino. Also attached is the Visuino project, that I created for this Instructable, you can download it and open it in Visuino: https://www.visuino.eu