Quick (hopefully) question...
I have 3 LED strips (40 LEDs each, ws2812b). I will need to program them to do mostly the same thing, ie. they will be parallel, and if there is a rainbow effect it will be the same in each strip, with some exceptions (io.e when they will be reacting to music). I have not coded these strips before and I am thinking whether it will be more convenient - to make coding easier - to wire them singularly (3 data wires connected to 3 arduino pins) rather that in series (as they normally would be connected ie only one data wire).
- One GPIO output can drive multiple strings, all will run the same animation.
Thanks Larry
I know that it is possible, but I haven't coded before so I was just wandering if the coding is easier (having 3 strips doing the same thing).
-
Easier ?
-
If the strips were doing different animations, you need separate output pins.
-
If the strips are doing the same animations you could use 1 output, saving the the other pins for other things.
-
The later would use fewer lines of code.
-
FYI
The Magic of NeoPixels | Adafruit NeoPixel Überguide | Adafruit Learning System
Practice with one strip here...
- Open wokwi.com
- In the "sketch.ino" tab, paste the sketch below
sketch.ino
#include <Adafruit_NeoPixel.h> // add this library to "Library Manager"
#define PIN 2
#define N_LEDS 40
Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
}
void loop() {
chase(strip.Color(255, 0, 0)); // Red
chase(strip.Color(0, 255, 0)); // Green
chase(strip.Color(0, 0, 255)); // Blue
}
static void chase(uint32_t c) {
for(uint16_t i=0; i<strip.numPixels()+4; i++) {
strip.setPixelColor(i , c); // Draw new pixel
strip.setPixelColor(i-4, 0); // Erase pixel a few steps back
strip.show();
delay(25);
}
}
- In the "diagram.json" tab, paste the code below
diagram.json
{
"version": 1,
"author": "Anonymous maker",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-arduino-nano", "id": "nano", "top": -33.6, "left": 220.3, "attrs": {} },
{
"type": "wokwi-led-matrix",
"id": "ring1",
"top": -109.4,
"left": -135.7,
"attrs": { "rows": "1", "cols": "40" }
}
],
"connections": [
[ "nano:2", "ring1:DIN", "green", [ "v0" ] ],
[ "nano:5V", "ring1:VDD", "red", [ "v-38.4", "h-28.8" ] ],
[ "nano:GND.1", "ring1:VSS", "black", [ "v-28.8", "h-38.4" ] ]
],
"dependencies": {}
}
thanks for the link !
I dont' know... that's why I am asking , I haven't coded LEd strips before.
If wired in series, being 3 parallel strips, I suppose I will have to tell the arduino to do something from LED1 to LED40 then, the same in the next from LED 41 to 80 (but in reverse order: from 80 to 41) so that LED 1 does the same as LED80, 2 same as 79 etc. Then the next strip is the same as the first one moving from 81 to 120.
I am also planning to have a mode of reaction to music / frequencies and then I will need the strips to do react to lows, mids and highs for example.
I am sure both things are achievable in both ways, but I wasn't sure about which way is easier to code and don't want to change the wiring later, hence my post.
It just depends on what kind of fun you want to have.
If the strips are on one output pin, the sheer number of them might make it into your deliberations about which way to go.
But 120 pixels takes only 3.6 milliseconds to show(), so that may not be important here.
You don't say which smart LED library you are using. At least one has a way to let you refer easily to conceptual smaller strips as if they were totally separate entities.
In any case, you will be three-peating some assignments, and/or doing some simple math so make things happen over here same as over there only backwards.
turn on pixel X // from one end
turn on pixel N - 1 - X // from the far end
here as X gets bigger, the pixels turn on sequential from both ends of the strip. It would be no easier on two strips, just different.
My own choice has always been to use one pin with one real strip, and use logic and maths to make what I want happen on any individual pixels or runs of them. I use calculations and also exploit lookup tables quite a bit.
I usually run animations at a constant frame rate, so some loop() time is spent figuring out the new frame set of all pixels, and once per frame I call the show() method.
a7
The pixel you want to light on any number of parallel strips will be:
row * num_columns + column. That is to say, you have rows 0, 1 and 2 and columns 0, 1, ... 39, the first pixel is (0 * 40 + 0) and the last pixel is (2 * 40 + 39). The last pixel in the first row is (0 * 40 + 39). The first pixel in the last row is (2 * 40 + 0).
@alto777
I was planning to use FastLED but I am open to suggestions if any other library offers advantages (I would not know at this stage)
In that case I may probably just stick to using one pin, as I have the advantange of using the free pins left as @LarryD said.
@xfpd
yes I think that you are right, practising on the virtual circuit may be the best way to learn and then decide. I asked in the forum because I am building the hardware part of the project at the moment and have not managed to look at the coding required as yet, but maybe I wiull put the hardware bit on pause, practice with the code and see which way best fits my needs.
Thank you all guys, for your always helpful advices!!
Ask anything you want about programming the simulation here. The simulator is a good place to organize your project ideas.
- Use a separate 470R resistor between the Arduino output pin and the LED string Data In pin (for each strip).
i.e. 3 strips means you need 3 resistors.
Ok thank you.
I have been working in the past few days, so didn't have any time to practice on the code , hopefully I will find some time this week
Will post some news asap
I am practicing with the code, and testing the LED strip with the Arduino Uno at the moment, but strangely I get only 1.1 A of current with 40 LEDs at full brightness in white colour. That's not a bad news, as I can probably get away with a smaller PSU than I initially thought, but I am a bit puzzled, as my calculation were completely wrong. I thought 120 LEDs could draw up to 7.2 A and 40 LEDs up to 2.4! The code I am using does not limit the brightness or the current. The PSU is rated 2A at 5V.
#include <FastLED.h>
#define NUM_LEDS 40
#define LED_PIN 3
CRGB leds [NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, GRB> (leds, NUM_LEDS);
FastLED.setBrightness(255);
}
void loop() {
fill_solid(leds, NUM_LEDS, CRGB::White);
FastLED.show();
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.