I am using the library wire in my program because i want to transmit data between two arduinos (with I2C). I am having problems with the distance (more than 100 meters). I have to choose the right cable (ethernet cat 5e or similar) but, furthermore, i believe i will have to reduce la speed of transmission (from the current one (100 kBytes/sec) to a lower value) in orden to miminise the cable´s impedance problems.
I have printed the .c and .cpp files of wire library and i have changed the data (from 100000L to 100L) and save the changes. After, I have printed my .ino file (with "#include "),i have compiled and i have uploaded to the arduinos slave and master but, it doesn´t change its speed (runs at 100 Kbytes/sec.).
What is the problem?. How can i change the I2C speed. Any suggestions about thes best kind of cable that i have to use.
In the microcontroller is a hardware divider for the I2C clock speed. That divider is very limited. Perhaps 50k might work, and up to 400k might work.
With wires that are not close to each other it is possible to get 2 meters distance with I2C. The normal safe length is about 50cm.
For 100 meters, you might need a serial communication chip like the RS-485, or use a special chip for I2C over long cables.
Perhaps the "SoftwareWire" library is able to reduce the speed a lot, but I have not tried that.
I am going to use two i2c bus extenders named P82B715. I have to do several checks but, i believe it will not be enought. That is why I am thinking in additional measures like reduce the speed or, check with different kind of cables.
Maybe, it will be a good idea if i change the transmission method and use RS-485.Really it is better in long distances. Does somebody have a simple skech for arduino master and arduino slave for RS-485 conmunications?. I have several arduinos slaves so, it has to be possible send messages from the master to a specific slave (with its address) and, after, that arduino slave send its information towards the master.
I have an additional problem. The arduino master is conected to a raspberry using TX/RX pines (serial). Is it possible (compatible) to connect the same arduino master to RS-485 grid and to raspberry pi using that method (both of them are serial conmunications?.
The I2C bus was developed by Philips to be used inside a television.
The RS-485 was developed to be used with twisted pair cable, like your CAT5e.
There are modules with a RS-485 chip and a few resistors.
For RS-485 it is best to have a hardware serial port. The Arduino Mega 2560 board has 3 spare hardware serial ports and the Arduino Leonardo (and Micro and others) has 1 spare hardware serial port.
I don't know if there is a library for it (for multiple slaves).
Wireless can be a good option.
What about ethernet or wifi ?
There is an Ethernet Shield, a wifi Shield, and the Arduino Yun (both Ethernet and wifi).
Perhaps ethernet is the easiest. If for example a number of slaves are at the end of the cable, you can set a bridge there (an old router can probably be set as a bridge with DD-WRT). The Arduino boards can connect to the bridge.
With a "bridge" I mean a router that acts transparant as if it is not there. The main router thinks that the Arduino boards are located directly to its ethernet.
And you can connect a computer to the ethernet as well.
When you want to collect data like temperatures. You could have an Arduino at the end of the ethernet cable, and have a few remote Arduinos sending data wireless to it.
It all depends on how many Arduino boards you want to use and how far the distances can be. Could you make a drawing ?
Is it not possible to make a radial estructure with RS485 with an arduino master in the center and several radial branches with 1-3 arduinos slaves conected to each one (with individual addresses). Total quantity of arduinos 10-12 slaves +1master. There will be 3 or 4 branches.
The max. Branche's longitude will be 20 meters.
i am trying to know if it is possible to run like i2c (1 master and several slaves) but using RS485 solution.
I need send messages from master to specific slaves including its address in the write o read sentence.
It would be the cheapest solution for me.
i have twisted cable for it, so i prefer use it and avoid the ethernet solution.
i have read the features of max485 circuit and it says it possible to connet until 32 devices but i cannot find skeches with examples of conmunication with several slaves conected simuntaniously.
The RS-485 is best with a single long cable. The begin and the end of the cable are terminated with a resistor. All the slaves are connected along the long cable. However, a star-configuration might also work. Branches of 20 meters is not very long.
The normal I2C bus has no problem with a star configuration, but I don't know if that is okay for the P82B715.
Ethernet is twisted pair (a few of them) and RS-485 is for a single twisted pair. I don't know why one of those would be a problem with Cat5e cable. What's wrong with Ethernet ?
A search on Github.com for "rs485" or "rs-485" gives more than 100 results
Modbus is ok for my proyect but, I cannot find clear examples for master's sketches or slaves's sketches. Furthermore, i don't know how i can choose the address of arduino receiver of message.
Talking about the resistor at the end of cable. If i have an star configuration, maybe it will be necesary to install diferent resistors at the end of each branch. Their value should be calculate getting the same value of impedance but with several resistor conected in paralel.
It's not about the same impedance, it is how the end of a long cable is terminated to prevent that the signal bounces.
I have never used ModBus myself, so I don't know any good libraries and how to use them.
What about the RadioHead with "RH_Serial" ? I'm sure that it has been tested and is working.
The I2C with P82B715 (or similar chip) is still an option.
How much data transfer do you need ? Are there high currents or motors or mains wires next to the cables ?
The RS-485 is for high speed data transfer, and is protected against nasty voltage spikes.
I'm sure I can make the SoftwareWire go super-slow and I have tested it (at normal speed) with an Arduino as Master and a Arduino as Slave with 100% reliability.
I have also written a Toggle-Handshake code that use no clock and no timing and no interrupts at all, it transfers data at the speed the Master and Slave can do in the background.
i haven´t decided the way of conmunication between master and the slaves. I´m looking for the bes solution (cheapest and the the simplest hardware added to the arduinos).
The quantity of data is only a few bytes. One byte from master to each slave and three bytes from each slave to the master. This process will be repeated inside a loop.
Talking about interferences, the cable will be installed inside the same tubes on the walls that home´s electrical grid (220 volts and 50 Hz (standard low voltage features in Spain)). Maybe, it will be neccesary to use a shielded cable.
Thank you Peter_n. You are right. I have checked My country´s technical rules and it is not allowed. I have to install an independient tube for data cable but it is not a problem because i have to make a remodelling at home.
About wireless solutions, I believe it would be worse. I think there will be problems with the coordination of conmunication between diferent arduinos slaves and master. Furthermore, i will need a more complicated and expensive hardware.
Simple transceiver modules can be 1 dollar on Ebay up to 10 dollars for a specific RFM module at 868MHz.
The best quality are the XBee modules: https://www.sparkfun.com/pages/xbee_guide