4
\$\begingroup\$

I am a programmer trying to build a circuit with limited EE knowledge. With so many options(at least being new to this), just want to make sure I am going down the right path.

What I am trying to build is a master device with a RaspberryPi and many plug and play slaves(relays and sensors with very small amounts of data transfer). Seems like using modbus/rs485/pic/75176(LTC485) would be the best solution.

  1. Consumer device, so component costs matter and an off the shelf product won't work.
  2. The more devices I can connect the better. (My understanding is Modbus can do 250 devices by default, but I can do a double register(16bit) to get 65k tho bandwidth will probably cut that in at least half which is fine)
  3. Slaves can be repeated many times. ie 10 of the same temperature sensors. I'm understanding that I don't necesarily have to define the slave id in modbus and can define it on the fly. Please correct me if I am wrong since I can't ask a consumer to set the ID manually if there is more than 1.
  4. I need the consumer (true end user no corporate) to just plug a device in and have the system recognize what it is and be able to uniquely identify it.
  5. True real time is not needed, a few second delay isn't a big deal.
  6. Everything will be a call from the master to get data from the slave. Nothing originating from the slaves.
  7. Plan on using a standard rj45 cable with a max distance of 100m since that's what they are rated for (cheap simple standard).
  8. Lastly, I do plan on having a wireless option in the future, so if any of it can mesh well, that's a bonus.

I found this example that seems like what I am looking for. Doing my code in c++, but should be easy to convert. https://docs.google.com/document/d/1YN4BeXw4zrb2dlk9HcTDxd-E5vxNjVN8wcSF4Q86yz0/

Again, I have much to learn, but tired of going down a bunch of wrong paths, so any advice would be great.

Thanks ahead of time.

\$\endgroup\$
  • \$\begingroup\$ Since it seems you're going to use Ethernet cables, why not use actual Ethernet? Each node comes with its own unique MAC id from the factory; all you need to do is define some type for each node either via your own protocol or one of the [too] many fieldbus protocols over Ethernet. There is no such facility like unique, factory assigned MAC addr in Modbus over RS485; you'd need to implement something custom. Also Modbus over RS485 only supports 32 nodes without repeaters IIRC. \$\endgroup\$ – Fizz Dec 18 '15 at 19:32
  • \$\begingroup\$ May have understood wrong, but with regular ethernet, I wouldn't be able to run a 12v power across and would need an expensive router every time I more ports are needed. Hadn't read about the repeater need. The ones I am seeing are very expensive. Guess that means RS485 is shot. Are there any other options? \$\endgroup\$ – VirtualLife Dec 18 '15 at 19:43
  • \$\begingroup\$ There's Power over Ethernet. \$\endgroup\$ – Fizz Dec 18 '15 at 19:44
  • \$\begingroup\$ Just to give a simple idea of what I am trying to accomplish. Picture a consumer outdoor weather station (not really but easiest example). The end user would buy the Master Unit (Raspberry Pi) and then whatever sensors they want to go with it. Trying to make the end user experience as easy as possible. So when they plug in a slave sensor, the master knows what it is and can communicate with it directly. \$\endgroup\$ – VirtualLife Dec 18 '15 at 19:46
  • \$\begingroup\$ What distance to envisage this to work at: per segment and total. Is your typical use case a daisy chain of sensors or a star topology? \$\endgroup\$ – Fizz Dec 18 '15 at 19:55
3
\$\begingroup\$
  1. Consumer device, so component costs matter and an off the shelf product won't work.

When doesn't it matter in industry ;)

  1. The more devices I can connect the better. (My understanding is Modbus can do 250 devices by default, but I can do a double register(16bit) to get 65k tho bandwidth will probably cut that in at least half which is fine)

Technically you can only give slaves address 1-247 as 248-250 are reserved. You could double the register address but then you wouldn't be compatible with any other Modbus device as you are no longer using Modbus Protocol.

  1. Slaves can be repeated many times. ie 10 of the same temperature sensors. I'm understanding that I don't necesarily have to define the slave id in modbus and can define it on the fly. Please correct me if I am wrong since I can't ask a consumer to set the ID manually if there is more than 1.

What do you mean by "design on the fly"? If you are not going to allow your end user to define their own Slave IDs then I reccomend you initiate your own slave IDs to a higher number, like 150+. If your device is connected to a pre-existing Modbus network then you might run into the issue of pre-exsisting slaves already using addresses that you assigned. YIKES! Keep in mind that most end users will begin assigning devices at address 1 but that's not always the case!

  1. I need the consumer (true end user no corporate) to just plug a device in and have the system recognize what it is and be able to uniquely identify it.

