Custom Built Pixel ...
 
Notifications
Clear all

Custom Built Pixel Controller

14 Posts
7 Users
0 Reactions
17.5 K Views
Posts: 10
(@kintara)
Active Member
Joined: 8 years ago

I am trying to get this to work with an ESP -WROOM-32 on a ESP DEVKITV1 board. You mention that you are using your ESP32 dev board to receive E1.31 over WiFi. What program are you using to send the data? I'm using VixenLights 3 but the ESP does not seem to acknowledge the data over WiFi after it has connected to my home WiFi Network. ANy ideas as to why?


Reply
Posts: 10
(@kintara)
Active Member
Joined: 8 years ago

Solved.

Kintara wrote:I am trying to get this to work with an ESP -WROOM-32 on a ESP DEVKITV1 board. You mention that you are using your ESP32 dev board to receive E1.31 over WiFi. What program are you using to send the data? I'm using VixenLights 3 but the ESP does not seem to acknowledge the data over WiFi after it has connected to my home WiFi Network. ANy ideas as to why?

A few things I had to do to get it working:
1) I had not set the ESP32's ip address correctly - The wifi router was 192.168.0.100 and I had the ESp sketch set a static IP address of 192.168.1.101. Changing it to 192.168.0.101 solved that issue.

2) Vixen lights does not seem to run too well on my laptop. I switched to using XLights and set up a simple single string as Uniplex 192.168.0.101 and a simple sequence. Used the Test mode in XLights and also ran WireShark to see the data packets sent by WiFi to the ESP. The blue 'recieve' led on the ESP lit up lovely.

3) Some of the bytes in the data packet were not as the Teensey was expecting: within the E131 sketch on the Teensy, I had to change the values on line 24 ; byte 115 in the packet was originally expected to be 114, but was actually 112.

I'll post the sketch when I can get hold of it.


Reply
Posts: 10
(@kintara)
Active Member
Joined: 8 years ago

From the info that djred2000 supplied and my own experiments I have come up with this schematic and made it on a Veroboard.

Schematic Teensy ESP32 Pixel Controller Sheet 1 20190310151533

and also a quick untested PCB layout

PCB InBox Controller 20190310160417

Reply
Posts: 10
(@kintara)
Active Member
Joined: 8 years ago

This is the code I used, based on the code of djred2000.

Load this module and the E131.ino into the same Sketch and load onto the ESP32.
ESP32_E131_Receiver.ino

// This works with Xlights
//Output from TX0 pin to go into RX on Teensy 3.2
#include <WiFi.h>
#include <WiFiUdp.h>
#include "esp_wifi.h"

const int BUFFER_SIZE = 638;
unsigned char PacketBuffer[BUFFER_SIZE]; //buffer to hold incoming packet data
boolean LEDState = true;
unsigned long currentcounter;
unsigned long previouscounter;
unsigned long StandbyDelay = 1000;
unsigned long currentDelay;

//WiFi Setup
char ssid[] = "dlink"; //WiFi SSID - change to your WiFi SSID 
char pass[] = ""; //WiFi Password
IPAddress local_ip(192, 168, 0, 101); //Static IP information
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
const int E131Port = 5568;
WiFiUDP Eudp; //UDP socket for Unicast E1.31

void setup()
{
  Serial.begin(2000000); //2 megabit 
  WiFi.mode(WIFI_STA); //wifi client mode
  esp_wifi_set_ps (WIFI_PS_NONE); //disable wifi power saving mode
  WiFi.begin(ssid, pass); //Connect to Network
  WiFi.config(local_ip, gateway, subnet); //Set static IP information
  while (WiFi.status() != WL_CONNECTED)  //wait until we are connected
  {
    delay(500);
    //Serial.println("Connecting");
  }
  Eudp.begin(E131Port); //Open E1.31 port
  pinMode(2, OUTPUT); //set onboard LED to output
  digitalWrite(2, LOW); //turn onboard LED off
//  WiFi.printDiag(Serial); //prints wifi status to serial port
//  Serial.print("Local IP adress "); //prints setup complete text to serial port
//  Serial.println(local_ip); //prints setup complete text to serial port
//  Serial.println("Setup Complete"); //prints setup complete text to serial port
  //delay(5000); //pause for 5 seconds 
  ConnectionCompleted();
}

