2
\$\begingroup\$

I am trying to create a smart alarm system for my house. I want to have one arduino as the master and several other AtTiny's as slaves to collect data as temperature, moisture, gas concentration, opened doors etc.

How do I connect multiple wired AtTiny's to a master Arduino? Which is the most clever way to communicate between them ? I have read that AtTiny's do not support spi or i2c but you can "hack" it somehow.

EDIT: the distance between the master and the slave can be 1 to 10 meters.

\$\endgroup\$
2
  • \$\begingroup\$ Are you looking for a wired or wireless solution? If you can afford it ($$$, power distribution), wireless solution such as XBee have the advantage of neatly handling multiple node communication. \$\endgroup\$
    – abey
    Jul 1, 2013 at 20:53
  • \$\begingroup\$ Nordic nRF24L01+ is my next step. But I need some wired tiny's also. \$\endgroup\$
    – Radolino
    Jul 1, 2013 at 20:56

2 Answers 2

2
\$\begingroup\$

If you happen to use those ATtiny that do not have hardware support of SPI or I2C, you can likely implement that in software, assuming you wont have any CPU-heavy processing running on the ATtiny (which is typically the case for mere sensor reading). That said, except for the 6-pins ones, most ATtiny's do have hardware support for both I2C and SPI (see product selector).

Choosing between I2C and SPI, I would go for the former given the multiple slave setup and the limited number of pins of the ATtiny (2 pins needed for I2C and 4 for SPI).

\$\endgroup\$
3
  • \$\begingroup\$ i2c is a good decision. \$\endgroup\$ Jul 1, 2013 at 22:58
  • \$\begingroup\$ how do I connect the 328 with the tiny45 ? I can't find a tutorial about what ports of the tiny I should use, only some references to the SCK and SLA ports. \$\endgroup\$
    – Radolino
    Jul 2, 2013 at 5:11
  • \$\begingroup\$ Check e.g. this instructable. \$\endgroup\$
    – abey
    Jul 2, 2013 at 7:24
2
\$\begingroup\$

Actually, the ATTinys have hardware to support TWI (the I2C variant) or SPI, known as the "Universal Serial Interface." You can do one of them at a time, not the other. Also, you have to do protocol things like "look for the proper slave address" in software -- the hardware will detect the start condition for you and hold the clock low until you're ready to receive a byte, but you then have to compare that byte to your own address, and then enter a polling loop if it matches. (Note that the I2C rise/fall times are not guaranteed on these devices.)

Same thing for SPI; you can get interrupts and data for the SPI slave select and data transfer, and it can shift out data from you to the master as well in hardware, but you have to feed it each byte manually, and as a master, you actually have to generate the clock manually (entering a loop that strobes the clock bit.)

I have used I2C for medium-distance bus communications on a robot, and it worked fine. I don't know if it would work as-is over 10 Meters -- you might want to modulate onto a pair of RS-485 wires and de-modulate on the other end, for example. That would probably work very well, at 100 kHz or so. RS-485 driver circuits are cheap and easy to work with. You'd need two twisted pairs for the communications, so regular phone wiring. (More if you also want to send power.)

If that's too much bother for you, I'd suggest using XBees for comms with series 1 firmware (so, regular "air wires" for UARTs.) The Attinys don't do UART natively, but you can emulate it with the USI (single-duplex only) or bit banging (slow data rates only.)

That being said, why are you using ATTinys? The cost of a ATmega in quantity 25 is something like $2. You might as well have a real chip on each end :-)

\$\endgroup\$
3
  • \$\begingroup\$ I had some spare mcu's in my drawer (Attiny26 and 45) and because orders take much time to be delivered here, I want to make the wisest decision. I have ordered many nRF24L01+s for wireless communication (XBees were far too expensive for me) and at the same time I want to have some wired mini-stations connected to the base. The wireless ones will have a battery connected so it could be nice to have a chip that consumes 2.7 or 3.3Volts instead of 5V. Also tinys are half the size of megas. \$\endgroup\$
    – Radolino
    Jul 2, 2013 at 5:09
  • \$\begingroup\$ And finally what I want the mcu to do is to read "on/off" state from a window contact sensor and send some bytes "door is open" or read an analog temperature sensor and send the readings. \$\endgroup\$
    – Radolino
    Jul 2, 2013 at 7:05
  • 1
    \$\begingroup\$ The mega runs fine at 8 MHz on a built-in resonator, just like the Tiny. If you order DIP parts in bulk, just get a bunch of megas instead of Tinys, the cost difference is small :-) If you already have the Tinys, or if the size really matters, then do I2C as per above. Although you'll need to do SPI for the nRF24L01+ IIRC. Luckily, the USI can do SPI, too, when managed right. \$\endgroup\$
    – Jon Watte
    Jul 2, 2013 at 18:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.