Multiple max 485 communicatio

Dear all,

Here i am attaching simple circuit for communicating two device over max485. i found below code seems work fine for some extent. during first time it read data, as soon as it complete read it start reading garbage value. Please let me know what are changes to be made in circuit to make it work.

I NEED TO COMMUNICATE DEVICE AS IN LAYOUT.
CONNECTION DIAGRAM REPRESENT ,PRESENT CONFIGURATION

master program-> Arduino1

void setup() {
  // put your setup code here, to run once:
  
  Serial.begin(9600);

}

void loop() {
  Serial.write("Arduino write");
  delay(1000);
  
}

slave program-> arduino 2

void setup() {
  
  Serial.begin(9600);

}



void loop() {
  
Serial.write(Serial.read());
  
 delay(1000);
  
}

CONNECTION DIAGRAM.pdf (6.1 KB)

LAYOUT.pdf (4.5 KB)

as soon as it complete read it start reading garbage value.

-1 is not "garbage"

Here i am attaching screen shot of output. Some time it keep reading same thing, how to overcome this problem.
Is there any mistake in connection diagram

output.pdf (175 KB)

Yes, that looks like -1 all right.
What do you expect to see printed when you read data that isn't there?

Start here

Here i m attaching out put window . Where i am getting data from Arduino 1 and reading it from Arduino 2

output-with result.pdf (145 KB)

out2.pdf (143 KB)

My PDF reader reports your document is damaged.

ya , i made it working . Small changes made in circuit, I have added 120ohm resistor at both data lines

But i am facing another problem.

i have reverse the action , i.e Initially Arduino1 master and Arduino2 slave. changed to Arduino1 as slave and Arduino2 as master . This time i could able to receive data. Program syntax similar as pasted earlier

But i am facing another problem.

...but you're not going to tell us what it is?
Or post any code or output.

I am interchanging master to slave and slave to master, Code Working is working fine if i interchange the code.

Code in master

void setup() {
  // put your setup code here, to run once:
  
  Serial.begin(9600);

}

void loop() {
  
  Serial.println("I am  master ");


String content = "";
  char character;
  while(Serial.available()) {
      character = Serial.read();
      content.concat(character);
   
  }
  
 
    Serial.println(content);

 delay(1000);
  
}

salve arduino

void setup() {
  // put your setup code here, to run once:
  
  Serial.begin(9600);

}



void loop() {

 Serial.println("I m slave ");

Serial.write("Msp SENDING DATA");

  
 delay(1000); 
  
}

AWOL:

But i am facing another problem.

...but you're not going to tell us what it is?
Or post any code or output.

Schematic.pdf (17 KB)

I can't open either of the documents attached to reply #4.

Code Working is working fine

Great!

ya its working fine. I have attached output and code above.

SO i am trying these two things which are not working
1)interchanging master to slave and slave to master .and dumping code viceversa
2) communicate single master with two slave devices
here only one salve is receiving data , as soon u connected to 2nd slave start reading garbage value

as soon u connected to 2nd slave start reading garbage value

Is this real garbage this time, or still just data that isn't there?

I dont value what garbage value meant by. I am reading improper values like in communcation if ground is not properly connected you observe improper strings

output-with result.pdf (145 KB)

i dont know what is meant by garbage value. According to me if output is reading improper strings i called it as garbage value.
i have attached output file here

output-with result.pdf (145 KB)

According to me if output is reading improper strings i called it as garbage value.

According to you earlier in this thread, reading data that wasn't there (which you still appear to be doing from your screenshots) was "garbage", but is, in fact, completely normal and expected behaviour.
Sort that out, then post your code and your output.

Present code : 1 master and 2 slave.

out put file attached as below.
page1: without second slave connected. out put from Serial monitor slave1
page2: with both slave connected and changes in out put slave1

master:

void setup() {
 
  Serial.begin(9600);

}


void loop()
{
  Serial.println("WELCOME ARDUINO UNO");
  Serial.write("UNO IS WRITING");
  delay(1000);
}

Slave1 and slave2

void setup() {
  // put your setup code here, to run once:
  
  Serial.begin(9600);

}

void loop() {
   
Serial.println("slave1 is running");// used in salve 1 program
Serial.println("slave 2 is running");// used in slave 2 program
String content = "";
  char character;
  while(Serial.available()) {
      character = Serial.read();
      content.concat(character);
   
  }
  
 Serial.println(content);
 delay(1000);
  
}

1MASTER2slave.pdf (244 KB)

Can I suggest you stop posting PDFs that don't open?
You're wasting my bandwidth.

Just cut and paste from your terminal window into a quote box.

Why are you using "String" in your receiver?

Can I suggest you stop posting PDFs that don't open?
You're wasting my bandwidth.

Just cut and paste from your terminal window into a quote box.

Why are you using "String" in your receiver?

i tried to insert quote , But it didn't worked for me since i could not able to cut it from terminal window . i wanted put image but they are 2 mb file . SO i am putting PDF file.