RS232 serial communication?

I've wired a RS232 module to pins 3 (receive) and 2 (transmit) of an Arduino Diecimila (ATmega168).

I've tried a few code samples (changing the R and T definitions to pins 3 and 2) but can't get any success.

This is the latest one I tried:

http://arduino.cc/en/Reference/softwareSerial

I'm using 9600 baud in CoolTerm and changed the baud rate in the sample code to match this.

I have the RS232 module connected to a serial/USB adapter and to my mac using CoolTerm. CoolTerm and the adapter are configured correctly: when I plug a loop-back adapter to the serial/USB adapter I get echoed characters. And typing on the Mac's keyboard makes the Receive LED flash on the RS232 module.

I must be doing something wrong.

Ideas?

Thanks.

Arduino Diecimila (ATmega168) Arduino IDE 1.6.1 Schmartboard RS232 module

You have connected pins 2 and 3. where is pin 7 connected?

Paul

You have connected pins 2 and 3. where is pin 7 connected?

Ground and +5v are supplied to the module from the Arduino. Pin 7 is grounded on the module and via the supply pins to the Arduino.

what is the default protocol for the serial library? 8 data; no parity; 1 stop bits?

Yes, 8N1 is the default.

Try a loopback through the Schmartboard. Power it with 5V and connect TD to RD.

Since that board is driving the CTS line then perhaps your serial adaptor is looking for the correct value on CTS. Try wiring that high or low (on the 5v side) with a 1k resistor or a piece of wire.

before chasing the hardware i’d like to get confirmation that the code is good.

#include <SoftwareSerial.h>
# define RxPin 3
# define TxPin 2

SoftwareSerial mySerial(RxPin, TxPin); // Receive & Transmit pins

void setup()  
{
  
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("Hello, world?");
}

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}

is it ok?

thanks.

OK, I have communication. (The problem was poorly-labeled pins on the RS232 module.)

What's the purpose of Serial.println and mySerial.println? What's the difference and why are both needed? I get printout on the terminal screen (on the Mac) with mySerial.println but not Serial.println. Is Serialprintln solely for use with the built-in USB interface? And mySerial.println is for use with a secondary serial interface (as the add-on chip I'm using)?

Still learning...

thanks.

The examples in serial input basics may be of interest.

...R

Sparkyy: OK, I have communication. (The problem was poorly-labeled pins on the RS232 module.)

With a 50% chance of wiring it up incorrectly, your first attempt will be wrong 100% of the time.

Sparkyy: What's the purpose of Serial.println and mySerial.println? What's the difference and why are both needed? I get printout on the terminal screen (on the Mac) with mySerial.println but not Serial.println. Is Serialprintln solely for use with the built-in USB interface? And mySerial.println is for use with a secondary serial interface (as the add-on chip I'm using)?

When you use that library (or almost any library) you need to create an instance of the SoftwareSerial object and you must give it a name. In the example, it is mySerial but it could be something more descriptive; whatever you want to call it.