Data logging with Mega 2560 using Max3232

Hi all,

I am trying to use the Serial1, Serial2 and Serial 3 (pin 14-19) of my arduino 2560 to read digital signal of my lab's instruments. I used a RS232 to TTL board (MAX3232) to convert the digital signals from the instruments, however there is no response.

I did some simple test.

i sent out some letters through the MAX3232 and the used a rs232 to usb converter to convert the signal and my computer can receive the letters and displayed using the arduino software. however, when i send back some letters, the ardunio could not receive.

Here is the code:

void setup(){
Serial.begin(9600);
Serial1.begin(9600);

pinMode(13, OUTPUT);
digitalWrite(13, LOW);
}

void loop(){
// to display something in arduino software
Serial1.write("Waiting Signal....");
Serial1.println("");
delay(500);

// to see if mega2560 recieve anything from the computer
if (Serial1.available()){
Serial1.println("");
int aaa = Serial1.read();
Serial1.println(aaa);
delay(500);
digitalWrite(13, HIGH);

}

}

actually i received some random number for the variable "aaa" and the LED always turned on.

Do you know how can I change the code so that I can receive digitial signal from rs232 using max3232 and the mega 2560 board.

Hope you can help!

new_ar:
however, when i send back some letters, the ardunio could not receive.

    // to see if mega2560 recieve anything from the computer

if (Serial1.available()){
      Serial1.println("");
      int aaa = Serial1.read();
      Serial1.println(aaa);
      delay(500);
      digitalWrite(13, HIGH); 
    }




actually i received some random number for the variable "aaa" and the LED always turned on.

The fact that the LED comes on and you get numeric character codes displayed means that your Arduino DID receive data from the PC. Perhaps you should look for characters more often than once per second:

void setup() {
  Serial1.begin(9600);
  
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);

  Serial1.println("Waiting Signal....");
}

void loop() {
    // If mega2560 recieve anything from the computer, echo it back
    if (Serial1.available()) {
      Serial1.write(Serial1.read());
      digitalWrite(13, HIGH);
    }  
}

I have had strange datas also when RS232 GND and Arduino GND were not connected...

I found that Serial1.available() is unreliable.
Try Serial1.readBytesUntil ('/n',....,....);

TFO