-
Notifications
You must be signed in to change notification settings - Fork 65
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
Splitting Universe Channels #28
Comments
It is always a good idea to reduce the amount of resources. :-)
Doing it all in one universe is as simple as:
Note: This is more pseudo code than copy/paste-ready! |
I have a Similar Question. I am Planning on Having Multiple ESP32 Each with a String on LEDS attached to Create Free standing light poles. My question is how do I offest the Start address for each string of lights. my setup is 30 RGB Lights per ESP32, Which is 90 Channels using this code
How would i do this? |
@chaosdesignnz
For a "reasonable" scaling option, the DHCP-based solution is the best one. There is only one firmware for all nodes, but you have to control the DHCP-server inside the network.
Note: Pseudo code!! Don't like any of the above options? Let me know. |
Hallo rstephan, thanks for your great Project. Can you give me a hint ? Best Regard from Hannover |
Hey all, rstephan thanks for your help on this unfortunately the project got postponed and I didn't make much process on the code, hopefully the project starts up again this year though! However, on the off chance this helps anyone browsing I've included the code (at the end) which sends different universe to different pins and includes AccelStepper (just random positions). Andreas you may be able to use this as a base and control the steper position with a DMX address as per the reccomendation on the second post;
or setting chanels from one universe
Compiled Code: //********************************STEPPER DEFINE******************************** #include <Stepper.h> const int stepsPerRevolution = 2048; // change this to fit the number of steps per revolution // Define a stepper and the pins it will use Stepper myStepper(stepsPerRevolution, 15, 2, 0, 4); //********************************ARTNET DEFINE******************************** #include <ArtnetWifi.h> #include <Arduino.h> #include <FastLED.h> // Wifi settings const char* ssid = "SSID"; const char* password = "pAsSwOrD"; // FASTLED settings //LED Strip 01 const int numLeds1 = 128; // CHANGE FOR YOUR SETUP const int numberOfChannels1 = numLeds1 * 3; // Total number of channels you want to receive (1 led = 3 channels) const byte dataPin1 = 12; CRGB leds1[numLeds1]; //LED Strip 02 const int numLeds2 = 128; // CHANGE FOR YOUR SETUP const int numberOfChannels2 = numLeds2 * 3; // Total number of channels you want to receive (1 led = 3 channels) const byte dataPin2 = 14; CRGB leds2[numLeds2]; //Total Number of Channels const int numberOfChannelsTot = numberOfChannels1 + numberOfChannels2; // Art-Net settings ArtnetWifi artnet; const int startUniverse = 1; // CHANGE FOR YOUR SETUP most software this is 1, some software send out artnet first universe as 0. // Check if we got all universes const int maxUniverses = numberOfChannelsTot / 512 + ((numberOfChannelsTot % 512) ? 1 : 0); bool universesReceived[maxUniverses]; bool sendFrame = 1; int previousDataLength = 0; // connect to wifi – returns true if successful or false if not boolean ConnectWifi(void) { boolean state = true; int i = 0; WiFi.begin(ssid, password); Serial.println("Connecting to WiFi"); // Wait for connection Serial.print("Connecting"); while (WiFi.status() != WL_CONNECTED) { delay(random(250, 1000)); Serial.print("..."); if (i > 0) { state = false; break; } i++; } if (state) { Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); } else { Serial.println("Connection failed."); ConnectWifi(); } return state; } //RGB Light Test //LED 01 void initTest1() { for (int i = 0 ; i < numLeds1 ; i++) { leds1[i] = CRGB(127, 0, 0); } FastLED.show(); delay(500); for (int i = 0 ; i < numLeds1 ; i++) { leds1[i] = CRGB(0, 127, 0); } FastLED.show(); delay(500); for (int i = 0 ; i < numLeds1 ; i++) { leds1[i] = CRGB(0, 0, 127); } FastLED.show(); delay(500); for (int i = 0 ; i < numLeds1 ; i++) { leds1[i] = CRGB(0, 0, 0); } FastLED.show(); delay(500); } //LED 02 void initTest2() { for (int b = 0 ; b < numLeds2 ; b++) { leds2[b] = CRGB(127, 0, 0); } FastLED.show(); delay(500); for (int b = 0 ; b < numLeds2 ; b++) { leds2[b] = CRGB(0, 127, 0); } FastLED.show(); delay(500); for (int b = 0 ; b < numLeds2 ; b++) { leds2[b] = CRGB(0, 0, 127); } FastLED.show(); delay(500); for (int b = 0 ; b < numLeds2 ; b++) { leds2[b] = CRGB(0, 0, 0); } FastLED.show(); } //DMX Set Up void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data) { sendFrame = 1; // set brightness of the whole strip if (universe == 15) { FastLED.setBrightness(data[0]); FastLED.show(); } // Store which universe has got in if ((universe - startUniverse) < maxUniverses) { universesReceived[universe - startUniverse] = 1; } for (int i = 0 ; i < maxUniverses ; i++) { if (universesReceived[i] == 0) { //Serial.println("Broke"); sendFrame = 0; break; } } // read universe and put into the right part of the display buffer if (universe == 1) { for (int i = 0; i < length / 3; i++) { int led = i; if (led < numLeds1) leds1[led] = CRGB(data[i * 3], data[i * 3 + 1], data[i * 3 + 2]); } } if (universe == 2) { for (int i = 0; i < length / 3; i++) { int led = i; if (led < numLeds1) leds2[led] = CRGB(data[i * 3], data[i * 3 + 1], data[i * 3 + 2]); } } previousDataLength = length; if (sendFrame) { FastLED.show(); // Reset universeReceived to 0 memset(universesReceived, 0, maxUniverses); } } void setup() { //********************************STEPPER SET UP******************************** myStepper.setSpeed(15); //********************************ARTNET SET UP******************************** Serial.begin(115200); ConnectWifi(); artnet.begin(); FastLED.addLeds<WS2812, dataPin1, GRB>(leds1, numLeds1); FastLED.addLeds<WS2812, dataPin2, GRB>(leds2, numLeds2); initTest1(); initTest2(); // this will be called for each packet received artnet.setArtDmxCallback(onDmxFrame); } void loop() { // we call the read function inside the loop artnet.read(); myStepper.step(random(0, 2048)); } |
Thanks Toby66 for your Help, im still not sure how to implement this part in my Code:
Im know what the Code mean but not how to insert this. #include <ESP8266WiFi.h>
#include <ArtnetWifi.h>
#include <Arduino.h>
#include <FastLED.h>
#include <AccelStepper.h>
//Stepper
#define STEPPER1_DIR_PIN D4
#define STEPPER1_STEP_PIN D3
//#define STEPPER1_EN_PIN D2
AccelStepper stepper(AccelStepper::DRIVER, STEPPER1_STEP_PIN, STEPPER1_DIR_PIN);
int curpos = stepper.currentPosition();
int prevpos = 0;
int chan = 1;
int led_start = chan + 1;
// WiFi stuff
const char* ssid = "FRITZ!Box 7490";
const char* password = "123456789";
// LED settings
const int numLeds = 5; // CHANGE FOR YOUR SETUP
const int numberOfChannels = numLeds * 3; // Total number of channels you want to receive (1 led = 3 channels)
const byte dataPin = 2;
CRGB leds[numLeds];
// Art-Net settings
ArtnetWifi artnet;
WiFiUDP UdpSend;
const int startUniverse = 0; // CHANGE FOR YOUR SETUP most software this is 1, some software send out artnet first universe as 0.
// Check if we got all universes
const int maxUniverses = numberOfChannels / 512 + ((numberOfChannels % 512) ? 1 : 0);
bool universesReceived[maxUniverses];
bool sendFrame = 1;
int previousDataLength = 0;
// connect to wifi – returns true if successful or false if not
boolean ConnectWifi(void)
{
boolean state = true;
int i = 0;
WiFi.begin(ssid, password);
Serial.println("");
Serial.println("Connecting to WiFi");
// Wait for connection
Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
if (i > 20){
state = false;
break;
}
i++;
}
if (state){
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
} else {
Serial.println("");
Serial.println("Connection failed.");
}
return state;
}
void initTest()
{
for (int i = 0 ; i < numLeds ; i++) {
leds[i] = CRGB(127, 0, 0);
}
FastLED.show();
delay(500);
for (int i = 0 ; i < numLeds ; i++) {
leds[i] = CRGB(0, 127, 0);
}
FastLED.show();
delay(500);
for (int i = 0 ; i < numLeds ; i++) {
leds[i] = CRGB(0, 0, 127);
}
FastLED.show();
delay(500);
for (int i = 0 ; i < numLeds ; i++) {
leds[i] = CRGB(0, 0, 0);
}
FastLED.show();
}
void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data)
{
sendFrame = 1;
if ((universe - startUniverse) < maxUniverses)
{
universesReceived[universe - startUniverse] = 1;
}
for (int i = 0 ; i < maxUniverses ; i++)
{
if (universesReceived[i] == 0)
{
//Serial.println("Broke");
sendFrame = 0;
break;
}
}
// read universe and put into the right part of the display buffer
for (int i = 0; i < length / 3; i++)
{
int led = i + (universe - startUniverse) * (previousDataLength / 3);
if (led < numLeds)
leds[led] = CRGB(data[i * 3 + led_start], data[i * 3 + 1 + led_start], data[i * 3 + 2 + led_start]);
}
previousDataLength = length;
// get 16Bit Data for Stepper part
for (int i = 0 ; i < chan ; i++)
{
int long newval = 0;
newval = map(data[i], 0, 255, 0, 512);
char hi = data[i];
char lo = data[i + 1];
int StepperPos = hi << 8 | lo;
Serial.print("data: ");
Serial.println(StepperPos, HEX);
stepper.moveTo(StepperPos);
}
if (sendFrame)
{
FastLED.show();
// Reset universeReceived to 0
memset(universesReceived, 0, maxUniverses);
}
}
void setup()
{
Serial.begin(115200);
ConnectWifi();
artnet.begin();
FastLED.addLeds<WS2812, dataPin, GRB>(leds, numLeds);
initTest();
// this will be called for each packet received
artnet.setArtDmxCallback(onDmxFrame);
// set Current Position to 0
stepper.setCurrentPosition(0);
} //End Setup
void loop(){
// we call the read function inside the loop
artnet.read();
//Stepper stuff
stepper.setMaxSpeed(13000);
stepper.setSpeed(9000);
stepper.setAcceleration(6500);
stepper.runSpeedToPosition();
} As next is the Webserver with Filesystem todo. Best Regards |
@ all @andreas-git For your code-example a hint:
Note: As always, pseudo code !! Don't copy-paste! Maybe my |
Thanks for reply @rstephan,
Thanks for advise, thats already pseudo credentials. :-)
Yes, that was my idea using variables for set the needed parameters thrue WebServer and store it on Filesystem.
Its looks what ive done already in my Code, but not so nice like you advise.
Im still not sure how do that at the moment, im still beginner. |
@andreas-git Don't copy-past "blind" and start crying if it is not work or it don't solve your exact problem! But sure, use it as a start, maybe you are lucky. The part:
is just a comment to give you an orientation where to put the code. The |
I've been using this for a while now and it has been super helpful. Currently, I'm using a collection of ESP32s to control both LED's and stepper motors via ArtNet, splitting the information over different universes as set out in #9 .
However, I'm scaling up the project and it seems wasteful to use two universes per ESP32 when all the information could fit within one universe.
What would be the best way to be able to split a universes' channels into multiple outputs?
I.E:
Cheers!
The text was updated successfully, but these errors were encountered: