Pages: [1]   Go Down
Author Topic: Serial Data  (Read 549 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dear All,

I hope this is in the correct forum, sorry if not. I am posting today to ask whether the Serial.begin(9600); has to be called at setup or if I can call it at any point, as the software I am writing is designed to be standalone yet you can select a computer controlled option from the menu I have created for the LCD Screen. When this computer controlled option is selected it would then be plugged in to the PC ready for control, but I do not know how long in this would be?

Failing this could I start it at the beginning and just use the serial.available() to wait for a connection once in that part of the program.


Thanks

Callum
Logged

nr Bundaberg, Australia
Online Online
Tesla Member
***
Karma: 126
Posts: 8473
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You can call it at any time before you use the port.

Quote
could I start it at the beginning and just use the serial.available() to wait for a connection once in that part of the program.
That's how you would normally do it. But isn't that the same as your first option?

Quote
the Serial.begin(9600); has to be called at setup


______
Rob
« Last Edit: April 09, 2012, 10:02:02 am by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

Germany
Offline Offline
Jr. Member
**
Karma: 0
Posts: 89
Walking on Nails
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can use Serial.begin() where you like. You should not call any Serial members when not initialized. Serial.available() tells you if a character is in the receive queue. It is not a check if the Serial is up/initialized.
Logged

loved the 68000 assembler back then and now I have to deal with THIS 8 bit thingy

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

Thanks for clarification Rob and Marek080.

Rob:
Sorry I didn't explain myself very well, in one case i.e the first paragraph would be to call it at the required time and the second case to call it in setup part of the program.

Marek080:
Thanks, for some reason I thought serial.available was a report that the serial device was connected and working.

Thanks once again.


Callum
Logged

Cleveland, TN
Offline Offline
Full Member
***
Karma: 2
Posts: 207
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't know the logic in this but I think you are still going to have problems. When you plug the Arduino into the USB port, it resets the Arduino. Evern if it is already plugged in, when you open the serial monitor it also resets the Arduino.

I think there is a trace you can cut or something to make it not do this but I don't think it is trivial.

If you are going to build a breadboard version, I think this is a non-issue but it does make one wonder why it would reset the Arduino but no a standalone Chip on a breadboard?
Logged

Luck,

Wade

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 602
Posts: 33385
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I think this is a non-issue but it does make one wonder why it would reset the Arduino but no a standalone Chip on a breadboard?
Because the arduino contains an auto reset circuit, that is a capacitor linking the DTR pin and the reset. If you miss that out on a stand alone then this will not happen. However it is harder to upload sketches because you have to hit the board's reset button at exactly the right time.
Logged

Pages: [1]   Go Up
Jump to: