Arduino Forum

Using Arduino => Programming Questions => Topic started by: amjlopez on Apr 01, 2012, 11:26 pm

Title: send command via rs232
Post by: amjlopez on Apr 01, 2012, 11:26 pm
Hello:
When I write in serial monitor number 3, I need to send this command=  3! to a device connected to arduino with Tx and Rx. and when I write in serial monitor 8,  I need to send this command  8! .
Can you tell me how to do it Please?
thank you very much.
Title: Re: send command via rs232
Post by: Grumpy_Mike on Apr 01, 2012, 11:33 pm
Quote
I need to send this command=  3! to a device connected to arduino with Tx and Rx.

First off what do you mean by 3!

The serial monitor uses the UART on the arduino so unless you have a Mega you have to do further serial communication with a UART simulator like new software serial.

Then if this device is RS232 you need to change the TTL voltages into RS232 voltages with a converter or a chip like the MAX202.
Title: Re: send command via rs232
Post by: amjlopez on Apr 04, 2012, 10:42 pm
Thank you very much:
The device that I use is an Extron switcher, one of its command is 2! , this command select the input 2 in the switcher through RS232.

I have an Arduino Uno and I have bought http://www.electronshik.ru/pdf/DFROBOT/DFR0077.pdf, it is connected to TX pin 6 and RX pin 7, VCC 5v and Gnd. I think the problem is the code that I donĀ“t know how to send 2! to the device.

Can you help me please?
many thanks
Title: Re: send command via rs232
Post by: AWOL on Apr 04, 2012, 10:46 pm
Code: [Select]
Serial.print("2!");
Title: Re: send command via rs232
Post by: amjlopez on Apr 05, 2012, 09:14 am
Thank you:
with this command I send it to the Serial Monitor but not on the external device.
many thanks
Title: Re: send command via rs232
Post by: dxw00d on Apr 05, 2012, 09:23 am
Then your description of how the device is connected,
Quote
device connected to arduino with Tx and Rx
, is misleading. Tx and Rx are generally accepted to mean the hardware serial pins.

How is it connected to the Arduino?
Title: Re: send command via rs232
Post by: Grumpy_Mike on Apr 05, 2012, 09:30 am
If you have connected that device through pins 6 & 7 then you need software to make those pins into a serial port. There is a libary called new software serial that will do that. It allows you to create other pins to talk serial to. Then you just print it, see the examples that come with it.
Title: Re: send command via rs232
Post by: amjlopez on Apr 05, 2012, 10:21 pm
Thank you.
I have just tried NewSoftSerial Library, the connections are right and does not work. I haven't error compiling the code.
NewSoftSerial Library works for Arduino UNO?
Do you know what is it wrong?
many thanks.
Title: Re: send command via rs232
Post by: AWOL on Apr 05, 2012, 10:23 pm
Quote
Do you know what is it wrong?

No.
Where's the code?
Title: Re: send command via rs232
Post by: Grumpy_Mike on Apr 05, 2012, 10:52 pm
Quote
the connections are right

Connected the ground?
Have you tried swapping over TX & RX?
If so post your code.
Title: Re: send command via rs232
Post by: zoomkat on Apr 05, 2012, 10:53 pm
Quote
The device that I use is an Extron switcher, one of its command is 2! , this command select the input 2 in the switcher through RS232.


Did you pay any attention to the below? New soft serial may be able to invert the arduino output.

Quote
Then if this device is RS232 you need to change the TTL voltages into RS232 voltages with a converter or a chip like the MAX202.
Title: Re: send command via rs232
Post by: amjlopez on Apr 06, 2012, 12:51 pm
Thanks again.
this is my new code:

#include <NewSoftSerial.h>

NewSoftSerial mySerial(7, 8); 

void setup() 
{
  Serial.begin(9600);
   // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
}

