
With the code uploaded you should see the RX and TX LEDs take turns
blinking on and off every second. You can also open up the serial monitor
(set to 9600 bps) and see every programmer’s favorite two-word phrase.
Understanding the Sketch
The RX LED is tied to Arduino’s pin 17. You can control it just as you would
any other digital pin. Set it as an
OUTPUT
, and
digitalWrite([pin],
[level])
it
HIGH
or
LOW
. The TX LED was not
provided as an Arduino-defined pin, unfortunately, so you’ll have to use a
pair of macros to control it.
TXLED1
turns the LED on, and
TXLED0
turns
the LED off.
In that sketch, you’ll also notice a pair of
Serial
initialization statements:
Serial.begin(9600)
,
Serial1.begin(9600)
. That ‘1’ makes a huge
difference. Think of the Pro Micro having two separate serial ports. The one
without
the ‘1’ is for communication to and from the computer over USB;
this is what is visible in the Serial Monitor. The
Serial1
port is a bonafide,
hardware UART
, where your Pro Micro can talk to any serial-enabled piece
of hardware.
If you open up the
Serial Monitor
, you should only see ‘Hello world’
printed. ‘Hello!’ is being sent out over the hardware UART, where,
presumably, nothing is listening. This begs the age-old question: “if a Pro
Micro is saying ‘Hello!’ over the hardware serial port, and nothing is there to
hear it, does the Pro Micro really say anything at all?.”
Why Does My Board Re-Enumerate Every
Upload?
In order to communicate serially, the Pro Micro emulates a
virtual serial
port
. Actually, it emulates two different serial ports – one for the bootloader,
and one for the sketch. Since the bootloader and sketch run individually.
Only one of these serial ports is visible at any one time.
When you click ‘Upload’ in the Arduino IDE, the Pro Micro resets itself and
starts its
bootloader
program. (The bootloader is a low-level program on
the Pro Micro which enables self-programming via serial.) To our operating
system, the bootloader looks like a completely different device, so it gets its
own serial port number. While the Pro Micro is being programmed, the
bootloader serial port will be open. When the sketch upload is finished, the
bootloader will exit, that serial port will be closed, and the regular Pro Micro
serial port will open up.
What this all boils down to is the fact that you have to
be patient
with Pro
Micros. Every time you upload a new sketch, your OS will need to work its
driver magic before you can open up the COM port. This can take a few
seconds after the code has finished uploading.
Page 17 of 27