this doesn't seem to be an issue with Arduino itself, but I'm having the following problem. I just started using an Arduino this week, and I'm familiar with c-based languages (PHP specifically) so this shouldn't be a coding problem.
I would like to print a line of code each time the Arduino starts. This is obviously easy:
The problem is not whether this is actually happening (the TX light flashes once during startup so I know it's being sent), the problem is I can't see it happening for the following two reasons:
I can't open the serial monitor until after the Arduino is physically connected to the computer, so I miss the first output (all output from the loop() shows up just fine)
When using terminal as a screen screen /dev/tty.usbmodem621 then unplugging and replugging in the Arduino looses the original connection and nothing new is output, same result by simply pressing the reset button.
I'm just confused as to how I'm supposed to be able to see the first message sent during the setup() if I can't connect a screen before that function runs?
I'm running OSX Mountain Lion with an Arduino Micro.
Since the Micro, like the Leonardo, uses software USB instead of a hardware USB-to-Serial adapter you need to add some code:
"This change means that if you're using any Serial print(), println() or write() statments in your setup, they won't show up when you open the serial monitor. To work around this, you can check to see if the serial port is open after calling Serial.begin():
Serail.begin(9600);
// while the serial stream is not open, do nothing:
while (!Serial) ;
alyda21:
I'm familiar with c-based languages (PHP specifically) so this shouldn't be a coding problem.
PHP isn't C-Based. PHP is its own language.
The Arduino is programmed with C++ and some nice libraries to make programming easier. It isn't C-based, it is C.
alyda21:
I can't open the serial monitor until after the Arduino is physically connected to the computer
In addition to the "serial wait" code suggested by John, keep in mind that each time your computer opens the serial port, it will cause the Arduino to reset. So opening the Serial monitor or running screen, causes a reset. It's called Auto-Reset.
Thanks johnwasser, your explanation and reference helped me to understand what was happening.
and James C4s, all I meant was that I am familiar with the code structure because of my background in PHP. I myself wondered why I was able to understand the code without knowing anything about Arduino itself, until I found this: List of C-family programming languages - Wikipedia.
Quote
PHP isn't C-Based. PHP is its own language.
True, but the structure is very much like C, and many of the functions in PHP are mapped exactly to corresponding C functions.