void loop()
{
  switch(Serial.read())
  {
    case '4':
    mySerial.print("4!");
    break;
    case '5':
    mySerial.print("5!");
    break;
    default :
    //
    break;
   }
}
Like I said  I use http://www.electronshik.ru/pdf/DFROBOT/DFR0077.pdf, it is connected to TX pin 7 and RX pin 8, VCC 5v and Gnd. Do I need another TTL voltage converter?

I have changed also pins 7 & 8 but does not work.
Title: Re: send command via rs232
Post by: Grumpy_Mike on Apr 06, 2012, 02:06 pm
Quote
Do I need another TTL voltage converter?

No

Do a loop back test, connect your TX and RX together on the RS232 side. Then send a byte out on the TX and see if it returns on the RX. ( you need to write some code to do this )
Title: Re: send command via rs232
Post by: amjlopez on Apr 06, 2012, 02:41 pm
I don't understand you.
loop back test,  I have made
void loop()
{
}

connect your TX and RX together...?

can you send me some code please?
many thanks
Title: Re: send command via rs232
Post by: AWOL on Apr 06, 2012, 02:43 pm
Loop-back tx to rx.
Title: Re: send command via rs232
Post by: Grumpy_Mike on Apr 06, 2012, 03:31 pm
Quote
connect your TX and RX together...?

Take a wire from the RS232 TX output and connect it to the RS232 TX input.

Then send a byte out, read a byte back and print it out so you can see it on the serial monitor. If everything is working and wired up correctly you should get the same byte back as you sent out.
If you get nothing then it is wired up wrong, broken or something else.
If you get back what you sent then your problem is with the connection between your device and the RS232.
http://en.wikipedia.org/wiki/Loopback (http://en.wikipedia.org/wiki/Loopback)
Title: Re: send command via rs232
Post by: amjlopez on Apr 06, 2012, 03:52 pm
thank you.
I have done the following:
I have connected Arduino to another PC through rs232 and I send data from Arduino and the PC receive and respond.
I'm using a serial program DataViewer (like Hyperterminal) .
Do you know What I am doing wrong with my Extron devices?
many thanks
Title: Re: send command via rs232
Post by: Grumpy_Mike on Apr 06, 2012, 04:04 pm
You are not testing your external rs232 converter through the pins you have it wired up to using the software serial. That is what you need to test.
Title: Re: send command via rs232
Post by: amjlopez on Apr 06, 2012, 04:13 pm
excuse me but I don't understand. Is my first time doing this.
thanks again
Title: Re: send command via rs232
Post by: amjlopez on Apr 06, 2012, 04:37 pm
How can I Take a wire from the RS232 TX output and connect it to the RS232 TX input?
Title: Re: send command via rs232
Post by: PaulS on Apr 06, 2012, 04:39 pm
Darn. I need to get a new Arduino. None of mine have a smiley face pin to use with NewSoftSerial.
Title: Re: send command via rs232
Post by: amjlopez on Apr 06, 2012, 04:47 pm
Thank you.
I have read in somewhere that I can use pin0 and pin 1 to send data to an external device with rs232 is that true?
If yes, maybe I have not to use newSoftSerial.
Title: Re: send command via rs232
Post by: PaulS on Apr 06, 2012, 05:07 pm
Quote
I have read in somewhere that I can use pin0 and pin 1 to send data to an external device

True.

Quote
with rs232

False. You can't send RS232 signals with a TTL chip. You can send TTL level data to a MAX232 chip, which can then output RS232 levels to the device.

You can't talk to two devices using the same set of pins. You can't read from the Serial Monitor and send to your external device on the same set of pins.
Title: Re: send command via rs232
Post by: zoomkat on Apr 06, 2012, 05:43 pm
Quote
You can't talk to two devices using the same set of pins.


You can send data to numerous devices connected in parallel to the serial pins. Receiving data can have issues.
Title: Re: send command via rs232
Post by: Grumpy_Mike on Apr 06, 2012, 06:02 pm
Quote
How can I Take a wire from the RS232 TX output and connect it to the RS232 TX input?

Why are you having trouble with concept?
You use wire, you solder it from pin 2 to pin 3 on the 9 way D-type connector on your TTL to RS232 converter.
You connect the other pins of this converter to the pins you had before. You then can test if you are talking to this converter or not.
Title: Re: send command via rs232
Post by: amjlopez on Apr 06, 2012, 07:40 pm
I only want to comunnicate with external device and control it. I don't care what method to use. I'am looking in some books, Google and forums and I cannot comunnicate yet with the device.
Title: Re: send command via rs232
Post by: Grumpy_Mike on Apr 06, 2012, 11:09 pm
Quote
I only want to comunnicate with external device and control it.

Yes and you have implemented something that if you have actually wired it up like you say should work. What we are trying to do is to help you test it to see where you have gone wrong.

One way to do this is a loop back test but you have trouble in doing what was asked of you.
Your DFROBOT RS232-TTL Converter should be connected to some pins other than 0 & 1. This should be being driven by new software serial. You say it is not working so a loop back test would rule out wiring problems and software problems.
The DFROBOT RS232-TTL Converter has a 9 pin D-type socket on the end I am asking you to connect pin 2 & pin 3, You might need to have a plug to put the wires on or you can do it on the PCB side.

When you have confirmed that this setup is working you can then go on to investigate other things that could go wrong like a miss match in the baud rate or data format between your  DFROBOT and the thing you want to connect it to.
Title: Re: send command via rs232
Post by: amjlopez on Apr 08, 2012, 04:13 pm
Thank you very much. I'll tried and I'll tell you.
Title: Re: send command via rs232
Post by: amjlopez on Apr 10, 2012, 12:05 pm
I'm here again.
I have connected pin 2 to 3 to make a loopback. And when I test it I don't get response.
I have changed cables and not work.
This is the code I'm trying to test:

#include <SoftwareSerial.h>
SoftwareSerial MyDevice(7,8);  //  I don't know which is TX and RX...
void setup() {
// begin serial:
Serial.begin(9600);
MyDevice.begin(9600);
}
void loop() {
  if (Serial.available() > 0) {
   
    switch (Serial.read()) {
    case 'a':   
      MyDevice.print("1!");
      Serial.println("sent 1"); //to test in S.Monitor
      break;
    case 'b':   
      MyDevice.print("5!");
      Serial.println("sent 5"); //to test in S.Monitor
      break;
    default:
      break;
      }
}
}

thank you very much.
Title: Re: send command via rs232
Post by: PaulS on Apr 10, 2012, 12:11 pm
Code: [Select]
SoftwareSerial MyDevice(7,8);  //  I don't know which is TX and RX...
Then, why the hell don't you try to find that out? Look at the source code!

Quote
I have connected pin 2 to 3 to make a loopback. And when I test it I don't get response.

Hardly surprising, since your code does not use pins 2 and 3.
Title: Re: send command via rs232
Post by: amjlopez on Apr 10, 2012, 12:20 pm
I mistake my response.
I solder TX with RX that is the pinout of RS232 connector. This is my scheme:

DFROBOT  TX->  Arduino pin 7
DFROBOT  RX->  Arduino pin 8
DFROBOT  VCC ->  Arduino 5V
DFROBOT  GNG -> Arduino Gnd

solder in DFROBOT DB9 pinout TX and RX  (2 and 3)
Title: Re: send command via rs232
Post by: amjlopez on Apr 11, 2012, 04:44 pm
Dear all:
I have changed to an Arduino Mega.
I have tried the loopback and is OK. The character that I send, I receive it.
I have changed my code. because Arduino Mega. This is my new code:

void setup() 
{
  Serial.begin(9600);
  Serial3.begin(9600); 
}

