Arduino Nano RP2040 issues with PWM on pin D9 & D10

Hi all,

I’ve been trying to control RGB lighting with an Arduino Nano RP2040. I use pin D8, D9 and D10 to control the RGB components using PWM.

Please find below a picture of a basic setup that reproes the issues as well as matching code.

Here are the results of the experiment:
(1) When setting D8 to 255 using analogWrite, the red LED turns on, as expected.
(2) When setting D9 to 255 using analogWrite, both the green and blue LEDs turns on, when only the green should turn on.
(3) When setting D10 to 255 using analogWrite, both the green and blue LEDs turns on, when only the blue should turn on.

Here are additional experiments:
(A) When swapping the Arduino Nano RP2040 with another RP2040 sourced from a different supplier (to eliminate manufacturing issues), in the very same setup, the issues still repro.
(B) When swapping the Arduino Nano RP2040 with an Arduino Nano (plain, not RP2040), in the very same setup, the issue does not repro, the individual RGB components turn on/off as expected.
(C) This also reproes whether I include “WiFiNINA.H” or not at the top.

Thanks in advance for any help or leads,

arduousno

Setup picture:

Code:

#include <WiFiNINA.h>
#include <Arduino.h>

#define REDPIN 8
#define GREENPIN 9
#define BLUEPIN 10

void setup() {
  Serial.begin(9600);
  pinMode(REDPIN, OUTPUT);
  pinMode(GREENPIN, OUTPUT);
  pinMode(BLUEPIN, OUTPUT);
}

int iteration = 0;

void loop() {

    switch (iteration % 4)
    {
      case 0:
        analogWrite(REDPIN, 255);
        break;
      case 1:
        analogWrite(GREENPIN, 255);
        break;
      case 2:
        analogWrite(BLUEPIN, 255);
        break;
      case 3:
        analogWrite(REDPIN, 255);
        analogWrite(GREENPIN, 255);
        analogWrite(BLUEPIN, 255);
        break;
    }
    
    ++iteration;
    delay(2000);

    analogWrite(REDPIN, 0);
    analogWrite(GREENPIN, 0);
    analogWrite(BLUEPIN, 0);

    delay(500);
}

From nina_pins.h

extern NinaPin  LEDR;
extern NinaPin  LEDG;
extern NinaPin  LEDB;

You should be using the pin names built into the core LEDR, LEDB, LEDG and let the compiler sort out the chip pin access.

void setup() {
  // Set LED Pins as Outputs
  pinMode(LEDR, OUTPUT);
  pinMode(LEDG, OUTPUT);
  pinMode(LEDB, OUTPUT);
}

See this tutorial
https://learnembeddedsystems.co.uk/using-the-rgb-led-on-the-arduino-nano-rp2040-connect

Thanks for the reply cattledog.

I'm not trying to drive the RP2040 onboard LEDs, but rather external LEDs which RGB components are connected to pin 8, 9 and 10. This is what is not working for me.

arduousno

Is anybody else facing this issue and/or able to repro this issue?

arduousno

Only those who refuse to take heed of the good advice they have received.

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