Author Topic: Networking for AVRs  (Read 2248 times)

0 Members and 1 Guest are viewing this topic.

Offline bifferosTopic starter

  • Regular Contributor
  • *
  • Posts: 52
  • Country: gb
Networking for AVRs
« on: March 10, 2022, 06:03:01 pm »
I have cat5 wiring to all rooms, with two cables (and sockets) in every wall box.  Most of the time the second socket is unused, so I thought to use these sockets to put a DS1820 in every room.  This is fine for temperature sensing but I realised it would be nice to include an AVR with the temperature sensor so I'd have a module in each room with more functions, such as buttons, buzzers, LED displays and so on as well as the temperature sensing function.

I could use my own form of power over cat5 to power these modules, I could use two of the 8 wires to transmit 12v, with a 5v regulator on the module, but what protocol should I use to talk to these modules?  Is it overkill to use ethernet when I control both ends, and the data rates will be very low?  I imagine ethernet, RS485 and CAN bus would all require transceiver ICs.  So I wondered if there's some differential protocol I could easily implement with an AVR and some very basic components.  Something cheap that would give much better noise immunity than a simple UART but not be overkill. I think the max distance would be about 20 metres.

thanks!
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9933
  • Country: us
Re: Networking for AVRs
« Reply #1 on: March 10, 2022, 07:05:24 pm »
I know you said AVR and I'm going to suggest the Arduino Ethernet board but maybe there is a way to incorporate it.

https://docs.arduino.cc/retired/boards/arduino-ethernet-rev3-without-poe

There's even a version with PoE

https://docs.arduino.cc/retired/boards/arduino-ethernet-rev3-with-poe

A more universal approach

https://www.digikey.com/en/products/detail/wiznet/WIZ750SR-232/8789615
 
The following users thanked this post: bifferos

Offline viperidae

  • Frequent Contributor
  • **
  • Posts: 306
  • Country: nz
Re: Networking for AVRs
« Reply #2 on: March 10, 2022, 10:20:31 pm »
I'd suggest to go with CAN, it provides you with a robust physical layer, which at low speeds can go quite far. No need for any sort of hub architecture to connect all your rooms. Built in bus arbitration. Controllers and physical interfaces are also cheap.
 
The following users thanked this post: bifferos

Offline penfold

  • Frequent Contributor
  • **
  • Posts: 675
  • Country: gb
Re: Networking for AVRs
« Reply #3 on: March 11, 2022, 12:05:12 am »
[...] I imagine ethernet, RS485 and CAN bus would all require transceiver ICs.  So I wondered if there's some differential protocol I could easily implement with an AVR and some very basic components.  Something cheap that would give much better noise immunity than a simple UART but not be overkill. I think the max distance would be about 20 metres.

thanks!

I guess ethernet would be the most expensive option, but it would (with an external mac+phy IC) be the quickest to set up, it's especially quick to get it going in arduino environment. Very robust and minimal messing around, just a bit more expensive.

CAN and RS485 are both relatively cheap physically, it'll depend what protocol you run on top of them as to how much of a faff it becomes. Any "robustness" in RS485 will be purely down to the data protocol, CAN does you some favours in the PHY. No-doubt there'll be an arduino library for some CAN and RS485 data protocols... so probably quit easy either way TBF.

I'm assuming you have a bit of a star type network physically, cables leading to the same place? That's not the most favourable setup for RS485, probably also not for CAN (but I think the standard allows it)... worth checking out what data-rates you can get away with - the concern being that a star network with a single driver will get reflections from each leg if not properly terminated OR need a particularly high drive current if it sees all the terminators in parallel.

