Blink on Pro micro RP2040?

I just got a couple of Pro micro RP2040 boards and thought I’d try the quick blink test using the Arduino IDE (2.2.1). That took longer than I expected! Here’s my question, why can’t I get the WS2812 to blink? I’m using this code:

int led = LED_BUILTIN; // the pin the LED is attached to

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(led, OUTPUT);
}

int ledOn = 0;

void loop() {
  // put your main code here, to run repeatedly:
  Serial.print("Set LED ");
  Serial.println(ledOn);
  digitalWrite(led, ledOn);
  ledOn = !(ledOn);
  delay(1000);
}

The serial monitor shows this:

Set LED 0

Set LED 1

Set LED 0

Set LED 1

Set LED 0

Set LED 1

Set LED 0

I’m surprised the code compiles without throwing an error. Reason being, the WS2812 LED on the pro micro rp2040 isn’t a regular LED like the code is assuming.

There are a few points to consider that will help explain why the code isn’t doing what you expect it to do.

First point, what this code does is toggle the LED pin between two states of voltage. Either 0 volts (LED on) or 3.3 volts (LED off) That might seem backwards but it seems backwards depending on how the LED is wired. If the LED is wired such that one leg is tied to 3.3 volts, it turns on when the “LED pin” goes to 0 volts because current flows through the LED between the two different voltages. If both sides of the LED are at the same voltage, no current will flow. (Hence why 0 volts makes the LED turn on, because the other side of the LED is connected to 3.3 volts.) When the “LED pin” is at 3.3 volts the LED doesn’t light because both sides are at 3.3 volts so no current flows. (The exact opposite would happen if the other side of the LED was connected to ground. For example, if the “LED pin” was at 3.3 volts, current could flow through the LED and it would light.)

Second point, If a regular LED was on the board, you should see it blink when you run this code for the reasons in the first point. But… the LED used on the pro micro RP2040 isn’t your typical LED, it’s a special LED that has a little controller circuit built into it. That controller isn’t looking for a simple high/low signal to turn the LED on or off, it’s looking for a special sequence of highs and lows that instruct the controller what you want the LED to do. (Like how bright the LED should be and what color you want the LED to light up.) Since your code just sends zero or 3.3 volts and not the special sequence, the LED doesn’t do anything.

So, what I’d suggest to make the code work the way it should, would be to not use the built in LED and instead use your own LED and a resistor. Any old 2 pin LED and a 330 ohm resistor will do. Connect the anode (positive) pin of the LED to the 3V3 pin on the board and connect the cathode (negative) pin on the LED to one leg of the 330 resistor. Then connect the other leg of the 330 ohm resistor to the “2” pin on the board.

Now, modify the code to change the part where the code uses “LED_BUILTIN” to change it to use pin 2 instead like this:

int led = 2; //-----> the *NEW* pin the *NEW* LED is attached to, this is what we're changing in code. <------

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(led, OUTPUT);
}

int ledOn = 0;

void loop() {
  // put your main code here, to run repeatedly:
  Serial.print("Set LED ");
  Serial.println(ledOn);
  digitalWrite(led, ledOn);
  ledOn = !(ledOn);
  delay(1000);
}

What this will do is toggle pin 2 on the board between 3.3 volts and 0 volts once a second. Since the “new” LED that you have connected is a regular LED, it will light up whenever there’s 0 volts on one side and 3.3 volts on the other, which is what the code is assuming all along. :slight_smile:

If you want to light up or blink the built in LED, it gets a bit more complex as you will need a library and different code that sends the proper commands to the WS2812 LED that instruct it to turn on and off. (and additionally if you want, how bright to be and what color to light up!)

I haven’t tested this code as I don’t have a pro micro RP2040 but it should work to blink the built in LED on the board. It does require you to install the adafruit neopixel library for it to work. Instructions for installing the neopixel library can be found in the link below.

https://learn.adafruit.com/adafruit-kb2 … el-blink-2

#include <Adafruit_NeoPixel.h>

#define LED_PIN 25  // ---> This is the pin the WS2812 LED on the sparkfun board listens to commands on <----
#define LED_COUNT 1

Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  strip.show();
  strip.setBrightness(50);
}

void loop() {
  setRingRed(false);
  delay(1000);
  setRingRed(true);
  delay(1000);
}

void setRingRed(bool off) {
  for (int i = 0; i < strip.numPixels(); i++) {
    strip.setPixelColor(i, strip.Color(off ? 0 : 255, 0, 0));
  }
  strip.show();
}

Thanks for the explanation!

I was trying to proceed based on the information in the Pro Micro RP2040 Hookup Guide which says, " The other is the addressable WS2812 RGB LED. The addressable LED is connected to GPIO25. You’ll to define functions or use the WS2812 library to control that LED."

Perhaps someone could add some of the information in this answer to the Guide?