Go Down

Topic: RS485 with attiny45/85 [SOLVED] (Read 9162 times) previous topic - next topic

sancho_sk

Jul 26, 2013, 08:09 am Last Edit: Aug 09, 2013, 04:25 pm by sancho_sk Reason: 1
Hello, everyone.
First of all, I'd like to point out that I did my research and I can't find relevant info, therefore I ask.

I'd like to create a simple project with arduino communicating over 50-70meters, sending or receiving simple 8bit values. It should operate remote relays, read counters, etc.
From what I found, I assume, the best way for such long-range communication is RS485 protocol (I have some experience with i2c, but it's not capable of such long-range transmits).
I'd like to use chip similar to MAX485.
I found tons of examples on how to work with Arduino and Max485. However, as all of the slave devices in my case will only need 1-bit output/input, I'd like to utilize ATtiny, either 45 or 85 (depending on the final code size).
It would also be lovely if I can utilize the internal 8MHz oscilator on the tiny, limiting the number of parts for each slave.
However, I am unable to find any examples of such design (only ATtiny2313).
Is it even possible to utilize tiny45 for such communication?
I'd like to point out that I do not care about the communication speed - I need only to transmit few bytes per second (like 10-12 bytes, nothing more).
Thanks in advance for any guidance/advices.

Nick Gammon

http://www.gammon.com.au/forum/?id=11428

Quote
Is it even possible to utilize tiny45 for such communication?


I don't see why not. RS485 is an electrical protocol. It doesn't care what device is at the end of it. If you can send async serial from a Tiny45 you should be able to use it.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

sancho_sk

Thanks for the hint. I am more-or-less looking for someone with practical experience with such setup :)

JuanB

Dear sancho_sk,

RS485 is perfect for your project. You will have to formulate a protocol with request/response format and that implements frame checking (error checking) on the data sent, especially if you are switching relays on/off remotely.

Nick Gammon's library seems to implement all of this and will definitely cut down on design and testing..

Be aware that when using the internal oscillator and you are using the UART functionality that temperature deviations will alter the clock frequency that might offset the bit timing making it very difficult to synchronize the start of a byte.

Modbus will also be a very good option but might be to large for a tiny.






sancho_sk

Thanks, I'll check the library. I already ordered the devices.
How serious can the temrature impact be if the communication speed will be set to ~1200bps?

Nick Gammon

Async serial will tolerate a clock error of around 9%.

Between bytes it resyncs (that is what the start bit is about) so a slight pause between sending bytes (if needed by experimentation) would allow it to resync each time.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Constantin

In order to make the RS485 transmissions as painless as possible, I highly recommend Bill Porters EasyTransfer library.

sancho_sk

Thanks for the EasyTransfer hint, but it seems more appropriate for communication of 2 arduinos, where as I have multiple slave devices.

Constantin

All depends on your application. However, if the aim is to reliably and easily transfer data serially (or via rs485) then easy transfer is a huge time saver. 

Mark_Grass

RS485 and EasyTransfer is the way to go.
Slave address: You can set the address of each slave device with dip switches, pins and shunts, or you can set it in software.  Each way has it's pros and cons. Easytransfer uses a data structure to send information.  Add a variable to the data structure for the "address" of each device.  The master will send out a packet to the desired slave but setting the "address" in the data structure. Each slave will receive the packet and check to see if the "address" matches.  If it does, the slave device acts on the data that it received.  The other slaves will ignore it and go back to whatever it was they were doing.

I use the MAX1487 http://pdf1.alldatasheet.com/datasheet-pdf/view/73460/MAXIM/MAX1487.html. It has  a max data rate of 2.5Mbps and you can have 128 devices on one twisted pair(TP).   It also costs about the same as the MAX485.http://www.aliexpress.com/item/Free-Shipping-MAX1487-MAX1487EPA-DIP-8-Made-In-China-Series-100-New-and-High-Quality/1061742692.html.

If you have any Cat5 cable around, you can use one TP for data and then run power over the remaining 6 wires.   It's small wire so you can't run much power down it without a voltage drop.  Cat5 cable is cheap and so are the connectors.  Makes for a clean setup.

attiny44,84,85, 2313?:  The comparison chart http://en.wikipedia.org/wiki/Atmel_AVR_ATtiny_comparison_chart shows that only the 2313 has a hardware UART.  The 84 and 85 do have a USI, but EasyTransfer uses the UART.  BUT...the EasyTransfer library now has a software EasyTransfer, so you can use the 44, 84 or 85 if you have enough program space.   That being said, I would go with the 44; I can get them cheaper than I can get the 85, has more pins etc.  http://www.ebay.com/itm/10x-Atmel-8-bit-Microcontroller-ATTINY44A-PU-10pcs-/330942429719?pt=LH_DefaultDomain_2&hash=item4d0db4ba17