Very easy to do but as stated in bullet 3, if your hardcoded Slave ID already exists on their system you will have multiple devices communicating to the same master.

Everything else you stated looks like standard Modbus RTU specifications so you should be fine there. I would reccomend looking up Modbus TCP protocols for when you use wireless transmission. Here is a helpful link to a website that goes over all of the Modbus Protocols as well as indepth analysis on what Modbus Erros and Responses need to look like.

Simply Modbus

\$\endgroup\$
  • \$\begingroup\$ Appreciate it. This is all proprietary, so not worried about other networks. I picture someone going to the store and buying 5 temperature sensors for example. Those temperature sensors would have the same ID from the factory (vs a light sensor would have a diff ID). When it get's plugged in, I don't want any collisions between those 5 with the same ID. Maybe I am just misunderstanding how the ID system works? \$\endgroup\$ – VirtualLife Dec 18 '15 at 18:59
  • 1
    \$\begingroup\$ I have not personally heard of any manufacturer pre-programming Modbus IDs into thier product as that is typically set up by the end user or some 3rd party before it goes out to consumer. Modbus IDs are NOT manufacture IDs they are seperate. You could code your system to periodically "ping" modbus addresses and see if you get a response from the slave in order to determine a new slave was added but you would need to set up the slave ID prior to this. \$\endgroup\$ – R. Johnson Dec 18 '15 at 19:26
  • \$\begingroup\$ That was essentially what I started trying to do with just USART communication. Every x amount of time, send a message to all slaves and they report back their ID and the internal list gets updated. Was running into data collisions which I didn't know how to handle, so I thought a standard like modbus would be better. Sounding like maybe not from Respawned comment. \$\endgroup\$ – VirtualLife Dec 18 '15 at 19:54
  • \$\begingroup\$ I'll look around and see if there is a communications protocol that might be more what you are looking for but comming from a controls standpoint, lonworks and modbus are typically used the most. \$\endgroup\$ – R. Johnson Dec 18 '15 at 20:11
  • \$\begingroup\$ Thanks. I was honestly hoping what was designed in that link was exactly what I needed. Looks like I may have to fake it for now for a POC until I can pay someone that has industry experience and time to build it. \$\endgroup\$ – VirtualLife Dec 18 '15 at 20:18
0
\$\begingroup\$

You could setup a pc as the modbus master and buy cheap micro plcs for your clients. There are many cheap reliable brands that can be programmed using function blocks. 1- 6 IO unit costs about USD90.00, but it will do what you want out of the box, no c++ programming or fancy electronics required. Just connect your sensors. Look for a PLC that supports both TCP and RTU. Xlogic has a wifi model that would suit what you're trying to do.

Modbus function 40 is used to identify devices, but you will have to manually assign each device ID.

\$\endgroup\$
0
\$\begingroup\$

Have a look at 1-Wire. There are a range of sensors and digital I/O chips which are uniquely IDed. Plenty of software to go with them including some very clever polling techniques to figure out what's on the network.

The system can work with 2-wires (1-Wire refers to one data wire, I suspect) but a three-wire system separating +5 V, data and GND is more reliable.

[Edit]

Have a look at Guidelines for Reliable Long Line 1-Wire Networks. It also addresses problems with star topology, etc. I used 1-wire temperature sensors with a RPi and invested in a 1-Wire-Pi board based on the DS2482S-100 driver chip. This looked after all the driving and timing accuracy and made the task straightforward and reliable.

\$\endgroup\$
  • \$\begingroup\$ What's the maximum length of wire in a 1-Wire system? \$\endgroup\$ – pjc50 Jan 5 '16 at 14:36
  • \$\begingroup\$ I am using somewhat of a 1-wire setup right now. Rx/Tx are tired together with a diode. Technically it works, but I have a collision issue when all devices are talking at once (when booting the system needs to send a hello who is on the network and get a name back from all the slaves). Hence the reason I looking into modbus so I didn't have to write my own. @pjc50, the max length is about 100m, but I think it depends on the # of devices attached also. \$\endgroup\$ – VirtualLife Jan 5 '16 at 15:22
  • \$\begingroup\$ Updating answer. \$\endgroup\$ – Transistor Jan 5 '16 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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