I have problems with arduino mega serial communication

Hello, I have problems with arduino mega serial communication.

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


  Serial1.println("Goodnight moon!");
}

void loop() { // run over and over

}

When you are sending the same data in a arduino one, if it works.

Please help

Captura.JPG

Well, the while(!Serial) only applies to boards such as the Due and Teensy which have USB serial. It should have no effect on the Mega but I'd still delete it for this test.

This will send "Goodnight Moon!" once only. Move that into the loop() so that it will keep sending the message continuously. Then see if you can get the text coming out of the Tx1 pin.

Your intentions are far from clear but it would appear that you might want a your Mega to say "Goodnight Moon" once to the serial monitor.

If that is the case, change the Serial1 commands to just plain Serial. Also delete the redundant and nonsensical while command. Then see what happens.

both the virtual terminal as the serial port are configured the equal.

void setup(){
  
  Serial1.begin(38400);
  

}

void loop() {
 
  Serial1.println("Hello Serial 1");

}

Not be if is proteus, but with arduino one works

Help

OK, it looks like you really do want to send a stream of hellos out of Serial1 Tx. In that case there is nothing wrong with your code, and all the problems are at the other end, i.e. the foreign and incomprehensible device. It seems that you want to connect to a D15 RS232 socket. It is faintly possible that the problem is that you are sending a 5v signal to RS232 which, would prefer 12v, i.e. you are not sending a proper signal and you need conversion hardware.

There are probably better ways to do what you want. Using a real terminal on a PC might be one. It would certainly be a good place to start.

Ok, what does "proteus" mean? Is it a board or device or software? How is it wired?

This code won't compile on an Uno so I can't understand that sentence.

Please try to describe the problem fully: what you want to happen, what you tried and what the actual result was. Ask questions by writing sentences that end in question-marks (?). With short answers like "it doesn't work" we can't help you with whatever "it" is.

@Morgan, both codes compile OK for a Mega. I imagine the problem is downstream from pin18.

I think you need a real Mega, not a simulator.

Hello, I have the same problem.
The example ASCII table works with Arduino Uno but it doesn't work with Arduino Mega.
Somebody can resolve it ?

Thanks.

distelg:
Somebody can resolve it ?

Not unless you post the program that is causing the problem.

And when posting code please use the code button </>so your code looks like thisand is easy to copy to a text editor See How to use the Forum

...R

distelg:
Hello, I have the same problem.

And if you're using a simulator, ask the simulator guys. The original post worked out to be for Proteus.