Route ArtNet to USB LED Devices ... on an ESP32??
  • CaseyJScalf
    activ8 member
    Posts: 81
    Joined: Sat Nov 08, 2014 10:15 am

    Route ArtNet to USB LED Devices ... on an ESP32??

    by CaseyJScalf » Thu Mar 03, 2022 5:00 am

    Just finished up getting a Teensy 4.0 to run the MadMapper code to accept ArtNet over a USB cable. Pretty awesome I must say.

    Find video and code here:

    So... after thinking I was curious if it would be possible to run the same code on other microcontrollers? Is there anything particularly special about the Teensy other than that it is fast?

    I pulled out a USB C ESP32 board from SparkFun and thought I would just upload the code and try? https://www.sparkfun.com/products/18018

    I was able to get the LEDs to blink just fine by commenting out the "JUST_TEST_LEDS" section. Everything looks good.

    Though, when I went for the rest of the code (which works great on the Teensy!) I was not able to pickup the board in MadMapper preferences. I double checked all I could and am still not able to make headway.

    So that is what I come here to post and ask: what is going on?

    Is it possible that this board just won't work because of some weird USB serial issue?

    Maybe I am using the wrong pin?

    Or perhaps the code in MadMapper is only good for a Teensy?

    Pictures show the Teensy and the ESP32. For the code I only changed the PIN from 2 on the Teensy to 12 on the ESP32.

    Thank you for any help!

    I am running both MM 4.2.1 & 5.0.2
    Mac OSX 11.5.1

    Code below didn't paste very well so here is a link to the GitHub where you can view it easier.
    https://github.com/CaseyJScalf/MadMappe ... Teensy.ino


    Code: Select all

    // Read data from MadMapper and write to LEDs... but for ESP32? //////////////////////////////////////////////////////////////////////////////////////////////////////// #include <SPI.h> #include <FastLED.h> #define MAD_LED_PACKET_HEADER 0xFF #define MAD_LED_DATA 0xBE #define MAD_LED_DETECTION 0xAE #define MAD_LED_DETECTION_REPLY 0xEA #define MAD_LED_PROTOCOL_VERSION 0x01 // Uncomment this line to see verbose debug prints in the Seril Monitor // #define DEBUG_MODE // Uncomment the line below test LEDs without the need of MadMapper or MadRouter sending data on serial port // #define JUST_TEST_LEDS // How many LEDs are in the strip? #define NUM_LEDS 3 // What data pin to send this out of? // Put a 330 Ohm resistor between pin and Data In for WS2812 #define DATA_PIN 12 // Fast LED Buffers CRGB leds[NUM_LEDS]; // MadLED protocol buffer char dataFrame[NUM_LEDS * 3]; int readingFrameOnLine = -1; bool gotNewDataFrame = false; enum State { State_WaitingNextPacket, State_GotPacketHeader, State_WaitingLineNumber, State_WaitingChannelCountByte1, State_WaitingChannelCountByte2, State_ReadingDmxFrame }; State inputState = State_WaitingNextPacket; unsigned int channelsLeftToRead = 0; char* frameWritePtr = dataFrame; //////////////////////////////////////////////////////////////////////////////////////////////////////// void setup() { Serial.begin(921600); for (unsigned int i = 0; i < sizeof(dataFrame); i++) dataFrame[i] = 0; // Create LED - type, what pin, color mode, object, number of LEDs FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS); Serial.print("Setup done"); } // End Setup //////////////////////////////////////////////////////////////////////////////////////////////////////// void processByte(unsigned char currentByte) { #ifdef DEBUG_MODE Serial.print("GOT BYTE: "); Serial.print(currentByte, HEX); #endif if (currentByte == MAD_LED_PACKET_HEADER) { inputState = State_GotPacketHeader; #ifdef DEBUG_MODE Serial.print("GOT PH "); #endif } else if (inputState == State_WaitingNextPacket) { // Just ignore this byte, we're not processing a packet at the moment // Wait for next packet start (xFF) } else if (inputState == State_GotPacketHeader) { if (currentByte == MAD_LED_DETECTION) { // Send back detection reply Serial.write(MAD_LED_DETECTION_REPLY); Serial.write(MAD_LED_PROTOCOL_VERSION); inputState = State_WaitingNextPacket; } else if (currentByte == MAD_LED_DATA) { inputState = State_WaitingLineNumber; #ifdef DEBUG_MODE Serial.print("GOT LD "); #endif } else { // Unknown packet start, reset inputState = State_WaitingNextPacket; } } else if (inputState == State_WaitingLineNumber) { if (currentByte > 0x7F) { // Error, reset inputState = State_WaitingNextPacket; #ifdef DEBUG_MODE Serial.print("ErrLineNum: "); Serial.print(currentByte); #endif } else { readingFrameOnLine = currentByte; inputState = State_WaitingChannelCountByte1; #ifdef DEBUG_MODE Serial.print("GOT LN "); #endif } } else if (inputState == State_WaitingChannelCountByte1) { if (currentByte > 0x7F) { // Error, reset inputState = State_WaitingNextPacket; #ifdef DEBUG_MODE Serial.print("ErrChCNT1: "); Serial.print(currentByte); #endif } else { channelsLeftToRead = currentByte; inputState = State_WaitingChannelCountByte2; #ifdef DEBUG_MODE Serial.print("GOT CHC1 "); #endif } } else if (inputState == State_WaitingChannelCountByte2) { if (currentByte > 0x7F) { // Error, reset inputState = State_WaitingNextPacket; #ifdef DEBUG_MODE Serial.print("ErrChCNT2: "); Serial.print(currentByte); #endif } else { channelsLeftToRead += (int(currentByte) << 7); if (channelsLeftToRead == 0) { // Error, reset inputState = State_WaitingNextPacket; #ifdef DEBUG_MODE Serial.print("ErrChCNT=0"); #endif } else { frameWritePtr = dataFrame; inputState = State_ReadingDmxFrame; #ifdef DEBUG_MODE Serial.print("GOT CHC2 "); #endif } } } else if (inputState == State_ReadingDmxFrame) { *frameWritePtr++ = currentByte; channelsLeftToRead--; if (channelsLeftToRead == 0) { // Finished reading DMX Frame inputState = State_WaitingNextPacket; gotNewDataFrame = true; #ifdef DEBUG_MODE Serial.print("GOT DATA "); #endif } } } // End processByte() //////////////////////////////////////////////////////////////////////////////////////////////////////// void loop() { // If in this mode the entire strip will fade black to white #ifdef JUST_TEST_LEDS Serial.println("Currently testing..."); static int value = 254; value = (value + 1) % 254; for (int i = 0; i < NUM_LEDS; i++) { leds[i] = CRGB(value, value, value); } #else // We read a maximum of 30000 bytes before we should call FastLED.show again // This is a good setting for the teensy, it depends on CPU speed, so it should be set lower on a slower CPU (ie arduino) // This limit (bytesRead<30000) is useless for protocols with a clock // But necessary when controlling more than 600 hundred RGB leds with WS2811 / WS2812 int bytesRead = 0; while (Serial.available() > 0 && bytesRead < 30000) { processByte(Serial.read()); bytesRead++; } if (gotNewDataFrame) { gotNewDataFrame = false; char* dataPtr = dataFrame; // Copy the data frame we received in the correct FastLED buffer for (int i = 0; i < NUM_LEDS; i++) { leds[i] = CRGB(dataPtr[0], dataPtr[1], dataPtr[2]); dataPtr += 3; } } #endif // Actually show the LEDs FastLED.show(); } // End Loop ////////////////////////////////////////////////////////////////////////////////////////////////////////
    Attachments
    IMG_3728.jpg
    Teensy 4.0
    IMG_3728.jpg (331.19 KiB) Viewed 11818 times
    IMG_3725.jpg
    ESP32 Thing
    IMG_3725.jpg (494 KiB) Viewed 11818 times
    Last edited by CaseyJScalf on Fri Mar 04, 2022 1:56 am, edited 2 times in total.
  • CaseyJScalf
    activ8 member
    Posts: 81
    Joined: Sat Nov 08, 2014 10:15 am

    Re: Route ArtNet to USB LED Devices ... on an ESP32??

    by CaseyJScalf » Thu Mar 03, 2022 5:10 am

    Her is what my preferences panel looks like
    Attachments
    Screen Shot 2022-03-02 at 7.52.22 PM.png
    Screen Shot 2022-03-02 at 7.52.22 PM.png (55.15 KiB) Viewed 11817 times
  • mad-matt
    garageCube team
    Posts: 1475
    Joined: Mon Sep 09, 2013 5:50 pm

    Re: Route ArtNet to USB LED Devices ... on an ESP32??

    by mad-matt » Mon Mar 07, 2022 12:10 pm

    No, it's just that MadMapper filters virtual ports based on vendorID / productID:

    if (vendorID==0x1d50 && productID==0x60aa)
    dt=LSDT_BlinkyTile;
    else if (vendorID==0x1d50 && productID==0x605e)
    dt=LSDT_BlinkyTape;
    else if (vendorID==0x2341 || vendorID==0x093a || vendorID==0x0403)
    dt=LSDT_Arduino;
    else if (vendorID==0x16c0)
    dt=LSDT_Teensy;
    else if (vendorID==0x2886)
    dt=LSDT_Seeeduino;
    else
    continue; // Not an arduino compatible device

    I can add the SparkFun ESP32 before MM 5.1 beta build. Could you send me the VID/PID of your product ? Just to be sure added the right ones. Are you on macOS or Windows ?
    This is how to get it: https://superuser.com/questions/1106247 ... 48#1106248
  • timbrass
    activ8 member
    Posts: 57
    Joined: Mon Mar 01, 2021 9:01 pm
    Contact:

    Re: Route ArtNet to USB LED Devices ... on an ESP32??

    by timbrass » Mon Mar 07, 2022 10:44 pm

    Matt - If you are adding other specific hardware IDs then can you add my Arduino Uno (clone)

    USB\VID_1A86&PID_7523&REV_0264
    USB\VID_1A86&PID_7523
  • mad-matt
    garageCube team
    Posts: 1475
    Joined: Mon Sep 09, 2013 5:50 pm

    Re: Route ArtNet to USB LED Devices ... on an ESP32??

    by mad-matt » Wed Mar 09, 2022 3:17 pm

    Done. For 5.1.0 beta 2 (or final release). I can PM you intermediate build when we have. Just let me know if you're on Windows or macOS
  • timbrass
    activ8 member
    Posts: 57
    Joined: Mon Mar 01, 2021 9:01 pm
    Contact:

    Re: Route ArtNet to USB LED Devices ... on an ESP32??

    by timbrass » Thu Mar 10, 2022 2:59 pm

    I am on Windows 11.

    At the moment I can see some LED activity on my single string of 25xWS2811 LEDs but only the first 9 light up (blink test fires all of them). No amount of fiddling with Fixture Manager seems to make the others work.

    The Device Setup for LED in Preferences/DMX Output defaults to 4000000 baud but does not accept changing that to the 921600 that Teensy 3.2 requires. Also there is a weird ? on the title bar that does nothing!
  • CaseyJScalf
    activ8 member
    Posts: 81
    Joined: Sat Nov 08, 2014 10:15 am

    Re: Route ArtNet to USB LED Devices ... on an ESP32??

    by CaseyJScalf » Wed May 25, 2022 1:53 am

    No, it's just that MadMapper filters virtual ports based on vendorID / productID:

    if (vendorID==0x1d50 && productID==0x60aa)
    dt=LSDT_BlinkyTile;
    else if (vendorID==0x1d50 && productID==0x605e)
    dt=LSDT_BlinkyTape;
    else if (vendorID==0x2341 || vendorID==0x093a || vendorID==0x0403)
    dt=LSDT_Arduino;
    else if (vendorID==0x16c0)
    dt=LSDT_Teensy;
    else if (vendorID==0x2886)
    dt=LSDT_Seeeduino;
    else
    continue; // Not an arduino compatible device

    I can add the SparkFun ESP32 before MM 5.1 beta build. Could you send me the VID/PID of your product ? Just to be sure added the right ones. Are you on macOS or Windows ?
    This is how to get it: https://superuser.com/questions/1106247 ... 48#1106248
    Thanks for the help you all rock! I am on the road now but I will look up that info and reply. Would be super cool to use the ESP32 and others as that opens up tons of options hardware wise!
  • reMutable
    junior Member
    Posts: 6
    Joined: Mon Mar 27, 2023 5:32 pm

    Re: Route ArtNet to USB LED Devices ... on an ESP32??

    by reMutable » Thu Nov 09, 2023 1:10 pm

    Done. For 5.1.0 beta 2 (or final release). I can PM you intermediate build when we have. Just let me know if you're on Windows or macOS
    Hi Mad Matt,

    Can you please add this ESP32 to your list ?

    Identifiant du produit : 0xea60
    Identifiant du fournisseur : 0x10c4 (Silicon Laboratories, Inc.)

    It is this board : JZK® ESP-32S ESP32

    I have set up a 1080 pixel installations for a party for this saturday. At home I was using a wifi router, I connected Madmapper and ESP32 (via WLED) to this wifi network and it was running quite smoothly. At the venue with samed setup, it is very difficult to connect to the wifi, and animations are very slow and it often loses connection and goes back to WLED style of animation. That why I would try to use USB.

    Thanks!
  • mad-matt
    garageCube team
    Posts: 1475
    Joined: Mon Sep 09, 2013 5:50 pm

    Re: Route ArtNet to USB LED Devices ... on an ESP32??

    by mad-matt » Thu Nov 09, 2023 6:26 pm

    Shit we just released 5.5 beta 1. Will be in next version, but if you tell me your platform I can start a build with this VID/PID.
  • mad-matt
    garageCube team
    Posts: 1475
    Joined: Mon Sep 09, 2013 5:50 pm

    Re: Route ArtNet to USB LED Devices ... on an ESP32??

    by mad-matt » Thu Nov 09, 2023 11:27 pm

    It's in 5.5 beta 2 available now
  • reMutable
    junior Member
    Posts: 6
    Joined: Mon Mar 27, 2023 5:32 pm

    Re: Route ArtNet to USB LED Devices ... on an ESP32??

    by reMutable » Mon Nov 13, 2023 11:14 am

    Thanks for you help, our leds where running smoothly during all our party :)

Who is online

Users browsing this forum: No registered users and 17 guests