Serial.begin(9600); //This pipes to the serial monitor
Serial.println("Initialize Serial Monitor");
Serial1.begin(9600); //This is the UART, pipes to sensors attached to board
Serial1.println("Initialize Serial Hardware UART Pins");
That "
1
" makes a huge difference. Think of the Qwiic 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 Qwiic 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! Can anybody hear me?
'
is being sent out over the hardware UART, where, presumably, nothing is listening. This begs the age-old question:
"If a Qwiic Pro Micro is saying 'Hello!' over the hardware serial port, and nothing is there to hear it, does the Qwiic
Pro Micro really say anything at all?"
Why Does My Board Re-Enumerate Every Upload?
In order to communicate serially, the Qwiic 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 Qwiic 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 Qwiic 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 Qwiic 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.
Note for Windows users
: The first time you upload a sketch, it may fail and give you an error. On top of that,
Windows will pop up that familiar '
Device driver software was not successfully installed
' notification. Don't let this
worry you too much. If you get the error, wait about a minute, and try uploading again.
Hopefully the upload will succeed the second time, but if it continues to fail, check out the how to enter the
bootloader section of the FAQ. Windows needs to install the same driver we've already installed for the Qwiic Pro
Micro's bootloader, but it's unable to get everything set up before the bootloader exits.
Example 2: HID Mouse and Keyboard
When the Pro Micro's were released, the most revolutionary feature (as far as Arduinos go) is its true USB
functionality. The Pro Micro can be programmed to emulate any USB device you could imagine. You can even
program it to act just like a mouse, keyboard, or other HID-class USB device.
What is
HID
?