void loop()
{
/*
//Make sure we are still connected to the AP each time through the loop.
if(WiFi.status() != WL_CONNECTED)
{
  ESP.restart(); //restart the board 
}
*/
  /* Start by checking to see if a packet is available on the E1.31 port */
  int packetSize = Eudp.parsePacket(); //parse packet
  
  if (packetSize)
  {
    if(LEDState == false)
    {
      digitalWrite(2, HIGH); //turn LED on
    }
    Eudp.read(PacketBuffer, BUFFER_SIZE); //read packet into buffer
    int count = checkE131Headers(PacketBuffer, BUFFER_SIZE); //pass data to see if it is E1.31
    if (count) //if it comes back genuine
    {
      LEDState = true;
      currentcounter++;
      //Serial.println(PacketBuffer[114]);
      Serial.write("SAC"); //packet header 
      Serial.write(PacketBuffer, BUFFER_SIZE); //write packet to serial port 
      Serial.flush(); //flush transmit buffer at end of for loop
    }
  }

 //Timer 
if(currentcounter != previouscounter) //has the value changed?
  {
    currentDelay = millis(); //store the time since the value has increased 
    previouscounter = currentcounter; //set the previous value equal to the current value
  }
  
  if(millis() - currentDelay > StandbyDelay) //current time minus time since the counter has changed.
  { 
   digitalWrite(2, LOW); //turn LED off. Not receiving E1.31 
   LEDState = false;
  }

} //end loop

This is the E131.ino sketch to be included with ESP32_E131_Receiver.ino

 int checkE131Headers(unsigned char* messagein, int messagelength) 
{
  if ( messagein[1] == 0x10 && messagein[4] == 0x41 && messagein[12] == 0x37) 
  {  
      int ChannelCount = messagein[123] * 256 + messagein[124]; // number of values plus start code
     // Serial.println(ChannelCount);
      return ChannelCount -1; //Return how many values are in the packet.
  }
  return 0;
}

void ConnectionCompleted()
{
  digitalWrite(2, HIGH);
  delay(250);
  digitalWrite(2, LOW);
  delay(250);
  digitalWrite(2, HIGH);
  delay(250);
  digitalWrite(2, LOW);
  delay(250);
  digitalWrite(2, HIGH);
  delay(250);
  digitalWrite(2, LOW);
  delay(250);
}

The Teensy3.2 uses these code modules, all to be in the same sketch

Teensy_Controller.ino

#define USE_OCTOWS2811
#include<OctoWS2811.h>
#include <FastLED.h>

//Adjustable Values
const int E131StartUniverse = 1; //First E1.31 universe to process
const int E131UniverseCount = 3; //Total number of E1.31 universes being processed
const int NumLEDsPerUniverse = 20; //Number of LEDs per universe. No more than 170 per universe (3 channels per LED)
const int NUM_LEDS_PER_STRIP = 20; //Number of LEDs per ouput pin
const int NUM_STRIPS = 3; //number of output pins. Recommend keeping at 8
const int NUM_LEDS = 60; //total number of LEDs
const int GlobalBrightness = 255; //Global LED brightness set at startup
const int StandbyDelay = 5000; //Delay in milliseconds before Standby function begins when no E1.31 is received 


//General Definitions
const int ledpin = 13; //LED on board for monitoring
const int BUFFER_SIZE = 638; //size of data buffer to hold E1.31 
const int E131_ADDRESS_OFFSET = 125; //byte 126 of the E1.31 packet contains channel 1 value
const int E131_START_CODE = 0; 
int E131CurrentUniverse;  //Current universe we are processing 
int StartLED = 0;
int EndLED;
int startms;
int endms;

//Timer Setup
unsigned int currentcounter = 0; //counter for data reception
unsigned int previouscounter = 0; //counter for data reception 
unsigned long currentDelay = 0; //current time value for E1.31 reception
unsigned long previousTime = 0; //time variable
unsigned long ChangeTime = 600000; //10 minutes in milliseconds 

// buffers for receiving data
unsigned char DataBuffer[BUFFER_SIZE]; //buffer to hold incoming E1.31 
unsigned char Header[3]; //header buffer

//FastLED Parallel Output using OctoWS2811 on Teensy 
//Ports: 2,14,7,8,6,20,21,5
CRGB leds[NUM_LEDS];

const int ChannelWidth = 3; //each pixel needs 3 channels for control
int Channel = 1; //current channel being used 
byte current_hue; //hue value for rainbow effect
int ledNumber; //current led Pixel being used for rainbow effect
int currentProgram = 1; //initial pixel pattern to run
uint8_t random_delay; //variable for random delay 
uint8_t random_color; //variable for random color
uint8_t random_color2; //variable for another random color
uint8_t brightness; //brightness variable 
uint8_t thishue; //for fill rainbow
uint8_t deltahue = 1; //for fill rainbow
uint8_t color1 = 0;

