Arduino Communication To and From a Serial RS232 Device

SparkFun RS232 Shifter SMD (No DB9) https://www.sparkfun.com/products/8780

The Leonardo is Wired up with the Following Connections (Picture Attached)

Arduino Wire RS232 Tx Blue TX Rx Orange RX GND Green GND VCC White VCC

Shifter Out CAT6 Cable to DB9

BL/WHT Pin 2 Rx BL Pin 3 Tx OR/Wht Pin 5 GND

The following is the code that communicates with the device (Serial Terminal) but fails to communicate back through the Arduino to the USB attached to a terminal.

include

SoftwareSerial portOne (1,0); String cmd ="";

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

while(!Serial){ ; // wait for serial port to connect. Needed for native USB port only }

while(!portOne){ ; // wait for serial port to connect. Needed for native USB port only }

Serial.println ("Enter Command"); }

void loop() {

while(Serial.available() > 0) { if (Serial.available()) { portOne.print((char)Serial.read()); } }

portOne.listen(); while(portOne.available() > 0) { if (portOne.available()) { Serial.print((char)portOne.read()); }

//Serial.println(); delay(100); } }

If you are trying to connect to a proper RS232 signal then you need a level shifter such as a MAX232 to convert between the RS232 voltages and the Arduino's TTL voltages. The RS232 voltages can damage an Arduino.

...R Serial Input Basics

Hey Robin2,

I am curious - are there many RS232 devices still being used? I was VERY surprised that a telescope camera I'm using relies on RS232. It's such an inefficient protocol - the voltages are inconvenient, and the device I have has a female D9 socket. It's YUGE!

Anyone: What is the best Serial to RS232 converter to use?

Thanks!

ChrisTenone: Hey Robin2,

I am curious - are there many RS232 devices still being used?

Sorry, I am not the person to handle that question.

...R

This code and design works to communicate with the end device from the Adurino monitor, a putty terminal, and my cell phone ( the real objective) but something is wrong, i can't return communication from the end device through the Arduino to my terminal.

Any ideas?

Sorry, Just realized that I completely missed the first 2 lines of the Original Post - I took too much notice of the Title.

I'm not clear what you mean in Reply #4 - is it something like this

Arduino Serial Monitor <----------> Arduino <-------------> TTL-RS232 converter <-------------> some device

and eventually you want to replace the Serial Monitor with your phone?

What Arduino are you using? If it is an Uno then you seem to be using the same pins for SoftwareSerial as for HardwareSerial. That won't work. Move SoftwareSerial to another pair of pins and try again.

Also, can you post a link to the datasheet for the device you want to talk to so that we can see if it has any special requirements - for example with the extra control lines such as DTR and RTS.

...R

Your drawing is essentially correct

Arduino Serial Monitor <----------> Arduino <-------------> TTL-RS232 converter <-------------> some device

And my main goal is to talk to this device, but I would like to also talk to cisco equipment and other serial devices. Do you think I just need to move my software serial to different digital inputs? The arduino supports the following digital points…

Not all pins on the Leonardo support change interrupts,
so only the following can be used for RX:
8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).

GE MDS 9710A Manuals
Manuals and User Guides for GE MDS 9710A. We have 1 GE MDS 9710A manual available for free PDF download: Technical Manual

https://www.manualslib.com/products/Ge-Mds-9710a-3223754.html

I'm not familiar with the leonardo, but are pins O and 1 not used for hardware serial?

Jdillinger: Not all pins on the Leonardo support change interrupts,

If you are using a Leonardo there is no need to use Software Serial. Just use Hardware Serial1 which is connected to pins 0 and 1. HardwareSerial works much better than SoftwareSerial.

I don't have time to study the datasheet tonight but it looks like it just needs Tx Rx and GND so it should be straightforward to talk to it.

It seems to be a wireless device. What will be at the other end of the link? Is it essential to have the other end working in order to verify that your Arduino communication is working?

...R

Ok, rewrote the file and found a better solution. I am also interested if I should use stream.readBytes(buffer, length)

The following sends data to the attached terminal, but I still can read data from the terminal.


void setup(){
// set the data rate for the SoftwareSerial port
Serial.begin(9600);
while(!Serial){
;
// wait for serial port to connect. Needed for native USB port only
}

Serial.println (“Enter Command”);
}

void loop() { // run over and over

while(Serial.available() > 0) {

if (Serial.available()) {
Serial.print((char)Serial.read());
}

}

delay(100);

}

Jdillinger: The following sends data to the attached terminal, but I still can read data from the terminal.

I presume that should be "still cannot"

Assuming you are using a Leonardo and you have the TTL-RS232 converter connected to pins 0 and 1 that code is NOT sending (or receiving) data from the converter.

You need to use Serial1 to communicate over pins 0 and 1 and Serial to communicate with your PC over the USB cable.

...R