Electronic – RxTx communication with multiple slaves using a RaspberryPi

modbuspicpickitraspberry piserial

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.

Best Answer

  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