void setup() 
{
pinMode(ledpin, OUTPUT);  //pin 13 to let us know if we are receiving any data
digitalWrite(ledpin, LOW); //turn LED off
Serial.begin(250000); //USB serial port for monitoring/debugging
Serial1.begin(2000000); //ESP8266 serial connection
LEDS.addLeds<OCTOWS2811, RGB>(leds, NUM_LEDS_PER_STRIP); //OctoWS2811 output on Teensy 3.2 
LEDS.setCorrection(TypicalLEDStrip); //color correction 
LEDS.setBrightness(GlobalBrightness); //Overall Brightness 
delay(5000); //delay 5 seconds 
POST(); //Run power on self test function each time board boots 
previousTime = millis(); //set time 
SetupComplete();
//Serial.println("Setup Completed");
}

void loop() 
{
//Reads serial data and determines what kind of data it is then processes it 
if (Serial1.available()) 
{
  
Serial1.readBytes(Header,3); //read 3 bytes at a time 
if(Header[0] == 'S' && Header[1] == 'A' && Header[2] == 'C') //check for E1.31 Header
{
  Serial1.readBytes(DataBuffer,BUFFER_SIZE); //read data into buffer 
//  digitalWrite(ledpin, HIGH); //turn LED on
  currentcounter++;
  E131Received();
}

}

 //Timer runs standby pixel functions when no E1.31 is being received. 
if(currentcounter != previouscounter) //has the value changed?
  {
    currentDelay = millis(); //store the time since the value has increased 
    previouscounter = currentcounter; //set the previous value equal to the current value
  }
  
  if(millis() - currentDelay > StandbyDelay) //current time minus time since the counter has changed. After 30 seconds of no data being received 
  { 
   digitalWrite(13, LOW); //turn LED off. Not receiving E1.31 
   Standby(); //run pixel standby function 
  }
} //end loop

E131.ino (for Teensy3.2)

void E131Received() 
{
  if(DataBuffer[114] >= E131StartUniverse && DataBuffer[114] <= E131UniverseCount) //first make sure the universe received is one we want to process
  {
  
digitalWrite(ledpin, HIGH); //turn LED off
  if(DataBuffer[114] == E131StartUniverse) //if current universe is the first in the series, reset all values
  {
    StartLED = 0;
    EndLED = NumLEDsPerUniverse;
    E131CurrentUniverse = E131StartUniverse;
   // Serial.println("Universe Start");  
  }
  //
  //  Serial.print("114 : ");
  //  Serial.print(DataBuffer[114]); //Universe number
  //  Serial.print("108 : ");
  //  Serial.print(DataBuffer[108]); // priority(100)
  //  Serial.print(" 115 : ");
  //  Serial.print(DataBuffer[115]);//115 = protocol flag(114)
  //  Serial.print(" 116 : ");
  //  Serial.print(DataBuffer[116]); //116 = length(9)
  //  Serial.print(" 118 : ");
  //  Serial.println(DataBuffer[118]); // 118 (161)= address and data type
if(DataBuffer[114] == E131CurrentUniverse && DataBuffer[108] == 100 && DataBuffer[115] == 112 && DataBuffer[116] == 71 && DataBuffer[118] == 161) 
//These figures may be different on your system. 
//Use WireShark to inspect the packets or uncomment the above Serial.print lines to see the data bytes recieved.
//108 = priority, 114 = Universe number, 115 = protocol flag, 116 = length, 118 = address and data type
{
     Channel = 1; //reset channel assignment to 1 each time through loop.
      for(int i = StartLED; i < EndLED; i++) //set values for 170 pixels. Max number per universe. 
      {
// Uncomment Serial.print lines to see data recieved.       
//    Serial.print(DataBuffer[E131_ADDRESS_OFFSET + Channel]);
//    Serial.print(" ");
        
//    Serial.print(DataBuffer[E131_ADDRESS_OFFSET + Channel+1]);
//    Serial.print(" ");
        
//    Serial.print(DataBuffer[E131_ADDRESS_OFFSET + Channel+2]);
//    Serial.print(" ");
      leds[i] = CRGB(DataBuffer[E131_ADDRESS_OFFSET + Channel], DataBuffer[E131_ADDRESS_OFFSET + (Channel +1)], DataBuffer[E131_ADDRESS_OFFSET + (Channel + 2)]);
      Channel += ChannelWidth; //increase last channel number by channel width
      }
      
 //   Serial.println("");
}    
      if(DataBuffer[114] == E131UniverseCount) //we've processed all universes now send data to pixels 
      {
      FastLED.show();
 //     Serial.print("FastLED FPS: ");
 //     Serial.println(FastLED.getFPS());
      }
      else //not all universes have been received. Move on to the next one. 
      {
        StartLED += NumLEDsPerUniverse; //increase by 170
        EndLED += NumLEDsPerUniverse; //increase by 170
        E131CurrentUniverse++; //increase by 1 
      }
}
digitalWrite(ledpin, LOW); //turn LED off
} //end function 

