Communication between two arduinos using RTU485

Hello all,

I am using Two arduinos to communicate each other by using RTU485.

I have a program for a master (1st arduino) and other for the slave (2nd arduino).

I want to catch the value of “variable*” by using the slave where the master sending the values.*
The communication happens by using Serial 0 and 3.
My problem is the slave gave me a message of 0 17 0 17 0 17 …etc instead of the real message and I do not know why ??
please, see my code in both master and slave, and tell me if there is any error !! especially the slave code.
Is my message variable[] correct ??
Thanks alot.
here the code of the master:
int sensorPin = A0; // select the input pin for LDR
int sensorValue = 0; // variable to store the value coming from the sensor
int breaker = 50 ; // switch bin
int breakerValue = 0; // switch ADC value
int ledPin = 52; // Led pin to detect switch case
int enableBus = 8;
byte variable[] = {0x11,0x06,0x00,0x02,0x64,0xD8};
int x, y;
void setup()
{
Serial.begin(9600);
Serial3.begin (9600);
pinMode(ledPin,OUTPUT);
**pinMode(breaker,INPUT); **
pinMode(sensorPin,INPUT);
pinMode (enableBus,OUTPUT);
delay(10);
}
void loop()
{
** sensorValue = analogRead(sensorPin); // read the value from the sensor**
** breakerValue = digitalRead (breaker);**
** x = sensorValue/256;**
** y = sensorValue%256;**
** variable[2]= x;**
** variable[3]= y;**
__ double Vout = sensorValue0.0048828125;
** int lux=(250/Vout)-50;**
** switch (breakerValue)**
{
** case HIGH:**
** {**
** Serial.println(lux); //prints the values coming from the sensor on the screen**
** digitalWrite (ledPin,HIGH);**
** if (Serial.available())**
** communication ();**
** delay(100);**
** break;**
** }**
** case LOW:**
** {**
** digitalWrite (ledPin,LOW);**
** delay(100);**
** break;**
** }**
** default:**
** break;**
**} **
}
void communication ()
{
** digitalWrite (enableBus, HIGH);**
** for(int i=0;i<sizeof(variable);i++)**
** {**
Serial3.write (variable);
Serial3.flush();
}
digitalWrite (enableBus, LOW);
}*__

[/b]
here the code of the slave:
int enableBus = 8;
byte B;
void setup ()
{
** Serial.begin (9600);**
** Serial3.begin (9600);**
** pinMode (enableBus, OUTPUT);**
** delay (10);**
}
void loop ()
{
** while(Serial3.available())**
** {**
** digitalWrite (enableBus,HIGH);**
** B= Serial3.read ();**
** Serial.write (B);**
** Serial.println (B);**
** Serial.flush ();**
** digitalWrite (enableBus,LOW);**
** }**

}

Your code is NOT posted properly. Read the stickies at the top of the forum that you were supposed to read BEFORE you blundered in here posting code incorrectly, and fix your post.

It is NOT necessary to flush() the outgoing buffer after each write. At most, you would flush the buffer after the entire array was written.

variable is a dumb name for a variable.

Hello Paul,

Here is my code, I did some changes.

Please any help ??

Here is my code, I did some changes.

I don't see any code, and the code in the original post is still posted incorrectly and still contains all the crap I pointed as that was wrong.

Read the damned stickies before your mouse gets anywhere near the Post button again.