RS485 conversion not working

I'm trying to set up a network with multiple Arduino slaves and a computer running Matlab. Due to the underground distances involved in the application I need to use RS485 protocol. I've purchased a few Arduino to RS485 converters and a few USB to RS485 converters. All from this site.

I connected them all up and they don't work. I get a few scrambled characters in the command prompt, that's all. Strange thing is that it works perfectly if I use the Arduino's USB connection and don't change the code.

Any ideas why this isn't working?

Here is my Arduino slave code. It waits to be addressed by the master and then transmits back the value in the sensor. I'm sticking to ASCII characters because it's easier

int first=0;
char address[]="A";
int out=134;

#define transmit HIGH
#define recieve  LOW
int control=7;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
delay(500);
pinMode(control,OUTPUT);
pinMode(11,OUTPUT);
digitalWrite(control,recieve);
}

void loop() {
  // put your main code here, to run repeatedly:
while(Serial.available()>0){
  if (Serial.find(address)){
    first=analogRead(A2);
    digitalWrite(control,transmit);
    Serial.println(first);
    Serial.flush();
    digitalWrite(control,recieve);
    //digitalWrite(11,HIGH);
    //delay(200);
    //digitalWrite(11,LOW);
  }
}
}

my matlab code is thus

s=serial('COM35'); fopen(s);
fprintf(s,'A'); fscanf(s)

Henradrie:
I'm trying to set up a network with multiple Arduino slaves and a computer running Matlab. Due to the underground distances involved in the application I need to use RS485 protocol. I've purchased a few Arduino to RS485 converters and a few USB to RS485 converters. All from this site.

I connected them all up and they don't work. I get a few scrambled characters in the command prompt, that's all. Strange thing is that it works perfectly if I use the Arduino's USB connection and don't change the code.

Any ideas why this isn't working?

Here is my Arduino slave code. It waits to be addressed by the master and then transmits back the value in the sensor. I'm sticking to ASCII characters because it's easier

int first=0;

char address[]="A";




my matlab code is thus


s=serial('COM35'); fopen(s);
fprintf(s,'A'); fscanf(s)

ok you define the address for your arduino as:

char address[]="A";

which is actually a 2 character string that also can be defined as:

char address[2] = {'A',0};

in the MathLab Code you send a single letter A, one byte, the Serial.find(address) will never find a match.

change the fprintf(s,'A'); to fprintf(s,"A");

chuck.