Misc.ino

void POST() 
{
   LEDS.showColor(CRGB(255, 0, 0)); //turn all pixels on red
   delay(1000);
   LEDS.showColor(CRGB(0, 255, 0)); //turn all pixels on green
   delay(1000);
   LEDS.showColor(CRGB(0, 0, 255)); //turn all pixels on blue
   delay(1000);
   FastLED.clear(); //clear pixels
   FastLED.show();
   //Serial.println("POST Completed");
}

void SetupComplete()
{
  digitalWrite(ledpin, HIGH);
  delay(250);
  digitalWrite(ledpin, LOW);
  delay(250);
  digitalWrite(ledpin, HIGH);
  delay(250);
  digitalWrite(ledpin, LOW);
  delay(250);
  digitalWrite(ledpin, HIGH);
  delay(250);
  digitalWrite(ledpin, LOW);
  delay(250);
}

PixelStandby.ino

//This function runs when we are not receiving E1.31
void Standby()
{ 

if(millis() - previousTime > ChangeTime)
  {
   //Serial.print("Current program: ");
   //Serial.println(currentProgram); 
   currentProgram++; //advance program
   previousTime = millis(); //store the new time
   random8(random_color2); //choose a random color for the static color function
   //Serial.print("Change program to: ");
   //Serial.println(currentProgram);
  }
  
if(currentProgram > 9) //current program greater than 9
{
currentProgram = 1;  //restart at 1
}

 switch(currentProgram) //switch case to control programs
    {
     case 1: rainbowFade(); break;
     case 2: alternating(); break;
     case 3: everyother(); break;
     case 4: simpleFade(); break;
     case 5: colorDraw(); break;
     case 6: ColorStep(); break;
     case 7: Twinkle(); break;
     case 8: staticColor(); break;
     case 9: cylon(); break;  
     case 10: OffMode(); break;
    } 
} //end standby 

//Draws a moving rainbow across all pixels
void rainbowFade()
{
thishue++;                                                  
fill_rainbow(leds, NUM_LEDS, thishue, deltahue); 
FastLED.delay(10);
FastLED.show();
} //end rainbow fade

//Alternates all pixels between 2 colors
void alternating()
{
  FastLED.showColor(CRGB::Red);
  delay(500);
  FastLED.showColor(CRGB::Green);
  delay(500);
} //end alternating

//Chase type effect alternating 2 colors across all pixels 
void everyother()
{
for(int i = 0; i < NUM_LEDS; i+=2)
{
  leds[i] = CRGB(255,0,0);
}
for(int i = 1; i < NUM_LEDS; i+=2)
{
  leds[i] = CRGB(0,0,255);
}
FastLED.show();
delay(500);
for(int i = 1; i < NUM_LEDS; i+=2)
{
  leds[i] = CRGB(255,0,0);
}
for(int i = 0; i < NUM_LEDS; i+=2)
{
  leds[i] = CRGB(0,0,255);
}
FastLED.show();
delay(500);
} //end everyother 

//Fades all pixels up and down and chooses a new color each time 
void simpleFade()
{
random_color = random8(0,255);
random_delay = random8(5,20);
for(brightness = 0; brightness < 255; brightness++)
{
for(ledNumber = 0; ledNumber < NUM_LEDS; ledNumber++)
{
leds[ledNumber] = CHSV(random_color, 255, brightness);
}
FastLED.show();
FastLED.delay(random_delay); 
}

for(brightness = 255; brightness > 0; brightness--)
{
for(ledNumber = 0; ledNumber < NUM_LEDS; ledNumber++)
{
leds[ledNumber] = CHSV(random_color, 255, brightness);
}
FastLED.show();
FastLED.delay(random_delay); 
}
} //end simple fade

