1 Master, N slave Communication via Rs485, Sending Different İnteger to Different Slaves

Hello everyone,

Im working on a Project. I have 1 Wemos D1 (master) and 2 Arduino Uno(slave) and Rs485 modules i shared the image below.


How can i send different integers to different arduinos ? Are there any example about this ? I have really hard times to doing this.

Here's an old topic that originally started out as wanting to use Modbus but eventually ended up using software serial ports to communicate between several UNOs using a very simple ASCII message.

1 Like

To start, check the datasheet of your RS485 module, does it run on 5V standard (as MAX485) or 3.3V? Then do the seme for your D1. Incompatible voltage levels between the 2 are not good.

It runs on 5V as MAX485.

And your D1 ...

I read the topic but you mentioned RE and DE connections and i dont have this connections in my board as you can see. Im really new person who started to coding arduino and other stuff. Already finished some project but this communication style is very new for me. And what i have as RS485 is different than other topics other RS485 to TTL. So i dont have RE DE pins and im confuse.

It looks like your board is one of those that automatically switches from receive to transmit mode and then back again. You can ignore and mention of the RE & DE signals as they are for the more common boards that let you control the transceivers directly.

1 Like

So i should coding without mention RE and DE just open software serial with rx tx and i'll define id's for the slaves. When i'm sending datas from master to slave i'll check id's then transmit and recieve it. How can i send datas from id and can check datas from slave ?

Yes, just use software serial. Remember to keep your baud rate low, say 9600 or 4800 as software serial can't do more than about 19200 baud on an UNO - you should use AltSoftSerial.

On the master you send out the message with the ID of the slave you want to talk to. In the demo code from my previous example, I would send out <5,0> to turn off the LED on node 5 for example.

Don't forget that this is your comms protocol, so you decide how you send and receive messages between your master and your slave devices. You may want to add in other parameters such as a command ID so your message from the master might be <5,2,3> for device 5 command 2 data value 3. You might want to ask a slave for some reading, so maybe <8,1,0> might mean device 8, command 1 (where command 1 to the slave means read a temperature and send it back), and the 0 is just padding to keep the 3 fields. When your slave sees this, it can respond with the temperature back (assume your master is device 0) - so <0,1,22.5> might be a response from the slave to the master saying that in response to command 1, here's the temperature of 22.5 degC.

1 Like

thank you for all the informations after i tried if i don't get what i want i will reply back to you for some help. hope u'll be in health in future thanks for everything so far.

Hi markd833,

After a 10s of try i couldnt make this communication with this module. Do you have a chance to write a simple code for me ?
Lets say, 1 master- 2 slave, master sending 2 integer one is defined as a=5 others b=8 ;

a goes the first slave and b goes the second slave. looks like very simple but i couldnt make it :confused: . Pls dont forget i dont have re_de for controlling, just have txd, rxd.

You can use modbus, eeprom or anytihng doesnt matter for me just want to learn how i send data to different slaves giving them an adress and sending data to that certain adress.

Have a look at the code in my reply #13 in the link I posted in reply #2. You can simply ignore the RE & DE signals (i.e. no wires go to these pins) or you can delete all references to them in the code.

My example receivers (aka slaves) used a simple 5 character string <n,d> where n is the 1 digit node number and d is the single digit data value. My receivers were UNO's as well.

For your transmitter (aka master) you can simply print the string to your software serial port.

Note that my example simply turned the builtin LED on or off, so the value of d was either '0' or '1'.

You should be able to get that going on your hardware FIRST before expanding it to pass larger data values etc.

1 Like

you defined rx buffer size in 8th pin, what is it ?
where is it connected ? Is it possible for you to send me a model or schematic of your program so I can see the connections?

It's not a pin - it's a constant that defines the size of the receive buffer array - see this a few lines further down the file:

// the received message is stored in here
char rxBuffer[ RX_BUFFER_SIZE ];
1 Like

As ı mentioned before i'm using wemos d1 r2 as master and when i looked to your code altsoftserial library does not include pins for wemos d1 r2. what should i do for this problem can i change your altsoftserial library to softserial library ?

I made your program for 2 slave and it's working now thank you. Can i send some number different than 0,1 ? like 3,50,300 ?

It's working but after a few times second node doesnt working

Of course. You will need to modify this bit of code:

        if (rxBuffer[2] == '0') digitalWrite(LED_BUILTIN, LOW);
        if (rxBuffer[2] == '1') digitalWrite(LED_BUILTIN, HIGH);

Any number you send will be stored in the array rxBuffer. Remember rxBuffer holds all the received characters except the start and end markers. If you were to send the number 75, then the 7 would be in rxBuffer[2] and the 5 would be in rxBuffer[3]. There's probably a really slick way of getting the number out but for now you can simply extract each digit and multiply it by 10, 100 etc to get the correct value out.

1 Like

But after a few times, second slave does not recieve anything. I havent understook why is that. When i restart second arduino it works again but after few times, it doesnt take any message.

What do you think about that ? i'm sure i made all connections right, if its not, it shouldnt work at all.

Ok, let me have a look at the original code just in case I did something wrong. :frowning_face:

1 Like