I2C master slave

Hi.
1.Is it possible to digitalRead and digitalWrite in-and output pins on a slave arduino via the master?
2. what's the max length of te I2C wiring?
3. Is there any exaple code concerning this topic?

Greetings,
Han

It is possible in theory.
It is even possible for real. But there are so many bad examples, you will get into a lot of trouble.

Suppose that you have two Arduino Uno boards, and you want to explore the Master-Slave configuration. That will work. It is fun to try and test that.

Suppose you have other boards and there is a motor in your project. That has a chance of 90% to fail (in a bad way).

Answers:

  1. Yes, but there are I2C I/O expanders. They are much better. They are made to create more input and output pins. There are even libraries that have similar "digitalRead()" and "digitalWrite()" functions. You can not use the Arduino "digitalRead()" and "digitalWrite()" function and re-route them to an external chip.
  2. The official I2C standard gives you 10 cm for the maximum length if you do it wrong. A reasonable length is 50 cm. If you do everything right then 2 meters might be possible. Some Arduino users brag that they can do 20 meters or so. Under very special conditions that is indeed possible (but not for you).
  3. Yes, but you don't need that, because there must be a better solution for the problem that you are trying to solve.

Can you tell what problem you are trying to solve ? Please give us a broader view of your project.

The attached file may worth reading.
Ch-7I2CLec.pdf (334.4 KB)

This is a good tutorial with examples to do what you want

Then it will violate I2C (Inter-inter circuit) topology?

There is no single correct answer as it is dependent on the electrical conditions of the bus. Take a look at the P82B715 I2Cbus-extender, it should work just fine for you. Koepel published earlier this: [SOLVED] I2C over Cat5 UTP with P82B715 bus extenders - #2 by Koepel which has good information.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.