Pro Micro & Fio V3 Hookup Guide

Pages
Contributors: jimblom
Favorited Favorite 11

Example 1: Blinkies!

The Arduino-standard Blink sketch won't have any visible effect on the Pro Micro -- there's no LED on pin 13. In fact, the only LEDs on the board are the power indicator, and RX/TX blinkies. Unlike other Arduino boards, though, we can control the RX/TX LEDs in our sketch. So let's get blinking!

Upload the RX/TX Blinky, Hello World Sketch

Copy and paste the code below into the Arduino IDE. Make sure to select the correct board and COM port that your respective board enumerated to. Finally, upload [1] it to your Pro Micro

language:c
/* Pro Micro Test Code
   by: Nathan Seidle
   modified by: Jim Lindblom
   SparkFun Electronics
   date: September 16, 2013
   license: Public Domain - please use this code however you'd like.
   It's provided as a learning tool.

   This code is provided to show how to control the SparkFun
   ProMicro's TX and RX LEDs within a sketch. It also serves
   to explain the difference between Serial.print() and
   Serial1.print().
*/

int RXLED = 17;  // The RX LED has a defined Arduino pin
// Note: The TX LED was not so lucky, we'll need to use pre-defined
// macros (TXLED1, TXLED0) to control that.
// (We could use the same macros for the RX LED too -- RXLED1,
//  and RXLED0.)

void setup()
{
  pinMode(RXLED, OUTPUT);  // Set RX LED as an output
  // TX LED is set as an output behind the scenes

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

void loop()
{
  Serial.println("Hello world!");  // Print "Hello World" to the Serial Monitor
  Serial1.println("Hello! Can anybody hear me?");  // Print "Hello!" over hardware UART

  digitalWrite(RXLED, LOW);   // set the RX LED ON
  TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF
  delay(1000);              // wait for a second

  digitalWrite(RXLED, HIGH);    // set the RX LED OFF
  TXLED1; //TX LED macro to turn LED ON
  delay(1000);              // wait for a second
}

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 Arduino IDE's serial monitor (set to 9600 bps) and see every programmer's favorite two-word phrase.

Hello World

Understanding the Sketch

RX LED

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 to turn the LED off or LOW to turn the LED on. Here's part of the code highlighted.

language:c
int RXLED = 17;  // The RX LED has a defined Arduino pin
void setup(){
  pinMode(RXLED, OUTPUT);  // Set RX LED as an output
}
.
.
.
  digitalWrite(RXLED, LOW);   // set the RX LED ON
  digitalWrite(RXLED, HIGH);    // set the RX LED OFF

TX LED

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. Here's part of the code highlighted.

language:c
TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF
TXLED1; //TX LED macro to turn LED ON

Serial Monitor (Serial) and Hardware Serial UART (Serial1)

In that sketch, you'll also notice a pair of Serial initialization statements:

language:c
  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 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! 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 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.


[1] 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 Pro Micro's bootloader, but it's unable to get everything set up before the bootloader exits.