sancho_sk

Each slave will receive the packet and check to see if the "address" matches.  If it does, the slave device acts on the data that it received.  The other slaves will ignore it and go back to whatever it was they were doing.

Thanks for this idea - it's quite easy and straight forward, so I'll give it a shot for sure.

I use the MAX1487 http://pdf1.alldatasheet.com/datasheet-pdf/view/73460/MAXIM/MAX1487.html. It has  a max data rate of 2.5Mbps and you can have 128 devices on one twisted pair(TP).

Sorry for the amateur question, but I failed to see the advantages of 1487 against the 485. Can you, please, elaborate? Maybe I missed something important :(

If you have any Cat5 cable around, you can use one TP for data and then run power over the remaining 6 wires.

Exactly my idea. I know the recommendations for power transfer over Cat-5 cable, it's way more than I really need for my project.

attiny44,84,85, 2313?:  The comparison chart shows that only the 2313 has a hardware UART.  The 84 and 85 do have a USI, but EasyTransfer uses the UART.  BUT...the EasyTransfer library now has a software EasyTransfer, so you can use the 44, 84 or 85 if you have enough program space.

As the only purpose of these chips will be to receive data and set one output according the data, or, in special cases, act as a counter using HW interrupt and on request send the number of counts as an answer, I assume there will be a lot of space left on all of the chips.
The number of pins is not a limitation, quite the opposite (I can make the design smaller), again considering the usage, so I am just fine with 8-DIP package (my only concern was the UART, but it seems to be handled by the EasyTransfer, as you pointed out).
I don't want to make free advertising, but the shop I am using has a better price for ATtiny85 and are quite fast as of delivery (http://www.tme.eu/sk/details/attiny85-20pu/mikroprocesory-atmel-avr-tht/atmel/#).
However, I have to thank all of the people here - within 2 days I have been guided and provided with information I would have to gather manually for weeks using trial-and-error approach.

Mark_Grass

Quote
I don't want to make free advertising, but the shop I am using has a better price for ATtiny85 and are quite fast as of delivery (http://www.tme.eu/sk/details/attiny85-20pu/mikroprocesory-atmel-avr-tht/atmel/#).

Wow on the price! I'll have to remember that source for the attiny chips. 
Digikey comes close but you have to buy 25+. It may be free advertising, but if some one has a better cheaper source,  let everyone know.   :D

Quote
Sorry for the amateur question, but I failed to see the advantages of 1487 against the 485. Can you, please, elaborate? Maybe I missed something important smiley-sad

MAX485 vs MAX1487:  My only point on that was simple.  If I'm buying components I try to buy more than I need for a project, because I almost always will find another application for them.  If the price differential is small between a lower spec'd device and a higher spec'd device,  I'll go with the higher spec'd device.  The next project may need the higher available speed. That's all I was saying. If you already have the other 485 chips, there's no need to order something else. :)

Device        data rate       device on line         current
MAX485       0.25Mbps              32                   300ma
MAX1487     2.50Mbps             128                   230ma

The forum is great.   Lots of people, with lots of experience, and lots of ideas.


sancho_sk

#12
Jul 28, 2013, 07:08 pm Last Edit: Jul 28, 2013, 07:12 pm by sancho_sk Reason: 1
Quote
Data rate       device on line         current
MAX485       0.25Mbps              32                   300ma
MAX1487     2.50Mbps             128                   230ma

My plan is to use SN75176, which has slightly more idle current, but, on the other hand can deliver 5Mbits and (more important from my perspective) costs peanuts at the same site I buy ATtny.
But the number of devices for MAX1487 looks interesting.

Mark_Grass

sancho_sk,

Just in case you're not familiar with structures this is the code for a simple structure:
Code: [Select]
struct DATA_STRUCTURE{
  //put your variable definitions here for the data you want to receive
  //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
  unsigned address;
  int blinks;
  int pause;
  int potValue;
  unsigned long  time;
  int var1;
  int var2; 
};
DATA_STRUCTURE mydata; 

if(mydata.address == myaddress){
  //then do this with the data
  }


You can access the values in the structure by using nameofstucture.elementname.

i.e.  scaledPotValue = (mydata.potValue)/scalingFactor;

sancho_sk

Thanks.
Seems reasonably easy and straightforward.
Today the pards ordered on Saturday should arrive, I'll update the thread as soon as I test both the ATtiny communication and the library.

Go Up