Esp32

djred2000

New member
Anybody using the ESP32 in their setup? I just got a few in and they work great at receiving E1.31. FastLED also supports it now if you want to drive pixels directly.
 
Thank you Mr.Kensington, I am already using Jasonspiva's ESP8266 multiplexing Pixel controller and it works fine. But when I compile the same code for ESP32, it gives lot of compiling error as ESP32's library's are different, it seems. Please try it yourself and help me with a solution. Thanks in advance.
 
I use multiple ESP32 based controllers in my show. They are running ESPixelStick V4 Software which also supports playing from an SD card (significantly reduces WiFi traffic)
 
Yes ESP32 works fine as an arduino, I do dont have enough experiance with all the code to make it work properly i just figured out how to make 4 32x64 p3 panels work as one.
tried to adapt the code for the matrix to make it serial read also. to see if you have had any luck making it work. do you have and serial read codes that worked for normal 2812 lights, going to try on one since they have WIFI, that would be awesome. I hope no one thinks I am trying to step on your toes here, that is certainly not my intention. .Just trying to recall how to create a new post of my own after seeing if no one else has had luck on making these work with vixen lights.
Here is what i have so far for the code.

HTML:
/******************************************************************************
    -------------------------------------------------------------------------
    Steps to create a virtual display made up of a chain of panels in a grid
    -------------------------------------------------------------------------
    Read the documentation!
    https://github.com/mrfaptastic/ESP32-HUB75-MatrixPanel-DMA/tree/master/examples/ChainedPanels
    tl/dr:
    
    - Set values for NUM_ROWS, NUM_COLS, PANEL_RES_X, PANEL_RES_Y, PANEL_CHAIN_TYPE. 
    - Other than where the matrix is defined and matrix.begin in the setup, you 
      should now be using the virtual display for everything (drawing pixels, writing text etc).
       You can do a find and replace of all calls if it's an existing sketch
      (just make sure you don't replace the definition and the matrix.begin)
    - If the sketch makes use of MATRIX_HEIGHT or MATRIX_WIDTH, these will need to be 
      replaced with the width and height of your virtual screen. 
      Either make new defines and use that, or you can use virtualDisp.width() or .height()
*****************************************************************************/
// 1) Include key virtual display library
    #include <ESP32-VirtualMatrixPanel-I2S-DMA.h>
    #include <FastLED.h>
    
// 2) Set configuration
    #define PANEL_RES_X 64 // Number of pixels wide of each INDIVIDUAL panel module. 
    #define PANEL_RES_Y 32 // Number of pixels tall of each INDIVIDUAL panel module.

    #define NUM_ROWS 2 // Number of rows of chained INDIVIDUAL PANELS
    #define NUM_COLS 2 // Number of INDIVIDUAL PANELS per ROW
    #define PANEL_CHAIN NUM_ROWS*NUM_COLS    // total number of panels chained one to another

    /* Configure the serpetine chaining approach. Options are:
        CHAIN_TOP_LEFT_DOWN
        CHAIN_TOP_RIGHT_DOWN
        CHAIN_BOTTOM_LEFT_UP
        CHAIN_BOTTOM_RIGHT_UP
        The location (i.e. 'TOP_LEFT', 'BOTTOM_RIGHT') etc. refers to the starting point where 
        the ESP32 is located, and how the chain of panels will 'roll out' from there.
        In this example we're using 'CHAIN_BOTTOM_LEFT_UP' which would look like this in the real world:
        Chain of 4 x 64x32 panels with the ESP at the BOTTOM_LEFT:
        +---------+---------+
        |    4    |    3    |
        |         |         |
        +---------+---------+
        |    1    |    2    |
        |  (ESP)  |         |
        +---------+---------+      
    */
    #define VIRTUAL_MATRIX_CHAIN_TYPE CHAIN_BOTTOM_LEFT_UP 

// 3) Create the runtime objects to use

    // placeholder for the matrix object
    MatrixPanel_I2S_DMA *dma_display = nullptr;

    // placeholder for the virtual display object
    VirtualMatrixPanel  *virtualDisp = nullptr;
// placeholder for the matrix object
// MatrixPanel_I2S_DMA *dma_display = nullptr;

/********************************
It did not like this section

const uint16_t colors[] =
{
  virtualDisp->Color(255, 0, 0), virtualDisp->Color(0, 255, 0), virtualDisp->Color(0, 0, 255)
};*/
uint16_t time_counter = 0, cycles = 0, fps = 0;
unsigned long fps_timer;