As I was writing the last paragraph it did just jump to mind on the cost side: if you have 5 temperature PCBs per room (assuming it'll be your own design) and one hub/central PCB (using CAN or RS485) - it may be cheaper to accept the incrimental cost of adding the ethernet mac+phy plus rj45 socket per temperature board and buy a POE switch that can also power them avoiding the cost of the HUB PCB. Then with the ethernet option, you could use a RasPi and take advantage of the linux-iness to make a nice web-interface to the network perhaps.
 

Offline bifferosTopic starter

  • Regular Contributor
  • *
  • Posts: 52
  • Country: gb
Re: Networking for AVRs
« Reply #4 on: March 11, 2022, 12:44:45 am »
Yes, the network is star topology.

I've used a couple of the ethernet shields. I used a Nano one and I think the wiznet with a full-size Arduino.  They never worked for longer than a few months without a reboot so I wondered if this is a reliable approach.  I've had Linux servers running for a year+, also hacked routers tend to do pretty well.   What I was doing with AVR was so simple I find it hard to believe it was my code, but it could have been I suppose.

I could revisit ethernet and stick to raw ether frames instead of web servers, never tried that, but I still have to work power into this.  PoE itself is out because I don't really want to change my 24-port switch for this project, so I want something DIY.   I've got some injectors, but they end up making the whole thing bulky.

There is some attraction to just hooking up an AVR to one of these adapters:  https://www.hobbytronics.co.uk/rj45-breakout
I already have a bunch of these that I got cheap.  A couple of caps, a regulator and power is done.  I could just go for ridiculously low baud (300 or something) and stick to 5v TTL serial, it may work, particularly if I keep a couple of rj45 lines free for some kind of 'interrupt'. for things like button presses.

I have a couple of the MCP2515 can bus modules in the component drawer, but when I look at these they don't seem any simpler than ethernet.   I suppose they give me separate screw terminals I can connect to the RJ45 breakout board, so it keeps solder points free for the power lines but that's about it.

EDIT:  Indeed I was planning on gathering all these modules together and connecting to something running Linux, which would give ethernet access to the whole arrangement.  I think it's safe to assume whatever that is will have plenty of IO, it may be Pi + Arduino, just because I find the Pi IO voltage rather limiting.
« Last Edit: March 11, 2022, 12:48:29 am by bifferos »
 

Offline penfold

  • Frequent Contributor
  • **
  • Posts: 675
  • Country: gb
Re: Networking for AVRs
« Reply #5 on: March 11, 2022, 08:37:14 am »
[...]
[...] wiznet with a full-size Arduino.  They never worked for longer than a few months without a reboot so I wondered if this is a reliable approach.  I've had Linux servers running for a year+, [...]
[...]

Interesting. If its just a reboot it needs, then you can always use a relatively long duration watchdog timer that the host resets with a regular ping. I'm not sure I've left an arduino ethernet board running that long, not had much problem with the ENC28J60 itself; it may be something to do with the arduino library.
 
The following users thanked this post: bifferos

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 13076
Re: Networking for AVRs
« Reply #6 on: March 11, 2022, 09:58:16 am »
IIRC RS485 and CAN don't support terminated branches or stubs - only the bus ends should be terminated and unterminated stubs need to be kept short to avoid severely limiting the max data rate.

OTOH with a whole spare 4 pair cable to use per endpoint, you can use two pairs (out and back) for data to convert your star topology to a bus, looping out to each endpoint from your central hub location.    That puts CAN bus and RS485 back on the table. 

The central hub can be pretty dumb as the bus master is just another node, so it could even be built without a PCB by punching jumper wires down to the back of a patch panel looping the bus from each jack to the next, and handling the power distribution via an automotive fusebox to feed individually fused power to each jack.   Unused jacks would need a loopback plug to complete the bus.   You would need terminators for the ends of the bus, but that's just a few resistors on perfboard, jumpered to the two end jacks in the patch panel.

'Generic' RS485 transceivers are currently far far easier to find in stock than CAN bus ICs, of which nearly 90% are currently out of stock at Mouser.  Worst case you might have to put a couple of footprints on your node PCBs to ease transceiver substitutions.  Everything else you need for RS485 can be handled by the AVR UART + an I/O pin for TX enable.

AVRs themselves are more of a problem, with nearly 70% out of stock at Mouser and few if any of the more popular ones in stock (e.g. no ATmega328 variant is available).   However it seems that Chinese Arduino modules are still reasonably available from suppliers with a high probability of actually delivering, so I'd probably design the sensor nodes around an Arduino Pro Mini, mounted as a daughterboard (that's the ATmega328PB one *without* a USB I/F) footprint, but within the footprint put tracks and pads to let you directly mount an ATmega328PB if you can get any. 

