zoukankan      html  css  js  c++  java
  • Arduino 寻找I2C地址address

    参考:http://henrysbench.capnfatz.com/henrys-bench/arduino-projects-tips-and-more/arduino-quick-tip-find-your-i2c-address/

    Arduino Quick Tip:  Find Your I2C Address

    Don’t Get Hung Up When You Want to Play

    I2C Address Scanner Quick Tip

    You’ve just received your new module and you want to test it.  You go back the seller’s web page and find instructions that are only slightly clearer than mud.  In fact, one of things you discover as you attempt to unravel the odd form of English that is used is that you can’t seem to figure out what the I2C address is.

    You can certainly find the data sheet for the device that the module is built around. With a little work, you should also be able to  identify the address pins.  Then, with a little probing,  you can identify the address.

    In fact, at some point in your project development, it may even become necessary.   Alas,  sometimes you only have a few minutes to play and you just want to see the freaking thing work.

    If that describes you, then try running the following sketch.  It will scan I2C possible addresses and report the address of the device that responds.

    address of the device that responds.



    I2C Scanner By Nick Gammon

    Copy, Paste, Upload and Run!

    // I2C Scanner
    // Written by Nick Gammon
    // Date: 20th April 2011
    
    #include <Wire.h>
    
    void setup() {
      Serial.begin (115200);
    
      // Leonardo: wait for serial port to connect
      while (!Serial) 
        {
        }
    
      Serial.println ();
      Serial.println ("I2C scanner. Scanning ...");
      byte count = 0;
      
      Wire.begin();
      for (byte i = 8; i < 120; i++)
      {
        Wire.beginTransmission (i);
        if (Wire.endTransmission () == 0)
          {
          Serial.print ("Found address: ");
          Serial.print (i, DEC);
          Serial.print (" (0x");
          Serial.print (i, HEX);
          Serial.println (")");
          count++;
          delay (1);  // maybe unneeded?
          } // end of good response
      } // end of for loop
      Serial.println ("Done.");
      Serial.print ("Found ");
      Serial.print (count, DEC);
      Serial.println (" device(s).");
    }  // end of setup
    
    void loop() {}
    
    

    I2C Scanner Results

    Run the sketch and you will see a result that looks something like this:

    I2C Scanner Results

  • 相关阅读:
    strpos 判断字符串是否存在
    TP 自动验证
    label 标签的用法,点label选中单选、复选框或文本框
    str_replace 替换 小技巧
    数据库文件MDF的空间占满了,没有自动增长是怎么回事?
    (4.7)mysql备份还原——深入解析二进制日志(3)binlog的三种日志记录模式详解
    (4.6)mysql备份还原——深入解析二进制日志(2)binlog参数配置解析
    (1.16)mysql server优化之buffer pool
    COALESCE函数
    linux网络设置和虚拟机克隆转移之后网卡找不到
  • 原文地址:https://www.cnblogs.com/MCSFX/p/11774266.html
Copyright © 2011-2022 走看看