Thuta Learning
ရှာဖွေရန်
AdvancedHardwarebeginner

I2C & SPI — Advanced GPIO Protocols

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • I2C & SPI — Advanced GPIO Protocols ကို ကြောက်စရာမလိုအောင် နားလည်မယ်
  • ကိုယ်တိုင် hardware wiring/code ကို run ကြည့်တတ်မယ်
  • Real project ထဲမှာ ဒီ concept ကို ချက်ချင်း အသုံးချတတ်မယ်

ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်

I2C (Inter-Integrated Circuit) က device များစွာကို wire ၂ ချောင်းတည်း (SDA data + SCL clock) ဖြင့် bus တစ်ခုပေါ် ချိတ်ဆက်နိုင်တဲ့ protocol ပါ — device တစ်ခုစီမှာ unique address ရှိပြီး, Pi က address နဲ့ ခွဲခြားပြီး ဘယ် device ကို ဆက်သွယ်ချင်တာလဲ ဆုံးဖြတ်ပါတယ်။ SPI (Serial Peripheral Interface) ကတော့ pin ပိုများပေမယ့် (MOSI, MISO, SCLK, CS) speed ပိုမြန်ပါတယ် — high-speed sensor/display module တွေမှာ သုံးလေ့ရှိပါတယ်။

လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်

I2C temperature sensor, OLED display, real-time clock module တွေကို I2C bus (SDA/SCL pin ၂ ခုတည်း) မှာ series ချိတ်ဆက်လို့ရပါတယ် — device များစွာချိတ်ထားရင် i2cdetect -y 1 command ကို run ရင် ချိတ်ဆက်ထားတဲ့ device address list ကို scan ပြသပေးပါတယ် (troubleshooting အတွက် အသုံးဝင်ပါတယ်)။ raspi-config ထဲမှာ I2C interface ကို enable လုပ်ရပါမယ် (Camera interface လိုပဲ default disabled)။

အတူတူ ကြည့်မယ်

bash
# Enable I2C interface
sudo raspi-config
# Interface Options → I2C → Enable

# Install i2c-tools
sudo apt install i2c-tools

# Scan for connected I2C devices
i2cdetect -y 1
You should see
i2cdetect -y 1 ကို run ရင် grid table ပေါ်လာပြီး, ချိတ်ဆက်ထားတဲ့ device address (ဥပမာ 0x3c) ကို highlight ပြသပေးမည်။

၅ မိနစ် စမ်းကြည့်

I2C sensor module (ရှိရင်) ကို ချိတ်ဆက်ပြီး i2cdetect -y 1 ကို run ကြည့်ပါ — device address ကို ဖော်ထုတ်ကြည့်ပါ။

သတိလေးတစ်ချက်

I2C bus ပေါ် device များစွာ ချိတ်ထားတဲ့အခါ address conflict (device ၂ ခု address တူ) ရှိရင် communication error ဖြစ်နိုင်ပါတယ် — device datasheet ကနေ default address ကို double-check ပါ။

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • I2C interface ကို raspi-config ထဲမှာ enable မလုပ်ဘဲ i2cdetect command run ကြိုးစားခြင်း (command not found ဒါမှမဟုတ် device မတွေ့ခြင်း)
  • I2C/SPI ကို GPIO digital pin (LED lesson) နဲ့ ရောနားလည်ခြင်း — protocol ကွာခြားချက်ကို notice မလုပ်ခြင်း

အခု ကိုယ်တိုင် စမ်းကြည့်

I2C sensor module (ရှိရင်) ကို ချိတ်ဆက်ပြီး i2cdetect -y 1 ကို run ကြည့်ပါ — device address ကို ဖော်ထုတ်ကြည့်ပါ။

You'll know it worked when: i2cdetect -y 1 ကို run ရင် grid table ပေါ်လာပြီး, ချိတ်ဆက်ထားတဲ့ device address (ဥပမာ 0x3c) ကို highlight ပြသပေးမည်။

I2C & SPI — Advanced GPIO Protocols | Thuta Learning