Note: I'm using Mouser's stock levels as a proxy for general distributor availability because they make it easy to filter by 'in stock' and by 'normally stocked' so gathering statistics doesn't involve mass scraping of individual product pages.
« Last Edit: March 11, 2022, 11:22:05 am by Ian.M »
 
The following users thanked this post: bifferos

Online Psi

  • Super Contributor
  • ***
  • Posts: 10220
  • Country: nz
Re: Networking for AVRs
« Reply #7 on: March 11, 2022, 11:16:10 am »
You can actually bit-bang 10Mbit ethernet for simple on/off control using an ATTINY85 with no other parts.
Everything is hardcoded for speed, but it works.
https://hackaday.com/2014/08/29/bit-banging-ethernet-on-an-attiny85/

Do I recommend it, definitely not, but just FYI and for fun   :-//


The cheapest option is probably go wifi route with an ESP8266.
The more fun/interesting option where you learn stuff is probably some kind of differential comms.
Just be prepared for a world of pain if you roll your own multi-node protocol. Or maybe a world of fun if you enjoy that.  :-DD
(Some AVR have a multi-node hardware protocol built in, i forget how it works, i think its UART with hardware detection if a packet is addressed to the MCU or not. Might save some time.
« Last Edit: March 11, 2022, 11:24:57 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 
The following users thanked this post: bifferos

Offline bifferosTopic starter

  • Regular Contributor
  • *
  • Posts: 52
  • Country: gb
Re: Networking for AVRs
« Reply #8 on: March 12, 2022, 12:38:18 am »
Interesting. If its just a reboot it needs, then you can always use a relatively long duration watchdog timer that the host resets with a regular ping. I'm not sure I've left an arduino ethernet board running that long, not had much problem with the ENC28J60 itself; it may be something to do with the arduino library.

The very common ENC28J60 module is the one I didn't try:  https://hobbycomponents.com/wired-wireless/111-enc28j60-ethernet-lan-network-module.  Maybe I should give it a go.
I used one of these:  https://www.amazon.co.uk/diymore-ENC28J60-Ethernet-Arduino-Webserver/dp/B01LANEBAA, and the Wiznet shield for the Uno.  Neither of these were geniune shields so they could have been faulty.

You can actually bit-bang 10Mbit ethernet for simple on/off control using an ATTINY85 with no other parts.
Everything is hardcoded for speed, but it works.
https://hackaday.com/2014/08/29/bit-banging-ethernet-on-an-attiny85/

I saw that in my searching!  It's right up my street.  You're talking to the guy who wired a Z8 microcontroller (could have used an AVR, but hadn't discovered them at that time) to a 3c509 ISA ethernet card using an ISA slot I got from an old motherboard and some stripboard and it actually worked!  :).   That certainly finds a use for my RJ45 breakout boards.  Crazy stuff.

OTOH with a whole spare 4 pair cable to use per endpoint, you can use two pairs (out and back) for data to convert your star topology to a bus, looping out to each endpoint from your central hub location.    That puts CAN bus and RS485 back on the table. 

This is a really interesting idea, and takes me back to the days of thin ethernet.  I remember wiring a building with it :(.  Everything stops working with a break in the bus, a good and bad thing at the same time.  Making use of the extra cabling in this way to save having point-to-point connections at the 'hub' makes the overall controller far simpler as it's just another node.  Nice idea.

But I think in the end I may go the 1-wire route.  There are slave libraries that I can investigate.  I take three lines for that, then leave the other 5 lines as interrupts.  I setup individual nodes to choose which interrupt lines to use, and share them in much the same way as an old PC ISA bus did.  So my controller needs to know what devices are using what interrupts, but it does give me the ability to respond quickly to button presses on the nodes.  Either I slow poll at regular intervals (for stuff like temperature), or when an interrupt line is pulled low, depending on the device I do a read of some register over w1.  I may need to read more than one slave device if the interrupt line is shared to find the source of the interrupt.

This is quite nice because some nodes will only be temperature, basically an rj45 breakout board with DS1820, maybe even a hacked ethernet cable + DS1820.  One node (the doorbell) could be just a dedicated interrupt line and nothing else.  It worked (after a fashion) in the early PCs, so could work for me.

Using this I can use one of these bus boards to connect all the cables together:
https://www.amazon.co.uk/Electronics-Salon-RJ45-9-Way-Board-Connector/dp/B00U2D2GP2
And I've only got to find 8 IO ports on my arduino to control the whole thing.  Perhaps I can even get away without resistors because I can use the internal pull-ups for my interrupt lines.

If the above is inadequate, I think I will investigate some kind of RS485/CAN bus system, looping pairs to make a bus.

Thanks for all the replies, a lot of good info here, as ever on this board.
 

Offline Renate

  • Super Contributor
  • ***
  • Posts: 1460
  • Country: us
Re: Networking for AVRs
« Reply #9 on: March 13, 2022, 06:31:27 pm »
I think that too many people grab instantly for wireless. In a fixed application I'd rather save the spectrum for something more useful.
I've been running a MODBUS (RS-485) system on ATMega32u4's for years now.
It works fine. I just connect wires without regard to topology. Ok, my distances are small. If you have bigger distances some thought should be in order.
CAN is fine, but I wouldn't bother without hardware that supports it. Ok, you can name any protocol and a Z80 can support it, but it's an uphill slog.
 

Offline max_torque

  • Super Contributor
  • ***
  • Posts: 1323
  • Country: gb
    • bitdynamics
Re: Networking for AVRs
« Reply #10 on: March 14, 2022, 09:36:54 pm »
The simple "fix" to enable a star topology on a linear network (ie CAN or RS485) is to provide your wiring harness and units with an OUT and RETURN, so each unit effectively sits in the middle of a linear bus!

You can use simple plugs with 120 ohm termination resistors in them to physically select/terminate the "ends" of your bus as an where you see fit
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3832
  • Country: nl
Re: Networking for AVRs
« Reply #11 on: March 15, 2022, 06:51:07 pm »
Yet another vote for either RS485 or CAN transceivers.
The're just small 8 pin chips that turn UART signals into a differential pair.

I am aware of the ENC28J60 and thw Wiznet 5600, but those need far more complex hardware and software.
There are plenty of networking libraries you can use with RS485 or CAN.

A little search in platromio from the command line shows 57 libraries for "rs485, a lot of them are based around modbus.

--------------------
me@home:~$ pio lib search rs485
Found 57 libraries:
--------------------

For the power supply:
Long cables have a significant DC resistance, and will therefore drop voltage over their length (on both the "power" and the "GND" wire!)
Therefore it is best to start with a high voltage, (for example 24V) and then use small SMPS modules at your network nodes to make the supply voltage for your microcontrollers.

Also read the "10 ways to bulleproof RS485" Application note
https://html.duckduckgo.com/html?q=10+ways+to+bulleproof+RS485


Also note that 100Mbit/s Ethernet only uses 4 wires.

This means you can use an CAT5 cable for all of:
1. One pair for 24Vdc.
2. One pair for RS485 data.
3. Two pairs for regular 100MBit/s Ethernet.

CAT5 cable and connectors can handle up to about 1Amp of current, and a small Linux computer only needs about 1A@ 5V, and with an SMPS that is about 200mA from 24V.
This means you can have a central power supply, a few Linux computers and a whole lot of smart sensor nodes all from the same CAT5 cable.

You do need to regard the topology of your network. Ethernet needs switches while a star configuration sort of works for RS485 if the baudrate is low (and your transceivers are slew rate limited), but a star topology should be avoided for RS485 (and CAN).

RS485 only defines signal levels (the lowest layer of the OSI model), while CAN defines a complete network stack.
AVR controllers do not have a built in CAN hardware peripheral, and doing it in software would be cumbersome.
You can just use CAN transceivers with normal UART though.
 

Online westfw

  • Super Contributor
  • ***
  • Posts: 4306
  • Country: us
Re: Networking for AVRs
« Reply #12 on: March 17, 2022, 07:00:50 am »
Unless you have a very big house, your wiring is compatible with "UART + Driver" circuits (which includes RS485, but also plain old RS232.)  RS232 is ... extremely widespread and well understood, even if it's recently been overshadowed by "logic level UART protocols."   All sorts of "upper level" protocols are common...
 

Offline rteodor

  • Regular Contributor
  • *
  • Posts: 170
  • Country: ro
Re: Networking for AVRs
« Reply #13 on: April 13, 2023, 06:45:34 am »
While searching if RS485 over Ethernet cables matches in impedance I stumbled over this thread. I am basically in the same situation as OP and I want to share my ideas, maybe they are of use or maybe somebody have something to criticize.

The wires are already in place in what I call "pseudo-star" topology. On some of the legs there might be more than one board with sensors, relays etc.
So I put a pair of RJ45 and a pair of jumpers so I can configure each board depending if its an intermediate or end board on the star's leg. Everything will be cabled with standard straight Ethernet wires that are easy to test, replace or extend.
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8760
  • Country: fi
Re: Networking for AVRs
« Reply #14 on: April 13, 2023, 09:49:30 am »
CAN or RS485 transceiver IC is a "very simple component", IMHO.

CAN is only a simple solution if you use microcontroller with built-in CAN peripheral, like AT90CAN something. If you insist on using AVR, I would not use CAN if I had a full choice over the system because you would probably want to use some of the more popular AVR chips, which do not have CAN.

RS485 would work with the UART peripheral you already have available in nearly every AVR MCU. You can come up with a very simple protocol where one master sends poll messages and slaves have unique addresses so they know which message to reply to.

If even RS485 transceiver IC is "too much hardware", then I don't know what to suggest. Direct signalling from the AVR IO pins simply is not electrically robust enough in such large networks.
 

Online westfw

  • Super Contributor
  • ***
  • Posts: 4306
  • Country: us
Re: Networking for AVRs
« Reply #15 on: April 13, 2023, 04:08:19 pm »
Someone recently pointed out that LVDS theoretically supports higher speeds and longer cables than rs232, as well as multidrop.  Transceivers are pretty cheap, too - comparable to rs232.
 

Online T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 22381
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Networking for AVRs
« Reply #16 on: April 13, 2023, 08:24:41 pm »
LVDS isn't nearly as robust as RS-485; I'm not aware of any receivers with common mode range wider than supplies.  And it's not good for as much distance, given the small signal level; but that's a tradeoff with bitrate which is also much higher, and yeah not hard to overcome RS-232 range for given bitrate.  For most commercial purposes, you'll want to use it in shielded cable, hence, USB, HDMI, etc. (roughly speaking).

That said, actually used it once (not by choice..) over twisted-pair ribbon, in an industrial power application, which shockingly, worked...

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline pqass

  • Frequent Contributor
  • **
  • Posts: 910
  • Country: ca
Re: Networking for AVRs
« Reply #17 on: April 13, 2023, 10:43:20 pm »
See attached topology diagram. You really can't screw it up as the diodes protect the slave transmitters.
Use one pair for [unregulated] DC power and another pair for RS232 TX, and RX; providing full-duplex.
Speed is dependent on the strength of the pull-down resistor which can be supplied from the MAX232 (pin 6; -10V) in the transmitter.
The master can poll but slaves may also generate a break signal (holding line low >2 characters) to get attention.
All messages should be validated via CRC.

See other topologies here: http://www.sampson-jeff.com/article/interface/int.htm
« Last Edit: April 14, 2023, 12:08:55 am by pqass »
 

Offline barshatriplee

  • Regular Contributor
  • *
  • !
  • Posts: 130
  • Country: bd
Re: Networking for AVRs
« Reply #18 on: April 14, 2023, 09:07:55 am »
You can see this: https://forum.digikey.com/t/can-example-atmega32m1-stk600/13039
This is about the built-in CAN controller of the ATmegaxxM1 family of microcontrollers. This project achieves CAN communication between multiple ATmega32M1 devices using STK600 development boards. CAN Libraries for ATmegaxxM1 devices in Studio 6 are provided as well.
 

Offline JustMeHere

  • Frequent Contributor
  • **
  • Posts: 813
  • Country: us
Re: Networking for AVRs
« Reply #19 on: April 14, 2023, 08:22:12 pm »
ESP32 makes this all real simple.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf