Pages: [1]   Go Down
Author Topic: PC <=>RS 232/485 <=>RS485/RS232 <=>Arduino communication problem  (Read 3388 times)
0 Members and 1 Guest are viewing this topic.
Croatia
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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..smiley

// 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;
                //myIntssmiley-cry((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]smiley-cry((int)myChar[0]-(int)myChar[1])*10)+1000;
 myInts[1]smiley-cry((int)myChar[0]+(int)myChar[1])*10)+1000;
}

Logged

Ontario
Offline Offline
God Member
*****
Karma: 25
Posts: 882
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I had a lot of trouble debugging this sort of thing until I did two things:

(1) debugging on a MEGA which has more than one UART, so that I can generate debug messages and such, as well as carry out the communications on a different UART
(2) got a BUS Pirate, which enables snooping on the serial lines to see what was being sent and received.

Some ideas regarding the code you mention:

Quote
Code:
NewSoftSerial SerijskaInverted(0, 1, true);

Pins 0/1 are connected to the hardware UART.  You do not need to use NewSoftSerial to do serial comms on these pints.  Just use Serial.begin(9600), Serial.available(), etc.

How are you powering your Arduino?  If you have a USB cable connected, then the USB-->Serial chip will be trying to send a signal to the Arduino at all times.  You must power your Arduino via Vin in order to ensure that there is no other logic connected to the UART RxD pin.

Quote
The problem is how to control RE/DE pin in RS232/485 converter?

First, what  RS232/485 driver are you using, and how is it wired?  Are you using one pair or two?

There are some tricks there.  Igor posted the best information here: http://real2electronics.blogspot.com/2009/09/arduino-and-rs485-english-version.html including the magic code required to detect when the Arduino UART has finished sending, so you can get the bus turnaround working properly.
Logged

Croatia
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

THANKS FOR FAST REPLY!!

I'm powering Arduino over external source (12 v battery) trough 5mm(?) female jack. I dont' use arduino USB port neither for supplying or communication. To communicate with Arduino i use standard USB/RS232 converter. That's the reason why i use NewSoftSerial library. USB/RS232 converter inverts signal so i use  NewSoftSerial library to reinverse it.

I'm not sure about the driver, im using two Hexin RS232/485 converters in half duplex mode between  USB/RS232 converter connected to PC and
Arduino's rx&TX pins (0,1). I get serial communication from Arduino to PC ("Hello ROV!"), but i can't send any data into Arduino. I saw Igor' s post earlier, but i didn' study it.

I'm not sure do i have to set pins 4 and(or) 7 in rs232 converter  to high state to send data?

Logged

Croatia
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Mistery solved!!
It looks like the problem was in hardvare uart!! I changed communication pins from 0&1 to 2&3 and it worked!! Some additional serial problems occured, but delay(20); between read and write solved it. 2-wire-long-distance communication here we come!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Interesting! Thanks for the info. I had same problem, Im using a standard RS232 to RS485 converter but found that I needed to use pins 2 and 3 and set these high. I also added an external 120ohm terminal resistor to the end of the RS485 line to prevent noise, ..and it worked! :-)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

good night got 2-III hexix converters to convert rs232 to rs485.
I have made regular calls AA, BB, the RS232 TX and RX-RX-TX communication system but the data are incorrect.

When I put the arduino to send "0123456789" get on the pc see. .. Vv The forces are 9600 baud and have tried with the pound soft serial pins 2 and 3 and still remains the same.

In pc I'm using a USB - RS232 converter put it directly and gave me this problem, tried to put a MAX232 converter but not resolved, conse someone help me?

greetings
Logged

Pages: [1]   Go Up
Jump to: