Loading...
Pages: [1]   Go Down
Author Topic: Data logging with Mega 2560 using Max3232  (Read 1789 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!







Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 96
Posts: 6354
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

however, when i send back some letters, the ardunio could not receive.
Code:
    // 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:

Code:
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);
    } 
}
Logged

Slovakia, Europe
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Print
 
Jump to: