Blink on a few microcontrollers

A follower of the blog sent me what I think is a pretty good question: “Why does everyone do a blink with a new board.” I thought I would take a few minutes to answer my take on this question. Plus, I’ll post examples of blink from various microcontrollers.

Links to hardware used can be found at the end of this post. Some of them may be affiliate links.

Why do a blink?

Blink is the Hello World of the microcontroller world. First and foremost, blink allows a person to test whether they can successfully write code to a board. Most of the time, we are programming these boards through a USB connection that emulates a serial port. There is a lot that can go wrong in this process. Running a quick program to blink an LED tests communication with the board. This will give us at least some comfort that communication with the board is operating as expected.

Another thing tested during the blink test is that the microcontroller being used has a bootloader installed. Not all microcontroller chips come pre-installed with a bootloader. Installing a bootloader isn’t that hard, but it is essential to know right away if we need to do so. When using cheap clone microcontrollers, it is not unusual to get boards without a bootloader. Or if the board has a bootloader, it might have one older or different than expected. These need to be known right away before trying to do anything else with a microcontroller.

Serial monitor addition.

Like some other makers, I usually modify my blink code to include messages in the serial monitor. That way, I am confirming that I can program a board and receive information back from the board. Doing so during the blink test is the perfect time to do so.

I’ll also note that I typically leave the serial port baud rate to the default of 9600 for Arduino boards and clones. However, on some boards, I change the baud rate to what the manufacturer recommends. For newer boards, that seems to be a baud rate of 115200.

Blink examples

Here are some examples of the blink code I use on various microcontrollers. I usually try to blink an LED and receive communication back through the serial port in each case.

Arduino Uno

The Arduino Uno is one of the more popular places for people to get started working with microcontrollers. The Arduino IDE comes with a nice blink sketch already written. The code I use is just the blink sketch with the serial monitor showing whenever the LED is on (high) or off (low). The programmable built-in LED on the Arduino UNO is digital pin 13. But the Arduino IDE already has this pin mapped to LED_BUILTIN, so it doesn’t have to be declared.

One nice thing about the Uno is that we don’t have to worry (as much) about different boot loaders. Here is what I chose in the Arduino IDE to program the Hero board:

Here is the blink sketch I use for a UNO:

void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
  // initialize serial communication at 9600 bits per second
  Serial.begin(9600);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  Serial.println("High");
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  Serial.println("Low");
  delay(1000);                       // wait for a second
}

In this case, I programmed a Hero Uno from inventr.io with this sketch. Below is a video of the Hero Uno board running the blink sketch with serial monitor. The built-in LED is the one at the bottom. You will also notice the LED below the power light is also blinking every second. This is the board sending serial communication to the serial port every second.

Arduino Nano

If I’m using an Arduino (or Arduino clone), I am usually using a Nano. The smaller form factor and a plethora of I/O pins make it perfect for most builds. For the Nano, I use the same blink sketch as previously. But with the particular Nano I’m using in the video below, I have to set the Arduino IDE to use the old bootloader. If you are having problems uploading to a Nano, the first thing to do is try uploading with the old bootloader’s processor.

Once the processor has been set correctly, the same blink sketch used with the Uno can be uploaded. Below is an example of the Nano blinking its LED and sending High and Low to the serial port.

The very bottom LED on this board, as pictured, is the built-in LED. Notice you can once again see the serial communication LED (just above the power LED on this board) also briefly blinks every second as it sends High and Low to the serial port.

QT PY

Lately, I’ve been using a lot of Adafruit boards. In particular, I’ve grown to like the QT PY. This low-power board is easy to fit in cosplay items. Plus, learning CircuitPython has been pretty fun. A lot of Adafruit dev boards use a built-in D13, just like the Arduino. That makes running blink on them pretty easy. But the QT PY is a little different. It has a built-in RGB, which has to be programmed slightly differently.

Below is the code I use to run blink on the QT PY. Note, I am using CircuitPython and editing the cody.py file with Mu.

import time
import board
import neopixel

pixels = neopixel.NeoPixel(board.NEOPIXEL, 1)

while True:
    pixels.fill((255, 0, 0))
    print("High")
    time.sleep(0.5)
    print("Low")
    pixels.fill((0, 0, 0))
    time.sleep(0.5)

Notice I am still sending High and Low messages out to the serial monitor. I am also setting the NeoPixel to red (255, 0, 0), but you can choose any color.

Here is the QT PY running the blink code:

Notice the QT PY does not have an actual power light. Plus, there is no LED that blinks when serial communication is taking place.

RasPi Pico

Last but not least, I will share running blink on the Raspberry Pi Pico. This low-cost board hit the market hard earlier this year. I can get this board cheaper than many of the Arduino Nano clones I’ve been using. I want to add a couple of features, but I feel manufacturers such as Adafruit and Espressif will develop boards featuring the RP-2040 with the features I would like.

For this board, I chose to use MicroPython. It should be noted the built-in LED is pin 25. I am also using Thonny to program the Pico.

from machine import Pin
from time import sleep

led = Pin(25, Pin.OUT)

while True:
    led.on()
    print("High")
    sleep(1)
    led.off()
    print("Low")
    sleep(1)

This blink script is doing the same as all the rest. It is blinking the LED every second while sending High and Low data to the serial port.

Here is the Pico running this code:

led.off

That is the end of this post. I just wanted to share examples of Blink on different development microcontroller boards. I actually have other examples of blink for various boards in previous posts. Maybe I’ll go back and blink blog more boards I have sitting around (if I find that odd thing called free time, that is).

Hardware used in this post

These are affiliate links to hardware used in this post. I may earn compensation from qualifying links. See my Affiliate Links page for more information.

Arduino UNO. I used a clone in this example. But a genuine Arduino UNO can be found in this Amazon associate link.

Nano V3.0 CloneAmazon associate link.

Adafruit QT PY. This is not an affiliate link. It can be found on the Adafruit website.

Raspberry Pi Pico, with headers. Amazon associate link.

Song of the Day: Don’t Blink

I’m not a huge Kenny Chesney fan, but this is the first song that came to mind when I started thinking about blink. This is a good song, though, with a great message.

Bonus Song: Blink-182

Another act of which I’m not exactly a fan. But how I talk about blink without including blink-182. They do have some good tracks, though, like this one.

Leave a Reply