Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix setPin() for RP2040 #389

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

fix setPin() for RP2040 #389

wants to merge 1 commit into from

Conversation

hlcm0
Copy link

@hlcm0 hlcm0 commented May 18, 2024

change

fix setPin() for rp2040. Make it possible for rp2040 to support more than 8 led strips. (as #329 mentioned)

modification:

  #if defined(ARDUINO_ARCH_RP2040)
  if (!init)
  {
    delayMicroseconds(100);
    pio_gpio_init(pio, p);
    pio_sm_set_consecutive_pindirs(pio, sm, p, 1, true);
    pio_sm_set_sideset_pins(pio, sm, p);
  }
  #endif

the code uses pio_sm_set_sideset_pins function to reconfigure the ouput pin of the state machine on the fly.
delayMicroseconds(100) is needed because we need to make sure that the state machine has finished sending bits on the previous pin.
I also rearrange the order of the code for the same reason.

test:

#include "Adafruit_NeoPixel.h"

#define PIN0 0
#define PIN1 1

#define NUMPIXELS 16

Adafruit_NeoPixel pixels(NUMPIXELS, PIN0, NEO_GRB + NEO_KHZ800);

void setup() {
  pixels.begin();
  pixels.clear();
}

void loop() {
  pixels.setPin(PIN0);
  pixels.show();   // Send the updated pixel colors to the hardware.
  pixels.setPin(PIN1);
  pixels.show();   // Send the updated pixel colors to the hardware.
}

And it worked fine.

signals are being sent out alternately from the two ports as expected:
ws2812

scale up view:
ws2812_scale_up_view

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant