Create a "small network" of devices - Page 1
Forum section: electronics / projects

author: Moriambar
author_rank: Unknown
timestamp: May 20, 2019, 10:50:11 am
content: Hi,I currently have a project on-hand and I need to determine how to connect it in order to communicate.First of all the network is composed by:17-20 boards with an ATTINY 45a PN532 nfc readeran arduino nano as a main boardThe basic functionality is:the pn532 reads a card and signals it to the nanothe nano determines which one oh the tiny boards (2 per time) has to activatethe configuration after 5s a new input can be providedI actually am not interested in the code, but in how to link the boards together. Each one of the 17-20 boards have an average distance of 1m from the nano, while the pn532 is 0.6m far. The maximum board distanca is ~2m. all of it will be installed in an electronically quiet environment (nothing else will be influencing the circuit).Since I found it a really simple protocol (with many already available libraries), I was thinking about connecting all of the boards through an i2c bus. This would simplify greatly the wiring, the pin usage (I usually have 2 pins available per tiny board), and the programming time (I know and used i2c a lot). I never used that protocol over such a long bus, though. Is it viable? Do you think I have better solutions? After all I am still a beginner and I'd like to learn.cheers

author: dom0
author_rank: Super Contributor
timestamp: May 20, 2019, 02:59:49 pm
content: ~20-30 meters of cable on a single I2C will not work too well, but there are I2C repeater chips. If I understand correctly, you have a star topology? If so, you can use a couple of those repeaters in the center (at the star) to segment the bus into smaller pieces.If this were larger, or more like a daisy-chain, then RS-485 would be a very sensible idea.

author: Moriambar
author_rank: Unknown
timestamp: May 20, 2019, 03:06:05 pm
content: Quote from: dom0 on May 20, 2019, 02:59:49 pmThanks for your reply. Yes it is a star configuration. I thought of splitting the net into 5 subnets (4 boards each), which will cut off drastically the total length of the single net segment. I did this mainly to organize the wiring, but I can also do it with this in mind. Do you think that this way could be more reliable?QuoteHmm, I don't need it for this project, but perhaps it could come in handy in the future. Do you know a good place to start for a kinda beginner?Cheers!

author: mariush
author_rank: Super Contributor
timestamp: May 20, 2019, 03:54:14 pm
content: If you can manage two wires for each device, you could read one bit at a time from devices easily.You have data and clock / next bit for each chip.The data wires from all 20 devices can go into 3 x 8 bit parallel to serial shift registers linked together.... Or you can use a port expander IC which creates additional IO pins and you can connect that chip using i2c or SPI.You can do the same for the clock/bit wires just have 3 8 bit serial to parallel shift registers (or two 16 bit, or one 24bit shift registers)To read data from a particular device, set the bit for that device high,shift data into the shift registers, then enable the shift registers. You get your 24 bits (for 3 x 8 bit shift registers) sent to all devices.Only the device you want gets a digital 1 (bit set).Device sees the digital 1 and puts a bit on the data wire.you wait 5-10ms or whatever you think it's enough, and then read the data bits from the shift registers.set all clock bits to low, wait a few ns, then set the bit to high again to get the next data bit through the data wire.Repeat 8 times or 16 times or whatever, as much as you needAn 8 bit shift register (serial to parallel) is less than 0.5$ for easy DIP package, here's an example:https://www.digikey.com/product-detail/en/texas-instruments/SN74HC595N/296-1600-5-ND/277246IO Port expanders are cheap, and work both ways, input or outputPCAL6416APW 16 io pins, i2c connection to your nano :https://www.digikey.com/product-detail/en/nxp-usa-inc/PCAL6416APW118/568-9922-1-ND/3677048https://www.digikey.com/product-detail/en/nxp-usa-inc/PCA6416APW118/568-9911-1-ND/3677037MCP23017-E/SP if you want DIP package , 16 i/o pins read/write through i2c :https://www.digikey.com/product-detail/en/microchip-technology/MCP23017-E-SP/MCP23017-E-SP-ND/894272With the MCP23017 you can have up to 8 of them on the i2c bus, so you could have 2 of them for the data input and 2 of them for the clock signals and you can handle 32 devices.

author: Moriambar
author_rank: Unknown
timestamp: May 20, 2019, 05:35:08 pm
content: Quote from: mariush on May 20, 2019, 03:54:14 pmThanks for your suggestion. What is the advantage of this solution over the i2c? Is it just about "cutting the length of the bus"?I like it a lot, if that's the case and it's more robust than the "naked" i2c.thanks