//Draws one color across all pixels and then draws another on the way back
void colorDraw()
{
random_color = random8(0,255);
for(ledNumber = 0; ledNumber < NUM_LEDS; ledNumber++)
{ 
leds[ledNumber] = CHSV( random_color, 255, 255);
FastLED.show();
FastLED.delay(15);
}
random_color = random8(0,255);
for(ledNumber = NUM_LEDS-1; ledNumber > 0; ledNumber--)
{ 
leds[ledNumber] = CHSV( random_color, 255, 255);
FastLED.show();
FastLED.delay(15);
}  
} //end color draw

void ColorStep()
{
  for(int i = 0; i < NUM_LEDS; i++)
  {
    leds[i] = CHSV(color1,255,255);
  }
  FastLED.show();
  FastLED.delay(500);
  color1+=25;
}

//Simple twinkle function across all pixels with random colors
void Twinkle()
{
int i = random16(0,NUM_LEDS); 
random_color = random8(0,255);
if (i < NUM_LEDS) 
{
leds[i] = CHSV(random_color, 255, 255);            
for (int j = 0; j < NUM_LEDS; j++)
{
leds[j].fadeToBlackBy(1);
}
}
FastLED.show();
} //end twinkle

//All pixels white 
void staticColor()
{
for(ledNumber = 0; ledNumber < NUM_LEDS; ledNumber++)
{ 
leds[ledNumber] = CHSV(random_color2, 255, 255);
}
FastLED.show(); 
} //end static white

void fadeall() 
{ 
  for(int i = 0; i < NUM_LEDS; i++) 
  { 
    leds[i].nscale8(255); 
  } 
}

//Cylon effect across all pixels. 
void cylon() 
{ 
  static uint8_t hue = 0;
  // First slide the led in one direction
  for(int i = 0; i < NUM_LEDS; i++) 
  {
    // Set the i'th led to red 
    leds[i] = CHSV(hue++, 255, 255);
    // Show the leds
    FastLED.show();
    // now that we've shown the leds, reset the i'th led to black
    //leds[i] = CRGB::Black;
    fadeall();
    // Wait a little bit before we loop around and do it again
    FastLED.delay(10);
  }
 
  // Now go in the other direction.  
  for(int i = (NUM_LEDS)-1; i >= 0; i--) 
  {
    // Set the i'th led to red 
    leds[i] = CHSV(hue++, 255, 255);
    // Show the leds
    FastLED.show();
    // now that we've shown the leds, reset the i'th led to black
    //leds[i] = CRGB::Black;
    fadeall();
    // Wait a little bit before we loop around and do it again
    FastLED.delay(10);
  }
}

void OffMode()
{
  FastLED.clear();
  FastLED.show();
  delay(5000);
  //Serial.println("Off");
}

Readme.ino

//This code will drive WS2811 pixels using the FastLED library. It is designed to run on a Teensy 3.2. It receives data over Serial from an ESP8266/ESP32. 
//
//Serial port 1 is used for connection to ESP8266.  Serial over the USB connection is used for debugging.
//
//The OctoWS2811 parallel output is being used to drive 8 output pins. 
//
//I included standby pixel displays for when no data is being received. 
//
//You will need all files for this to compile properly and use the Arduino IDE. 

Reply
Posts: 116
Topic starter
(@djred2000)
Estimable Member
Joined: 13 years ago
Kintara wrote:Solved.

A few things I had to do to get it working:
1) I had not set the ESP32's ip address correctly - The wifi router was 192.168.0.100 and I had the ESp sketch set a static IP address of 192.168.1.101. Changing it to 192.168.0.101 solved that issue.

2) Vixen lights does not seem to run too well on my laptop. I switched to using XLights and set up a simple single string as Uniplex 192.168.0.101 and a simple sequence. Used the Test mode in XLights and also ran WireShark to see the data packets sent by WiFi to the ESP. The blue 'recieve' led on the ESP lit up lovely.

3) Some of the bytes in the data packet were not as the Teensey was expecting: within the E131 sketch on the Teensy, I had to change the values on line 24 ; byte 115 in the packet was originally expected to be 114, but was actually 112.

I'll post the sketch when I can get hold of it.

I'm glad you got it working! I have used Vixen, XLights, and FPP to send the E1.31 data to the ESP32 and they all work. You have to make sure the output settings in each program match exactly.


Reply
Page 2 / 3
Share: