send command via rs232

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.

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.

1 Like

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

Serial.print("2!");

Thank you:
with this command I send it to the Serial Monitor but not on the external device.
many thanks

Then your description of how the device is connected,

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?

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.

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.

Do you know what is it wrong?

No.
Where's the code?

the connections are right

Connected the ground?
Have you tried swapping over TX & RX?
If so post your code.

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.

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.

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.

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 )

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

Loop-back tx to rx.

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.

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

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.

excuse me but I don't understand. Is my first time doing this.
thanks again

How can I Take a wire from the RS232 TX output and connect it to the RS232 TX input?