CRGB currentColor;
CRGBPalette16 palettes[] = {HeatColors_p, LavaColors_p, RainbowColors_p, RainbowStripeColors_p, CloudColors_p};
CRGBPalette16 currentPalette = palettes[0];


CRGB ColorFromCurrentPalette(uint8_t index = 0, uint8_t brightness = 255, TBlendType blendType = LINEARBLEND) {
  return ColorFromPalette(currentPalette, index, brightness, blendType);
}
String readString = "";      // a String to hold incoming data
bool stringComplete = false;  // whether the string is complete

/******************************************************************************
 * Setup!
 ******************************************************************************/
void setup() {
  
  
  Serial.begin(115200);
  
  /******************************************************************************
   * Create physical DMA panel class AND virtual (chained) display class.   
   ******************************************************************************/

  /*
    The configuration for MatrixPanel_I2S_DMA object is held in HUB75_I2S_CFG structure,
    All options has it's predefined default values. So we can create a new structure and redefine only the options we need
 Please refer to the '2_PatternPlasma.ino' example for detailed example of how to use the MatrixPanel_I2S_DMA configuration
  */

  HUB75_I2S_CFG mxconfig(
                PANEL_RES_X,   // module width
                PANEL_RES_Y,   // module height
                PANEL_CHAIN    // chain length
  );

  //mxconfig.driver = HUB75_I2S_CFG::FM6126A;     // in case that we use panels based on FM6126A chip, we can set it here before creating MatrixPanel_I2S_DMA object
/* virtualDisp->begin();   //initalize the matrix
  virtualDisp->setTextWrap(false);
  virtualDisp->setBrightness(40);
  virtualDisp->setTextColor(colors[0]);
*/
int x    = 16;  //holds the width of the matrix for counting colums
int pass = 0;  //used to calculate the number of characters read from the serial input


  // Sanity checks
  if (NUM_ROWS <= 1) {
    Serial.println(F("There is no reason to use the VirtualDisplay class for a single horizontal chain and row!"));
  }

  // OK, now we can create our matrix object
  dma_display = new MatrixPanel_I2S_DMA(mxconfig);

  // let's adjust default brightness to about 75%
  dma_display->setBrightness8(192);    // range is 0-255, 0 - 0%, 255 - 100%

  // Allocate memory and start DMA display
  if( not dma_display->begin() )
      Serial.println("****** !KABOOM! I2S memory allocation failed ***********");

  // create VirtualDisplay object based on our newly created dma_display object
  virtualDisp = new VirtualMatrixPanel((*dma_display), NUM_ROWS, NUM_COLS, PANEL_RES_X, PANEL_RES_Y, VIRTUAL_MATRIX_CHAIN_TYPE);

  // So far so good, so continue
  virtualDisp->fillScreen(virtualDisp->color444(0, 0, 0));
 virtualDisp->drawDisplayTest(); // draw text numbering on each screen to check connectivity

 delay(5000);

 virtualDisp->fillScreen(virtualDisp->color444(0, 0, 0));
  delay(2000);
}

void loop ()
{
  virtualDisp->fillScreen(virtualDisp->color444(0, 0, 0));  //clear the screen
  virtualDisp->setCursor(0, 0);  //set the begining cursor position
  serialtochar();
  chartoscreen();

}  //end loop

void serialtochar() {
  while (Serial.available())  //if serial data is available, run the loop
  {
    delay(10);
    if (Serial.available() > 0)  //if there is serial data continue
    {
      
      char c = Serial.read();  //read the next byte of data
      readString += c;  //append the data to the char variable readString
    }

  }

}

void chartoscreen()
{
  if (readString.length() > 0)  //if the number of bytes in readString are greater than 0
  {
    virtualDisp->println(readString);  //print the data in readString
    pass = -abs(readString.length());  //set pass to the negative value of the number of characters

    if(--x < pass * 6)  //reserve 6 spaces for each character - continue looping until x = pass * 6
    {
      x = virtualDisp->width();  //set x to the number of colums in the matrix
      readString = "";  //set the data to blank
    }


    virtualDisp->show();  //show the data stored
    delay(70);  //wait a bit - sets scrolling speed

  }
}


void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    // add it to the inputString:
    readString += inChar;
    // if the incoming character is a newline, set a flag so the main loop can
    // do something about it:
    if (inChar == '\n') {
      stringComplete = true;
    }
  }
}






