Serial: What is different between Gammon's RS485 (blocking) and RS485 "non blocking" libraries? The RS485 master-slave communication library on Nick Gammon's page http://www.gammon.com.au/Arduino/RS485_protocol.zip is working for me OK, but on the same hardware wiring is not working for the non-blocking library http://www.gammon.com.au/Arduino/RS485_non_blocking.zip.

I can not find information about the connection of MAX485 on Arduino for non-block version. Is MAX485/RS485 from HW serial (ie Rx=0 and Tx=1)?

If so, how can a slave on the same line at the same time receive from master the message "hello world" and print it to the serial monitor?
Thank you for the explanation. 

When I added the SoftwareSerial library into Nick's example for non-blocking, so it works, but is it still a non-blocking?

//Master:
#include &lt;RS485_non_blocking.h&gt;
#include &lt;SoftwareSerial.h&gt;
const byte ENABLE_PIN = 4; 
SoftwareSerial mySerial(2,3); //RX = 2 TX = 3

size_t fWrite (const byte what) {
  return mySerial.write (what);  
}

RS485 myChannel (NULL, NULL, fWrite, 0);  

void setup () {
  Serial.begin (9600);
  mySerial.begin (28800);
  myChannel.begin ();  

  pinMode (ENABLE_PIN, OUTPUT);  // driver output enable 
}  // end of setup

const byte msg [] = "Hello world";

void loop () {
  digitalWrite (ENABLE_PIN, HIGH);  // enable sending 
  myChannel.sendMsg (msg, sizeof (msg));
  digitalWrite (ENABLE_PIN, LOW);  // disable sending
  delay (1000);   
}  // end of loop

//Slave:
#include &lt;RS485_non_blocking.h&gt;
#include &lt;SoftwareSerial.h&gt;
const byte ENABLE_PIN = 4; 
SoftwareSerial mySerial(2,3); //RX = 2 TX = 3

int fAvailable () {
  return mySerial.available ();  
}

int fRead() {
  return mySerial.read ();
}

RS485 myChannel (fRead, fAvailable, NULL, 20); 

void setup() {
  Serial.begin(9600);
  mySerial.begin(28800);
  myChannel.begin();
  pinMode (ENABLE_PIN, OUTPUT);  // driver output enable
}  // end of setup

void loop() {
  if (myChannel.update()) {
    Serial.write (myChannel.getData(), myChannel.getLength());
    Serial.println();
  }
}  // end of loop


Regards, Vava
(Sorry for my English... :-)
Reference page: http://www.gammon.com.au/forum/?id=11428



The blocking library is intended where you want to wait for incoming data, and are prepared to do nothing else while it arrives. There is also a timeout parameter which lets the code proceed if nothing happens for a specified number of milliseconds.

The non-blocking library is intended for where you need to do other things (like control motors, or read switches) at the same time you are receiving data. For that situation you call an update function periodically which assembles the incoming packet, byte-by-byte if necessary.

When the data is fully received the update returns true, and you can process the packet.




  If so, how can a slave on the same line at the same time receive from master the message "hello world" and print it to the serial monitor?


As I stated above in neither case do you receive and print "at the same time", however the non-blocking one does not simply wait until all the data has arrived.



Example code from the linked page:

void loop ()
  {
  if (myChannel.update ())  // returns true when packet fully received
    {
    Serial.write (myChannel.getData (), myChannel.getLength ()); 
    Serial.println ();
    }

  // do other things while waiting

  }  // end of loop





  If in example for non-blocking libraries is the same wiring as in the example of blocking library, where is (in non-blocking example) definition of RX(=2) and TX(=3) pins?


The hardware is the same.




  there is limitation for use - only pins which supports change interrupts.


Of course. If the underlying protocol is SoftwareSerial then the usual limitations apply (that is for the Rx pin).