Greetitngs Arduino community!
I'm using Java applet to communicate to Arduino over serial port for controlling 2 brushless motors for my ROV project. Since i need a link over 100m i decided to use two RS232/485 converters. I'm using pins 0 and 1 (rx and tx pins, not USB) to communicate with rs232 side of the converter in ROV and other converter in PC. I tested PC <=> Arduino over RS232 protocol (without RS232/485 converters) and everything works great, but when assemble PC <=>RS 232/485 <=>RS485/RS232 <=>Arduino link i got a problem. LINK WORKS ONLY IN ONE DIRECTION!!! I recieve messages from Arduino to PC, but i can't send data from PC to Arduino!
The problem is how to control RE/DE pin in RS232/485 converter? Which pin do i need to set high(low)? On which converter (PC or Arduino)? On RS232 or 485 side?
P.S. this is my 1st post..
// This is my code, i control 2 (will be 3) BLDC motors over ESC controllers, glad to share it!!
#include <ServoTimer2.h> // the servo library
#include <NewSoftSerial.h> // using NewSoftSerial to invert signal!
#define PIN1 2 // define the pins for the servos
#define PIN2 3
#define PIN3 4
NewSoftSerial SerijskaInverted(0, 1, true);
ServoTimer2 MOTOR1; // declare variables
ServoTimer2 MOTOR2;
ServoTimer2 MOTOR3;
char incomingByte = 0;
int analogPin = 3;
int val = 0;
int i=0;
int val2 = 0;
//char myInts[2]={0,0};
char myChar[2]={'a','d'}; //just filling array!
int myInts[2]={1000,1000};
void setup() {
MOTOR1.attach(PIN2); // attach a pin to the servos
MOTOR2.attach(PIN3);
//MOTOR3.attach(PIN4);
SerijskaInverted.begin(9600);
delay (2000);
SerijskaInverted.println(" Hello ROV!");
delay (2000);
}
void loop()
{
// val = incPulse( MOTOR1.read(), 1);
MOTOR1.write( myInts[0]);
// val = incPulse( MOTOR2.read(), 2);
MOTOR2.write( myInts[1]);
// val = incPulse(MOTOR3.read(), 4);
//MOTOR3.write(myInts[2]);
delay(10);
if (SerijskaInverted.available() > 0) {
for(int i=0;i<2;i++){
// read the incoming byte:
incomingByte = SerijskaInverted.read();
myChar*=incomingByte;*
//myInts=(((int)myChar_10)+1000); //calculation from char to int to get 1000-1500 ms pulse_
_ delay(10);
SerijskaInverted.println((int)myChar);
}
SerijskaInverted.flush();*_
* }*
myInts[0]=(((int)myChar[0]-(int)myChar[1])*10)+1000;
myInts[1]=(((int)myChar[0]+(int)myChar[1])*10)+1000;
}