/* This for testing
 // delay(1000);

  Serial.println("Chain of 4x 64x32 panels for this example:");
  Serial.println("+---------+---------+");
  Serial.println("|    4    |    3    |");
  Serial.println("|         |         |");
  Serial.println("+---------+---------+");
  Serial.println("|    1    |    2    |");
  Serial.println("| (ESP32) |         |");
  Serial.println("+---------+---------+");

   // draw blue text
   virtualDisp->setFont(&FreeSansBold12pt7b);
   virtualDisp->setTextColor(virtualDisp->color565(0, 0, 255));
   virtualDisp->setTextSize(2); 
   virtualDisp->setCursor(0, virtualDisp->height()- ((virtualDisp->height()-45)/2));    
   virtualDisp->print("ABCD");

//    Red text inside red rect (2 pix in from edge)
   virtualDisp->drawRect(1,1, virtualDisp->width()-2, virtualDisp->height()-2, virtualDisp->color565(255,0,0));

//    White line from top left to bottom right
   virtualDisp->drawLine(0,0, virtualDisp->width()-1, virtualDisp->height()-1, virtualDisp->color565(255,255,255));

//   virtualDisp->drawDisplayTest(); // re draw text numbering on each screen to check connectivity

  delay(2000);
  virtualDisp->fillScreen(virtualDisp->color444(0, 0, 0));
  delay(2000);
  virtualDisp->setFont(&FreeSansBold12pt7b);
   virtualDisp->setTextColor(virtualDisp->color565(0, 222, 0));
   virtualDisp->setTextSize(1); 
   virtualDisp->setCursor(0, virtualDisp->height()- ((virtualDisp->height())/2));    
   virtualDisp->print("   Hello      There");
   delay(2000);
  virtualDisp->fillScreen(virtualDisp->color444(0, 0, 0));
   delay(500);
 virtualDisp->setTextColor(virtualDisp->color565(0, 222, 0));
   virtualDisp->setTextSize(1); 
   virtualDisp->setCursor(0, virtualDisp->height()- ((virtualDisp->height())/2));    
   virtualDisp->print("We are      Here");
   delay(2000);
virtualDisp->fillScreen(virtualDisp->color444(0, 0, 0));
   delay(1000);
   // Set current FastLED palette
  currentPalette = RainbowColors_p;
  Serial.println("Starting plasma effect...");
  fps_timer = millis();
}

void loop() {
   for (int x = 0; x < virtualDisp->width(); x++) {
            for (int y = 0; y <  virtualDisp->height(); y++) {
                int16_t v = 0;
                uint8_t wibble = sin8(time_counter);
                v += sin16(x * wibble * 3 + time_counter);
                v += cos16(y * (128 - wibble)  + time_counter);
                v += sin16(y * x * cos8(-time_counter) / 8);

                currentColor = ColorFromPalette(currentPalette, (v >> 8) + 127); //, brightness, currentBlendType);
                dma_display->drawPixelRGB888(x, y, currentColor.r, currentColor.g, currentColor.b);
            }
    }

    ++time_counter;
    ++cycles;
    ++fps;

    if (cycles >= 1024) {
        time_counter = 0;
        cycles = 0;
        currentPalette = palettes[random(0,sizeof(palettes)/sizeof(palettes[0]))];
    }

    // print FPS rate every 5 seconds
    // Note: this is NOT a matrix refresh rate, it's the number of data frames being drawn to the DMA buffer per second
    if (fps_timer + 5000 < millis()){
      Serial.printf_P(PSTR("Effect fps: %d\n"), fps/5);
      fps_timer = millis();
      fps = 0;
    }
*/
}//END LOOP
/*****************************************************************************
    Thanks to:
    * Brian Lough for the original example as raised in this issue:
      https://github.com/mrfaptastic/ESP32-HUB75-MatrixPanel-I2S-DMA/issues/26
      YouTube: https://www.youtube.com/brianlough
      Tindie: https://www.tindie.com/stores/brianlough/
      Twitter: https://twitter.com/witnessmenow
    * Galaxy-Man for the kind donation of panels make/test that this is possible:
      https://github.com/Galaxy-Man
*****************************************************************************/


If you can use any of this i hope it will work for you.
Just as a reminder this has not worked yet for the DMD matrix just the 2812 matrix with some changes of course.
Everywhere that it now says "virtualDisp->" used to be "matrix."


Hopefully someone can hope both of out,

Thanks.
 
Back
Top