void loop()                     
{
  if (Serial3.available()) {
      Serial.print((char)Serial3.read());
  }
  if (Serial.available()) {
      Serial3.println((char)Serial.read());
   
  }
}
I have connected my device Extron to DFROBOT RS232  through  to Serial3 of Arduino,
Then, I sent this command:   !   (admiration), and the device must respond the input selected.
But I have no response from the device.
When I send the command:  !,  I see that Rx of DFROBOT light, but doesn't light the TX light. I mean, I don't get response from the Extron device.
Can you help me please?
Many thanks
Title: Re: send command via rs232
Post by: AWOL on Apr 11, 2012, 04:48 pm
Is the bit rate correct?
Is the character format (8,n,1) OK for the receiver?
Title: Re: send command via rs232
Post by: amjlopez on Apr 11, 2012, 08:05 pm
Baud rate is 9600 for Arduino and Extron device.
Other parameters, Do I have to configure it writing code?
How can I do it?

Parameters for Extron device are:
Parity bit : none
Data bit: 8
Stop bit: 1
Handshake: none.
Thank you very much
Title: Re: send command via rs232
Post by: Grumpy_Mike on Apr 11, 2012, 11:39 pm
Quote
Parameters for Extron device are:...........

That is the same as the arduino so there is nothing extra to do.

Quote
When I send the command:  !,  I see that Rx of DFROBOT light, but doesn't light the TX light. I mean, I don't get response from the Extron device.

This would suggest you are not sending the correct command. Your code is wrong try this:-

Code: [Select]
void setup()
{
  Serial.begin(9600);
  Serial3.begin(9600);
}

void loop()                     
{
  if (Serial3.available()) {
      Serial.write((char)Serial3.read());
  }
  if (Serial.available()) {
      Serial3.write((char)Serial.read());
   
  }
}
Title: Re: send command via rs232
Post by: Techone on Apr 12, 2012, 01:07 am
Quote
Extron device


Any datasheet ? I would like to see it. Maybe you need to read the datasheet of the so call "Extron device"

Ok... You want to send ---> !  Is it ASCII code ? or a binary code ?  If I have a device to received a data, I need to know :

Baud rate
8 bits
Parity or Not
Stop bits
Start bits

So your device is : 9600 baud - 8 bits - no parity - 1 stop bit  OK
Code sequence into the device ?   Answer in the datasheet <-- Maybe  ASCII into the device ?  Answer in the datasheet <-- Maybe

You see what I mean ....
Title: Re: send command via rs232
Post by: amjlopez on Apr 12, 2012, 01:00 pm
Thank you to all.
Here you can download the manual:
http://media.extron.com/download/files/userman/68-791-01_IN1508_UG_H.pdf
At the end of the manual are the codes to control it and some samples.

Title: Re: send command via rs232
Post by: Grumpy_Mike on Apr 12, 2012, 10:56 pm
So the first thing I would do is to see if it is talking to you, the book says:-
Quote
When a power-up occurs, the switcher responds by sending the following message to the host:
Copyright 2005, Extron Electronics, IN1508, Version x.xx] Version x.xx is the firmware version number.

So write some code to see this message by transferring it from the software serial input to the hardware serial output and displaying it on your monitor.
Title: Re: send command via rs232
Post by: amjlopez on Apr 16, 2012, 10:57 am
Thank you very much.
I have tried with the new code and When I connect Extron I don't get anything.
Must be a problem with the cable? Do you know the pinout?
I don't know how to solve this.
Title: Re: send command via rs232
Post by: Grumpy_Mike on Apr 16, 2012, 11:25 pm
Quote
I don't know how to solve this.

You solve it by using the right tools. Use an oscilloscope to see that your device is sending data to you. You use it also to see that you have got the baud rate right and that the signal is the right way up. It should go to a logic one after it has finished sending stuff.
If all that checks out you look again at your software serial stuff and see it is recieving.
Title: Re: send command via rs232
Post by: amjlopez on Apr 17, 2012, 01:56 pm
How I said in a above message, I connected the device right to a PC and hyperterminal and I get the the message from Extron device.
I have no an oscilloscope is to expensive for me. Is there any other to posibility to test it? or oscilloscope software?

Do you know other cheap serial devices to make trying with Arduino and serial?
Many thanks
Title: Re: send command via rs232
Post by: AWOL on Apr 17, 2012, 02:01 pm
Tell us what equipment you do have, and what equipment you know how to use.