docs-content icon indicating copy to clipboard operation
docs-content copied to clipboard

Fixed pinouts of Red and Green led of MKR 1010 wifi led example

Open ngolf opened this issue 2 years ago • 3 comments

What This PR Changes

This swaps the pinouts of the Red and Green led. I believe the current example has them wrong (at least produces the wrong colours on my board). It also seems intuitive that the pinout order matches "R G B"

Contribution Guidelines

ngolf avatar Jun 30 '23 08:06 ngolf

@ngolf Are you sure you're using a MKR WiFi 1010 board? If so, can you share the sketch that is producing the wrong colors?

The full sketch in the tutorial produces the expected behavior on my board (GREEN, RED, BLUE, OFF):

#include <WiFiNINA.h>
#include <utility/wifi_drv.h>

void setup() {
  WiFiDrv::pinMode(25, OUTPUT); //define green pin
  WiFiDrv::pinMode(26, OUTPUT); //define red pin
  WiFiDrv::pinMode(27, OUTPUT); //define blue pin
}

void loop() {
  WiFiDrv::analogWrite(25, 255);
  WiFiDrv::analogWrite(26, 0);
  WiFiDrv::analogWrite(27, 0);

  delay(1000);

  WiFiDrv::analogWrite(25, 0);
  WiFiDrv::analogWrite(26, 255);
  WiFiDrv::analogWrite(27, 0);

  delay(1000);

  WiFiDrv::analogWrite(25, 0);
  WiFiDrv::analogWrite(26, 0);
  WiFiDrv::analogWrite(27, 255);

  delay(1000);

  WiFiDrv::analogWrite(25, 0);
  WiFiDrv::analogWrite(26, 0);
  WiFiDrv::analogWrite(27, 0);

  delay(1000);
}

Here's a reference to the unintuitive pin ordering by an Arduino firmware engineer: https://github.com/arduino-libraries/WiFiNINA/issues/24#issuecomment-428480945.

I think this example could be improved by defining constants for the RGB pins and using them inside the loop() function.

seaxwi avatar Jul 17 '23 07:07 seaxwi

Here's a reworked example that (1) declaring pin constants and (2) uses the conventional RGB order when referencing the pins:

#include <WiFiNINA.h>
#include <utility/wifi_drv.h>

const uint8_t LED_RED = 26;
const uint8_t LED_GREEN = 25;
const uint8_t LED_BLUE = 27;


void setup() {
  WiFiDrv::pinMode(LED_RED, OUTPUT); //define red pin
  WiFiDrv::pinMode(LED_GREEN, OUTPUT); //define green pin
  WiFiDrv::pinMode(LED_BLUE, OUTPUT); //define blue pin
}

void loop() {
  WiFiDrv::analogWrite(LED_RED, 255);
  WiFiDrv::analogWrite(LED_GREEN, 0);
  WiFiDrv::analogWrite(LED_BLUE, 0);

  delay(1000);

  WiFiDrv::analogWrite(LED_RED, 0);
  WiFiDrv::analogWrite(LED_GREEN, 255);
  WiFiDrv::analogWrite(LED_BLUE, 0);

  delay(1000);

  WiFiDrv::analogWrite(LED_RED, 0);
  WiFiDrv::analogWrite(LED_GREEN, 0);
  WiFiDrv::analogWrite(LED_BLUE, 255);

  delay(1000);

  WiFiDrv::analogWrite(LED_RED, 0);
  WiFiDrv::analogWrite(LED_GREEN, 0);
  WiFiDrv::analogWrite(LED_BLUE, 0);

  delay(1000);
}

seaxwi avatar Jul 17 '23 07:07 seaxwi

Mine goes (Red / Green / Blue / Off / ...) with the built in example, and (Green / Red / Blue / ...) with the reworked example you sent.

[image: image.png]

On Mon, 17 Jul 2023 at 08:40, seaxwi @.***> wrote:

Here's a reworked example that (1) declaring pin constants and (2) uses the conventional RGB order when referencing the pins:

#include <WiFiNINA.h>#include <utility/wifi_drv.h> const uint8_t LED_RED = 26;const uint8_t LED_GREEN = 25;const uint8_t LED_BLUE = 27;

void setup() { WiFiDrv::pinMode(LED_RED, OUTPUT); //define red pin WiFiDrv::pinMode(LED_GREEN, OUTPUT); //define green pin WiFiDrv::pinMode(LED_BLUE, OUTPUT); //define blue pin } void loop() { WiFiDrv::analogWrite(LED_RED, 255); WiFiDrv::analogWrite(LED_GREEN, 0); WiFiDrv::analogWrite(LED_BLUE, 0);

delay(1000);

WiFiDrv::analogWrite(LED_RED, 0); WiFiDrv::analogWrite(LED_GREEN, 255); WiFiDrv::analogWrite(LED_BLUE, 0);

delay(1000);

WiFiDrv::analogWrite(LED_RED, 0); WiFiDrv::analogWrite(LED_GREEN, 0); WiFiDrv::analogWrite(LED_BLUE, 255);

delay(1000);

WiFiDrv::analogWrite(LED_RED, 0); WiFiDrv::analogWrite(LED_GREEN, 0); WiFiDrv::analogWrite(LED_BLUE, 0);

delay(1000); }

— Reply to this email directly, view it on GitHub https://github.com/arduino/docs-content/pull/1124#issuecomment-1637531519, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARVJZK7X3WHVJDHCYQ3GFRTXQTUAPANCNFSM6AAAAAAZZREFD4 . You are receiving this because you were mentioned.Message ID: @.***>

ngolf avatar Jul 17 '23 17:07 ngolf