- Sorry for bad english
Trying to do a project where matlab will be master and arduino slave.
I connected the PC to the RS485 bus via RS232/485 converter. I have connected arduino to RS485 bus via transceiver (MAX485).
I connected in the following way
PIN-OUT MAX485 --> Arduino
1 -> RO (Receiver Output) to pin 0 (Rx)
2 -> Receive enable to a digital input (pin4)
3 -> Driver enable to a digital (pin4)
4 -> DI (Driver In) to pin 1 (Tx)
5 -> GND to gnd of the arduino
6 -> SIGNAL A (bus RS-485+)
7 -> SIGNAL B (bus RS-485-)
8 -> Vcc to 5 V of the arduino
I wrote a simple code to verify communication
code in arduino
char z;
char z2;
int led=13;
#define pinT 04
void setup() {
Serial.begin(9600);
pinMode(pinT,OUTPUT);
digitalWrite(pinT,LOW);
pinMode(led,OUTPUT);
}
void loop() {
if(Serial.available()>0){
digitalWrite(led,HIGH);
delay(2000);
z=Serial.read();
if(z=='C'){
digitalWrite(led,LOW);
}
}
digitalWrite(pinT,HIGH);
delay(10);
Serial.println(5);
delay(10);
digitalWrite(pinT,LOW);
}
in matlab
global s1
s1=serial('COM3','BaudRate',9600);
s1.InputBufferSize=1;
s1.Terminator='';
s1.Timeout=1;
fopen(s1)
while (1)
fprintf(s1, 'C');
pause(1);
uzorak = fscanf(s1,'d')
end
fclose(s1);
I'm a beginner, if someone could take a look what is wrong, or what is not wrong: D
and direct me in the right direction