element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Learning to find I2C addresses of sensors for Arduino Due
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 16 replies
  • Answers 2 answers
  • Subscribers 395 subscribers
  • Views 2484 views
  • Users 0 members are here
Related

Learning to find I2C addresses of sensors for Arduino Due

rahimmuh3
rahimmuh3 over 9 years ago

Hi! My name is Rahim M. and I am a full time Mechanical Engineering student at South Mountain Community College.

 

I am currently taking a Engineering Special Projects class involving ANSR and ASCEND for a weather balloon experiment.

 

My classmates and myself have chosen to use the Arduino Due microprocessor for our project because of its immense power and versatility as a processor, but just about everyone on our team is ignorant to the knowledge of how to program with Arduino, especially with I2C addresses.

 

If anyone out there can give us advice on how to begin finding and programming with I2C addresses for our Arduino Due, it would be very much appreciated.

 

I understand that finding I2C addresses is a rather complicated task, especially for beginners, but we really need the knowledge of how to do this in a simple manner as soon as possible.

 

I look forward to hearing from everyone!!!

 

Thank you.

 

Rahim M.

  • Sign in to reply
  • Cancel

Top Replies

  • Former Member
    Former Member over 9 years ago +2 suggested
    Rahim; There are a couple of excellent tutorials on tronixstuff.com specifically about using I2C and Arduino. It looks like you've already been to Adafruit, so no need to mention that. http://tronixstuff…
  • Robert Peter Oakes
    Robert Peter Oakes over 9 years ago +2
    Here are a bunch of Videos and Posts I have produced in the past that also use / describe I2C The Modular Bench Power Supply ++, Arduino UNO and precision ADC, DAC + MDO3000 I2C debugging Fuel Tank BoosterPack…
  • Former Member
    Former Member over 9 years ago +1
    In order to program the Arduino Due microprocessor you have to have Arduino IDE 1.5 or later which can be found here: https://www.arduino.cc/en/Main/Software#toc3 After installing Arduino 1.5 or later…
  • Former Member
    0 Former Member over 9 years ago

    In order to program the Arduino Due microprocessor you have to have Arduino IDE 1.5 or later which can be found here:

    https://www.arduino.cc/en/Main/Software#toc3

     

    After installing Arduino 1.5 or later the link below may be able to help.

    https://www.arduino.cc/en/Guide/Environment

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • shabaz
    0 shabaz over 9 years ago

    Hi Rahim,

     

    The Wikipedia page for I2C explains that devices are either master or slave.

    The microcontroller on the Arduino Due is a master device usually. It doesn't have an I2C address. I2C addressing is for slave devices.

     

    The usual method is to see what integrated circuits (ICs) require I2C interfacing, and then the addresses can be found in the product datasheets for those ICs. You can just type the IC part number in google to get the datasheets.

     

    Does the Arduino Due have peripheral chips on-board that use I2C? I didn't think that was

    the case, but I'm not familiar with it.

     

    If you're interfacing an I2C device to the Arduino Due, then you need to check the datasheet of the device that you are interfacing.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago

    Rahim;

     

    There are a couple of excellent tutorials on tronixstuff.com specifically about using I2C and Arduino.  It looks like you've already been to Adafruit, so no need to mention that.

    http://tronixstuff.com/2010/10/20/tutorial-arduino-and-the-i2c-bus/

     

    Here is a more general one on SparkFun: https://learn.sparkfun.com/tutorials/i2c

     

    And the I2C/Wire library reference on the Arduino site: https://www.arduino.cc/en/Reference/Wire

     

    When you're reading, the "Two-Wire" or "TWI" protocol is I2C.  Some refer to it as Two-Wire, understandably, as connections just require two wires: SDA (Data) and SCL (Clock).  A couple of gotcha's that you may or may not be aware of.  The Due is a 3V3 uC, unlike most Arduinos, which are 5VDC.  You'll need to reference (Include) the "Wire" library in your programming.  If you're using an IDE besides Arduino (Keil, Atmel Studio, etc.) then check Atmel's website for additional libraries required.

     

    Arduino pins can sink 20mA of sustained current, or 40mA max.  Not a problem using I2C, but if you use other pins be aware of those limitations. 

     

    Use a 9-12VDC/2A power source on the DC jack, when not using the USB port for power.  Any lower voltage and your uC may destabilize.  Much higher and the on-board voltage regulator will get too hot.  You can't really attach a heatsink as the VR is flush-mounted on the PCB.

     

    Best of luck!

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • balearicdynamics
    0 balearicdynamics over 9 years ago

    Hello Rahim,

     

    today later I plan to post in Arduino an article on the use of SDA/SCL (Data and Clock) with the LCD alphanumeric display, driven by a shift register. This particular case just only use the two wires of I2C without the need to manage the chip select (not available in the shift register. Will add some more detail on how the library control work in the hope it will be helpful to you.

    Managing more than one device with I2C means to use always the same 2 wires (that are, the I2C bus) and addressing pin(s) to tell to the bus what is the device that should be controlled in a particular moment. I think that seeing the things in two separate steps maybe more understandable.

     

    Enrico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 9 years ago

    Here are a bunch of Videos and Posts I have produced in the past that also use / describe I2C

    The Modular Bench Power Supply ++, Arduino UNO and precision ADC, DAC + MDO3000 I2C debugging

    Fuel Tank BoosterPack With Rechargeable LION Battery and CCS or Energia - I2C issues

    MDO3000 used to debug I2C on an Arduino UNO using the embed option

    The Modular Bench Power Supply ++, Arduino UNO and precision ADC, DAC + MDO3000 I2C debugging

     

    What you have not said is what you want to do with the I2C, what chips are you going to communicate with or is it another Arduino ??

     

    also there is of course hte Arduino Help pages them selves https://www.arduino.cc/en/Reference/Wire

     

    So asside from learning the basics about what I2C is, then you need to decide what you want to do with it ?. As Shabaz has already stated, the addresses of the chips is not hard to find, you just refer to the datasheets

     

    knowing what chip to select in the first place is a little harder but if appoached methodically should not be too hard

     

    I.E. Google the function you want along with the connection type ("I2C ADC 8bit") will give you plenty of chips that are Analogue to Digital Converters, 8Bit resolution with an I2C communications bus

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • rahimmuh3
    0 rahimmuh3 over 9 years ago in reply to Former Member

    This was helpful marcus barnes.

     

    Thank you!

     

    Rahim M.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • rahimmuh3
    0 rahimmuh3 over 9 years ago in reply to shabaz

    Thank you for your advice shabaz! Well, myself being very inexperienced with Arduino programming and the hardware itself, I really do not know that much about on-board peripheral chips. Right now, the main issue for us is learning the process of Reading and Writing from our I2C senors to our Arduino Due microprocessor, of basically setting up the code for the sensors and microprocessor to communicate.


    Any advice on this would be greatly appreciated.


    Thank you.

     

    Rahim M.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • rahimmuh3
    0 rahimmuh3 over 9 years ago in reply to Former Member

    Thank you Brian Edwards!!! The link to tronixstuff is really putting things into a better prospective. Right now our team is doing its best to set up code to get the I2C sensors to Read and Write to the Arduino Due one at a time, but we are running into some issues that are holding us back from even getting one sensor to work. We know that there is a issue with the code, but we can not seem to pen-point what the issue is exactly.


    So far, here is the code that we put together in bits and pieces down bellow...If you or someone else can help figure out what's wrong with the code it would be very much appreciated.


    Thanks again.


    Rahim M.



    #include <Wire.h>

     

     

    void setup()

    {

       Serial.begin(57600);

       Wire.begin();

    }

     

     

    #define MPL3115A2_ADDRESS 0x60

     

     

    void loop()

    {

       Serial.println(IIC_Read(0x0C));

    }

    z

    byte IIC_Read(byte regAddr)

    {

      // This function reads one byte over IIC

      Wire.beginTransmission(MPL3115A2_ADDRESS);

      Wire.write(regAddr);  // Address of CTRL_REG1

      Wire.endTransmission(false); // Send data to I2C dev with option for a repeated start. THIS IS NECESSARY and not supported before Arduino V1.0.1!

      Wire.requestFrom(MPL3115A2_ADDRESS, 1); // Request the data...

      return Wire.read();

    }

     

     

    uint8_t I2CReadRegister(uint8_t I2CDestinationAddress, uint8_t Register)

    {

       Wire.beginTransmission(I2CDestinationAddress);

       Wire.write(Register);

       Wire.endTransmission(false);

       Wire.requestFrom(I2CDestinationAddress, 1 );

      

       delay(200);

      

       return Wire.read();

    }

     

     

    void I2CWriteRegister(uint8_t I2CDestinationAddress, uint8_t Register, uint8_t Data)

    {

       Wire.beginTransmission(I2CDestinationAddress);

       Wire.write(Register);

       Wire.write(Data);

       Wire.endTransmission();

    }

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago in reply to rahimmuh3

    You're welcome Rahim.

     

    First question/observation - In your code what is 'z' in your loop?

     

    void loop()

    {

       Serial.println(IIC_Read(0x0C));

    }

    z      // What is this referencing?

    byte IIC_Read(byte regAddr)

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • jc2048
    0 jc2048 over 9 years ago in reply to rahimmuh3

    I'm not familiar with the Arduino [so view this as trying to help, but could well be wrong], but from the Arduino reference data you point to it looks like you aren't giving it time to do the I2C transfer.

     

    Wire.requestFrom(MPL3115A2_ADDRESS, 1); // Request the data...

     

    That says "go and read a byte from the I2C"

     

    You then try to read the byte immediately with

     

    return Wire.read();

     

    You're working on the assumption that requestFrom blocks and execution doesn't continue until the data is in the buffer but that isn't necessarily true if the I2C stuff is running on interrupts in the background.

     

    A quick and dirty test is to try inserting a delay(200), as in the example routine, before the return and see what that does. If that works, you can then look at how to do it properly using Wire.available, which seems to be your means to find out what's in the buffer.

     

    Putting

    do() while(Wire.available() == 0);  //loop doing nothing while there are no bytes in the buffer

     

    before the return would be one way if you don't mind wasting the 20uS or 30uS that it would sit there.

     

    [Hope I've got that right - I'm an old hardware engineer, so no expert with coding, though I can just about cobble together bits of C when I put my mind to it.]

     

    If none of that works, I should put a scope on it and take a look at SCL and SDA [a scope is much the best way to debug firmware when there's hardware involved].

     

    Good luck with your weather balloon project - sounds interesting and fun.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube