Pages: [1]   Go Down
Author Topic: SerialUSB.print() in Output  (Read 1940 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
setup() {
while(!Serial); //Tried while(!SerialUSB); as well
SerialUSB.begin(9600); //Doesn't matter speed

SerialUSB.print("Hello World");
}

As well as:
Code:
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).
« Last Edit: March 29, 2013, 04:51:28 pm by Wilsonator » Logged

Offline Offline
God Member
*****
Karma: 32
Posts: 507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It looks like it should say:

while(!SerialUSB);   

and it should come after SerialUSB.begin(9600);
« Last Edit: March 29, 2013, 04:49:20 pm by stimmer » Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Still having problems with this. Anyone know a solution?
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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(){}.
Logged

Offline Offline
God Member
*****
Karma: 32
Posts: 507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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) ;"
Logged

Earth
Offline Offline
Sr. Member
****
Karma: 14
Posts: 330
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
while (!SerialUSB.available());
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: