LoginSignup
2
1

More than 5 years have passed since last update.

Arduino で i2cdetect する

Posted at

i2c の機器を買ったけどアドレスが解らない or 認識されてるのか解らない、そんなときに Linux では i2c-tools の i2cdetect コマンドですぐ調べられる。

Arduino でも i2c_scanner のやり方で解るんだけど、i2cdetect の出力の方がかわいくて解りやすいので、同じように出力するライブラリを書いた。

#include <Wire.h>
#include <i2cdetect.h>

void setup() {
  Wire.begin();
  Serial.begin(9600);
}

void loop() {
  Serial.println("-- i2cdetect --");
  i2cdetect();
  delay(1000);
}

結果

-- i2cdetect --
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1