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.
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.
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.