i'm currently working on a project that implements a communication between a Arduino mega 2560 and a sensor named a photomultiplicator through a rs232 adaptator. This sensor is wired on the Serial2 of the board and it has a strict list of commands that we can send to him. Once the command send, it responds by sending 2 characters that represent a report of the good reception of the command. For instance i send : D carriage_return and it replies VA for saying the command is valid.
Anyway before even plug the sensor to the board, i link the board to computer with its RS232 connector so i check the data i plan to send. I'm on Linux so i open a cutecom (a terminal to chat with Arduino through RS232) and when i plug the board, so when the program starts to run i notice that i receive 2 null characters -> 0x00 twice.
This is a big problem to me because the sensor will read them and the first command i'll try to give him it will reject it.
Is there a way to flush the Serial2 before or somehow solve this? i check the flush method on the serial library but it doesn't match with what i want.
Sorry if the english ain't good and thanks in advance
If I understand correctly you want the Arduino Mega to send commands to the sensor device using Serial2. You say you connect Serial2 to your PC (using cutecom on the PC) and it appears to send 0x00 to the PC when the Mega is started up.
How is the Mega powered?
Can you post a copy of your code or (if it is long) a short sketch that illustrates the problem.
No it's the contrary actually.
Through the command cutecom on my computer in a terminal, i can see that 2 0x00 are sent to the sensor right after downloading the program into the board and each time the program reload (for instance each time i open a monitor in the arduino ide).
So where is the diagram of your hardware and where is the code. No one else has problems with extra chars being sent so the problem is at your end. With the diagram and the code no one can help you.
You normally need physical pull-up resistors on the TXn pins to prevent then
floating at powerup. The RX/TX pins itself already have them I believe, but the rest default
to INPUT.
I was avoiding posting my code since i don't have only the main sketch on arduino but other external cpp's.
I'm only pasting here the code where lies all the Serial2 calls. We got here the main sketch and the Photomultiplicateur.cpp which is the class for my sensor (sorry my variable names are in french :s )