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)