ต่อ I2C มากกว่า 1 อุปกรณ์

ปรกติ เราต่ออุปกรณ์ลงไปบน I2C bus ตรงๆได้เลย

ยังไม่แน่ใจว่า มีข้อจำกัดเรื่องจำนวนหรือไม่?

แต่ต่อ 2 – 3 ตัวไม่มีปัญหา ทำงานได้สบายๆ

จาก Diagram, ขา SDA กับ SCL คือ A4, A5

จริงๆมีอีกตำแหน่ง แต่มันก็คือขาเดียวกัน เพราะ UNO มี Hardware I2C ชุดเดียว

ต่อ SDA ของทุกอุปกรณ์เข้าด้วยกัน

ต่อ SCL ของทุกอุปกรณ์เข้าด้วยกัน

ต่อเข้า บอร์ด

จบ

ส่วน Vcc / GND ก็ต่อทุกตัวตามปรกติ

#include <Wire.h>
#include <LiquidCrystal_PCF8574.h>
// เพิ่ม RTC library
#include <DS3232RTC.h>      // https://github.com/JChristensen/DS3232RTC
LiquidCrystal_PCF8574 lcd(0x3F);  // set the LCD address to 0x27 for a 16 chars and 2 line display
DS3232RTC myRTC;

Wire.begin();
Wire.beginTransmission(0x3F);
error = Wire.endTransmission();
  
if (error == 0) {
  lcd.begin(16, 2);  // initialize the lcd    
  lcd.setBacklight(255);
}

setSyncProvider([](){return myRTC.get();}); // the function to get the time from the RTC
if(timeStatus() != timeSet)
  //Serial.println("Unable to sync with the RTC");
else
  //Serial.println("RTC has set the system time");

I2C LCD ต้องระบุ Address เวลาจะติดต่อหรือเริ่มใช้งาน
แต่ RTC – ถ้าใช้บาง library ก็ไม่ต้องใส่ address เพราะเหมือนมันจะ fix มาเลย – น่าจะเป็น 0x68