I2Cアドレスをスキャンする
スキャナーですべてのバス上のデバイスを検出します。
「I2Cアドレスをスキャンする」はCoddyKit上の無料Arduino & IoT Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはArduino & IoT Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Arduino & IoT Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Find What Is Connected
Before coding a sensor you need its address. An I2C scanner sketch finds every device on the bus for you. 🔍
Why Addresses Matter
Two devices with the same address will clash on the bus. Scanning first tells you what is there and warns of conflicts.
The Datasheet Can Lie
A datasheet lists a default address, but solder jumpers can change it. Scanning gives you the real, current value every time.
How a Scan Works
The scanner tries every address from 1 to 127 and checks who answers. Each reply means a live device sits at that spot.
Start a Transmission
To test one address you open a message with beginTransmission. It targets the device without sending real data yet.
Wire.beginTransmission(addr);End and Read the Result
Calling endTransmission returns 0 if a device acknowledged. Any other number means nobody answered at that address.
byte error = Wire.endTransmission();Loop Through Addresses
Wrap the test in a loop that walks from 1 to 127, checking each address once and noting which ones reply.
for (byte a = 1; a < 127; a++) {
Wire.beginTransmission(a);
}Print Found Devices
When a device acknowledges, print its address to the Serial Monitor so you can copy it straight into your real sketch.
Serial.print("Found device at 0x");
Serial.println(a, HEX);Read Addresses in Hex
I2C addresses are usually shown in hex, like 0x27 or 0x3C. Printing with HEX matches the format libraries expect.
No Devices Found?
An empty scan usually means missing pull-ups, swapped SDA and SCL, or no power. Check the wiring and try again.
Your First Step Every Time
Make scanning a habit. It confirms wiring works and hands you the exact address before you write any sensor code. 🛠️
Quick Check
What does endTransmission returning 0 mean during a scan?
Recap
You can now scan the bus, walk addresses 1 to 127, and print the hex address of every device before writing real code. ✅
よくある質問
「I2Cアドレスをスキャンする」レッスンは無料ですか?
はい。「I2Cアドレスをスキャンする」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Arduino & IoT Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Arduino & IoT Academyコースには全4レッスンが含まれています。
「I2Cアドレスをスキャンする」で何を学びますか?
スキャナーですべてのバス上のデバイスを検出します。 ブラウザで直接実行するハンズオンコードでArduino & IoT Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Arduino & IoT Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのArduino & IoT Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。
「I2Cアドレスをスキャンする」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このArduino & IoT Academyレッスンでコードを書いて実行できますか?
はい。すべてのArduino & IoT Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- I2Cが2本の線で通信する仕組み
- I2Cアドレスをスキャンする
- SPIが高速にデータを送る仕組み
- 1つのバスで複数のデバイスを動かす