RP2040 Connect RGB LED still glows after analogWrite(LEDR, 255);

I just experimentet with my new Arduino RP2040 Connect and played with the onboard RGB LED.
When i tried to turn the LEDs on and off using the analogWrite-Function, i noticed a glow of the LEDs when they should have been turned off.
Is this normal or did i miss something? Is this a bug?

/* This sample code shows some behaviour of the RGB-LED (LEDR in example used).
 * I'm unable to turn the LEDs off, after activating them with analogWrite(led, 0). 
 * The LEDs still glow.
 * I have to repeat the OUTPUT-assignemnt, to turn them completely off.
 * Is this normal?
 */
#include <WiFiNINA.h>

void setup() {
  // use LEDR as output
  pinMode(LEDR, OUTPUT);  //LEDR, LEDG, LEDB
}

void loop() {
  // turn LEDR on (max brightness)
  analogWrite(LEDR, 0);
  delay(1000);
  // turn LEDR off (expected: no light at all, found: LEDR still glows)
  analogWrite(LEDR, 255);
  delay(1000);
  // trying to turn LEDR completely off (with digitalwrite)
  // doesn't work either, LEDR still glowing
  // if LEDR would have been activated by digitalWrite(LEDR, HIGH); this would turn LEDR completely off 
  digitalWrite(LEDR, LOW);
  delay(1000);
  // setting LEDR as output (again) and then calling digitalWrite - turns LEDR off
  pinMode(LEDR, OUTPUT);
  digitalWrite(LEDR, LOW);
  delay(1000);
}

First, thank you for providing a small program example that demonstrates the problem. Also for using code tags.

I don't think the problem is in your code. Post a schematic. (NOT a pretty Fritzing picture. Fritzing pictures are not schematics that engineers can read).

1 Like

Thank you for your reply and your compliments - it's my first post in this forum :slight_smile:

I'm just using the Arduino RP2040 Connect without any additional parts - the RGB-LED is onboard.
(Sorry, i forgot to mention "onboard" - i have added this to the original post)

I suspect that this is because the blue and green LEDs share a GPIO with the WiFi data lines.

If you use discrete LEDs and user GPIO ports, then your code shpuld work just fine.

Hmm, i'm not sure.
It also happens with the red LED and there is no wlan traffic which could influence the LEDs. Also switching the LEDs with digitalWrite(LEDR, HIGH/LOW) turns them perfectly on and off without any glowing.

Your post was MOVED to it's current location as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

1 Like

I had a look at the signal and it is clearly created by the analogWrite function.

There are pulses with a frequency of 1kHz.

The pulses are 3.91us in length which is ~1ms / 255

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.