I am trying to build a long range (approx. 15 meters) I2C communication between one ATmega328p and several (approx. 10) ATtiny24A, both will be programmed using Arduino IDE.
All the microcontrollers will be on same I2C bus. 328p will be the master and others will be slaves.
Communication will consist very low info size, for example master will scan for slave devices first, after confirmation every slave device are intact it will go to receive mode.
Slaves will send only 2 digital input values to master when the values changed (2 buttons on 2 digital inputs on slaves), after initial scan mentioned above.
The furthest slave will be 15 meters away from master which will be connected with shielded wire (e.g. 4x0.22 wire).
So my main questions are,
Do i need to use I2C Repeater IC's or for this cable length and data size will it be enough to lower I2C speed to 1kHz (maybe 10kHz)?
If lowering I2C speed will solve the problem, do i need to use " Wire.setClock()" function on both master and slave codes?
Do ATmega328p and ATtiny24A both support low speed (1kHz or 10 kHz) I2C communication?
Lastly, on net, generally I2C pull-up resistors are selected 4k7 ohms. Is it enough if I place them only on master board or do i need to put them on slave boards also ?
Your help would be much appeciated.
Thanks in advance.
I2C is limited in it's range. You can extend the range with great work and by limiting the bus speed.
Are you married to the concept of I2C?
RS485 at about a dollar and a half per module might make life a whole lot easier and then you're good up to about 800 meters.
I2C is designed for short distances but it can be made to work over longer distances. I have it working reliably over about 25 to 30m.
Use twisted pair cable, use 2 pairs. On 1 pair put 0V and SCL and on the other pair 0V and SDA. If you need to supply power in the same cable swap one of the 0V connections for +5V.
Use 1k pull up resistors. Better still distribute the resistance to either end of the I2C bus, so put 2k resistors at each end so they are in parallel giving 1k on each of SDA and SCL. Doing this minimises reflections.
I've not tried running at 100kHz, but you are right to try a lower frequency if needed. You might get it working at 100kHz, don't know, experiment.
You only set the clock speed in the master, the slaves clock from SCL, that's the whole point of having a clock signal.
Thanks for reply.
I don't have to use I2C for communication as you said.
But on slaves I am using ATtiny24A for price reasons, so it does not have TX RX pins.
Searched SoftwareSerial lib for ATtiny24A and couldn't find a suitable one.
The least expensive solution would be ATMega8 I think, still aprrox 2 times pricey than ATtiny24A.
So i turned to I2C which is available on ATtiny24A.
Thanks for your reply.
So what i understand is that if i use low clock and low pull-up resistor values at each end of nodes, communication will be fine.
I found a chip(LTC4311) that has been said to carry I2C communication over 100mt by CAT5 cable.
I understand there will be no need to use this chip because it is an expensive chip and above solution would be sufficient.
Try it and see. It might work OK with the clock at the standard 100kHz, I have not tried that. I note that you only want to go 15m, I am pretty sure that with cat 5 or similar cable and low value pull up resistors you will get it working.
Electronics is a hobby that makes experimenting easy, so experiment and see what you get. Start with the standard 4k7 resistors, it might work, although I suspect it won't. Reduce the value to 2k and see what happens. Based on my experience I would expect 1k to work, but 2k might well be OK.
Don't be afraid to try things!
Do let us know how you get on.
I2C --> cms (depends on speed);
the maximum bus length of an I2C link is about 1 meter at 100
Kbaud, or 10 meters at 10 Kbaud.
ref: I2C Bus Range and Electrical Specifications, Freescale 9S12 HCS12 MC9S12 I2C Hardware =So%20the%20maximum%20bus%20length,within%20an%20otherwise%20shielded%20enclosure
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.