Go Down

Topic: SerialUSB.print() in Output (Read 2464 times) previous topic - next topic

Mar 29, 2013, 10:41 pm Last Edit: Mar 29, 2013, 10:51 pm by Wilsonator Reason: 1
Hi I am having trouble getting the DUE to output any serial information during the setup loop. I also want to understand better the 'soft erase' procedure.

In the arduino documentation (http://arduino.cc/en/Guide/ArduinoDue):
"Opening and closing the Native port at a baudrate other than 1200bps will not reset the SAM3X. To use the serial monitor, and see what your sketch does from the beginning, you'll need to add few lines of code inside the setup(). This will ensure the SAM3X will wait for the SerialUSB port to open before executing the sketch:
while (!Serial) ;"

I assume when I upload a sketch that the Arduino IDE handles the soft erase procedure in the background? Would this be a correct assumption?

Also I cannot get any output to print to serial monitor from the setup loop I have tried the following so far to no avail:

Code: [Select]

setup() {
while(!Serial); //Tried while(!SerialUSB); as well
SerialUSB.begin(9600); //Doesn't matter speed

SerialUSB.print("Hello World");
}


As well as:
Code: [Select]

setup() {
SerialUSB.begin(9600); //Doesn't matter speed
while(!Serial); //Tried while(!SerialUSB); as well

SerialUSB.print("Hello World");
}


Can anyone tell me how I can get my setup to properly print to serial monitor when I first load it up (the same way the old atmel atmega chips would print every time you opened serial monitor).

stimmer

#1
Mar 29, 2013, 10:47 pm Last Edit: Mar 29, 2013, 10:49 pm by stimmer Reason: 1
It looks like it should say:

while(!SerialUSB);   

and it should come after SerialUSB.begin(9600);
Due VGA library - http://arduino.cc/forum/index.php/topic,150517.0.html


It looks like it should say:

while(!SerialUSB);   

and it should come after SerialUSB.begin(9600);


Tried this as well, update original post to reflect this.

No luck.

Still having problems with this. Anyone know a solution?

ageurtse

Maybe a stupid question but did you hook up your usb kabel on the native usb port, not the programming port.



Maybe a stupid question but did you hook up your usb kabel on the native usb port, not the programming port.


Indeed I have. I am having no trouble with SerialUSB.print and SerialUSB.write during the loop() {} phase of the program, but I do not get any output for the setup() {} phase of program.

Behavior on my arduino MEGA is that every time I open serial monitor the program reset from setup() {} and I see in serial monitor any print or write commands executed in setup. For the due this is not so, I never see the print and write commands that occur during setup(){}.

stimmer

The native USB port does not trigger a reset on opening the serial monitor - if it did it would cause a USB disconnect. If you need auto-reset on opening the serial monitor, use the programming port.
Due VGA library - http://arduino.cc/forum/index.php/topic,150517.0.html


The native USB port does not trigger a reset on opening the serial monitor - if it did it would cause a USB disconnect. If you need auto-reset on opening the serial monitor, use the programming port.


Makes sense. But what is this all about? It can be found in arduino documentation.
"Opening and closing the Native port at a baudrate other than 1200bps will not reset the SAM3X. To use the serial monitor, and see what your sketch does from the beginning, you'll need to add few lines of code inside the setup(). This will ensure the SAM3X will wait for the SerialUSB port to open before executing the sketch:
while (!Serial) ;"

Collin80



The native USB port does not trigger a reset on opening the serial monitor - if it did it would cause a USB disconnect. If you need auto-reset on opening the serial monitor, use the programming port.


Makes sense. But what is this all about? It can be found in arduino documentation.
"Opening and closing the Native port at a baudrate other than 1200bps will not reset the SAM3X. To use the serial monitor, and see what your sketch does from the beginning, you'll need to add few lines of code inside the setup(). This will ensure the SAM3X will wait for the SerialUSB port to open before executing the sketch:
while (!Serial) ;"


Ordinarily that line would be very funny. However, they've overloaded the boolean operator for that class so, in theory, it will return true only if the USB port is active and somebody is listening. So, that line really should be waiting until you connect a terminal program to the serial port. I don't know why that isn't working for you. Perhaps it might be a good idea to make the program wait for you to press a key before it actually progresses. This could be as simple as:
Code: [Select]

while (!SerialUSB.available());

Thanks, that last solution should work for what I'm doing.

Go Up