1

I am trying to read data from RS232 Shield with an Arduino Mega.

This is the schematic pin, TX is 3 and RX is 2.

Wiring: PC > USB-RS232 cable > Arduino RS232 Shield. Software to send/receive data: Hercules Setup Utility

From Arduino, I can transmit data to RS232, the TX led blink and I got the value at PC. From PC, I send the data, the RX led blink but nothing is showed in Arduino Monitor.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port 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());
  }
}

I also tried to move RX and TX to Pin 15 and 14 but worked as the same as before.

8
  • What does the 'RS232 direction pin' do? If its only working one way then that would be the first place I would look at. Also do you have you SD Shield plugged in at the same time? Commented Jul 7, 2017 at 15:14
  • @CodeGorilla Sorry, it was direction to RS485. And no, SD Card. Commented Jul 7, 2017 at 15:17
  • You're going to need to clarify if you have RS232 as in the title or RS485 as in the code, and you're going to need to show the full system wiring. When you say PC, do you mean the one connected to the RS232 or RS485 connector, or do you mean the one connected to the Arduino USB port? On the end which is not the Arduino serial monitor, what are you using to send/receive data? Commented Jul 7, 2017 at 15:41
  • @ChrisStratton forget RS485, just deleted that code, I wont use RS485 for nothing. I am using Hercules setup utility. Commented Jul 7, 2017 at 15:53
  • Ok, but the question remains too incomplete to be answerable. Commented Jul 7, 2017 at 15:55

1 Answer 1

0

Found the problem, cant use PIN 2 as RX.

Note: Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.