Skip to content

error: 'U2TXD_OUT_IDX' was not declared in this scope #10

Closed

Description

@EdwardDeaver

Hi,

I'm trying to use this library with an esp32 Feather S2 from Unexpected Maker and I'm getting this issue when compiling the project.

SparkFun_DMX_Shield_Library/src/SparkFunDMX.cpp: In member function 'void SparkFunDMX::update()':
/SparkFun_DMX_Shield_Library/src/SparkFunDMX.cpp:127:31: error: 'U2TXD_OUT_IDX' was not declared in this scope
pinMatrixOutAttach(txPin, U2TXD_OUT_IDX, false, false);
^~~~~~~~~~~~~
SparkFun_DMX_Shield_Library/src/SparkFunDMX.cpp:127:31: note: suggested alternative: 'U1TXD_OUT_IDX'
pinMatrixOutAttach(txPin, U2TXD_OUT_IDX, false, false);
^~~~~~~~~~~~~
U1TXD_OUT_IDX

Activity

  1. romkey commented on Sep 15, 2023

    @romkey

    U2TXD_OUT_IDX isn't defined on the ESP32 S2 because it only has two UARTS. Vanilla (original) ESP32 and ESP32-S3 CPUs both have three UARTs.

  2. raypp2 commented on Sep 21, 2023

    @raypp2

    I'm having the same issue trying to use a SparkFun Thing Plus - ESP32-S2 WROOM with a SparkFun ESP32 Thing Plus DMX to LED Shield. In my case, I'm only trying to use the device to send and receive DMX commands. I am not controlling an LED fixture.
    Have you found any workaround for this or does this issue mean that this library isn't compatible with the S2?

  3. romkey commented on Sep 21, 2023

    @romkey

    The library as it's written is not going to build for the S2. Either Sparkfun needs to update it or you need to make a copy and edit it to use U1TXD_OUT_IDX. I'm not sure if that's the only change needed to make it build and run correctly with an S2.

  4. raypp2 commented on Sep 21, 2023

    @raypp2

    Thanks John. I did quickly try updating the U2TXD_OUT_IDX value in the SparkFunDMX.cpp to both U0TXD_OUT_IDX and U1TXD_OUT_IDX but unfortunately the solution wasn't that simple for my situation. It does compile but I suspect that changing the pin would cause it to no longer work on the DMX shield.

    I tested this on both the S2 and also tried loading the alternate UARTs onto a tested & working SparkFun Thing Plus original but that broke the DMX. It's not worth me testing different pinning right now because just using another S1 board is easier.

    If anyone at SparkFun reads this and this is truly a compatibility issue, it would be helpful to put a notice on the DMX Shield and S2's product pages that they will not be compatible. The product page currently shows this text, which would be inaccurate if this bug is hardware based:

    The DMX to LED shield is designed to work with the SparkFun Thing Plus - ESP32 WROOM or any board with a Feather footprint, so Feathers and Feather-Wings will fit it.

  5. brhoff720 commented on Sep 22, 2023

    @brhoff720
  6. added a commit that references this issue on Sep 29, 2023
  7. sfe-SparkFro commented on Sep 29, 2023

    @sfe-SparkFro
    Contributor

    Hi folks!

    I've created #11 that I think fixes compatibility with the ESP32-S2, as well as our USB-C version of the ESP32 Thing Plus (the pinout is slightly different).

    I've not had a chance to test it. @raypp2 or @EdwardDeaver any chance you're able to try it out and let me know how it goes? If all is well, I can merge the pull request and publish a new release. Thanks!

  8. pjpmarques commented on Sep 30, 2023

    @pjpmarques

    Hi,

    I've tried this patch with the ESP32 Thing Plus, USB-C version, and unfortunately it's not working for me.
    It may be another issue (since the only thing I have is the DMX shield and the board), but I suspect there's still a compatibility issue involved.

  9. sfe-SparkFro commented on Oct 2, 2023

    @sfe-SparkFro
    Contributor

    Thank you for testing! Sorry that it didn't fix it, I'll dig a bit deeper and try to resolve the problem once I have some hardware to play with, and time to play with it 🕐

  10. pjpmarques commented on Oct 2, 2023

    @pjpmarques

    Fyi -- Using the correct pins which are in the patch (Pin 4 - Enable, Pin 16 - RX, Pin 17 - TX), I got the board to work using the ESP32 Thing Plus, USB-C version, but not using the provided library. I've implemented the correct timings for detecting the start of data and the UART#2 to read the data packets. Thus, without going into "debugging mode" on the Sparkfun library, it seems to me that the problem is in the timings/timers/interrupts being used.

    Snippet of my code (ugly, I know, but I was just trying to debug this):

      // ...
      uart.begin(DMX_BAUD, SERIAL_8N2, rx_pin, tx_pin);
    
      bool good_start = false;
      while (!good_start) {
        // Wait while RX is HIGH (idle)
        while (digitalRead(rx_pin) == HIGH)
            ;
    
        // We've detected RX became low, start counting time
        unsigned long t1 = micros();
    
        // Now the signal needs to be low for at least 88 usec
        while (true) {
            // If the signal becomes high before 88usec, it was a false start, if it continues low after that, it's a good start
            if (digitalRead(rx_pin) == HIGH) {
                break;
            }
    
            unsigned long t2 = micros();
            if (t2-t1 >= 88) {
                good_start = true;
                break;
            }
        }
      }
    
      // Ok, we have a good start with RX still low. Let's continue to monitor until it becomes HIGH
      while (digitalRead(rx_pin) == LOW)
        ;
    
      // Ok, RX is now HIGH, we can activate the UART for the rest of the decoding
      uart.flush(false);
    
    // Read the 512 channels
    // ....
  11. sfe-SparkFro commented on Oct 2, 2023

    @sfe-SparkFro
    Contributor

    Thanks for the code, that's helpful!

    I've got some hardware and tinkered with it a bit today testing with Example 1 and 2. There was an issue with the timer here:

    timer = timerBegin(0, 1, true);

    E (31) timer_group: timer_init(275): HW TIMER divider outside of [2, 65536] range error
    E (31) timer_group: timer_set_counter_value(86): HW TIMER NEVER INIT ERROR
    E (35) timer_group: timer_start(97): HW TIMER NEVER INIT ERROR
    E (40) timer_group: timer_isr_callback_add(227): HW TIMER NEVER INIT ERROR
    E (47) timer_group: timer_set_alarm_value(155): HW TIMER NEVER INIT ERROR
    E (53) timer_group: timer_set_auto_reload(132): HW TIMER NEVER INIT ERROR
    E (60) timer_group: timer_set_alarm(179): HW TIMER NEVER INIT ERROR
    

    Makes me wonder, did this ever work? Far as I can tell, the divider always needed to be at least 2 in the ESP-IDF, right? Idk. This library needs a serious overhaul, though I don't have time for that unfortunately.

    I've pushed some commits to #11 that fix this, and some synchronization issues, and another spot where the UART number needed to be changed for the S2. I've got it working on my end with the ESP32 Thing Plus, ESP32 Thing Plus (USB-C), and ESP32-S2 Thing Plus.

    @pjpmarques You mind testing it again quickly for me? Just want to make sure I've not broken anything 😉 If all is well, I'll merge it in.

  12. pjpmarques commented on Oct 2, 2023

    @pjpmarques

    I've tried the new code and it's not working for me. Not sure why, since it seems to be because of the time as you said. I've using the library as this (connected to a proper DMX512 show controller with 192 channels). The test code is as follows:

    #include <Arduino.h>
    #include <HardwareSerial.h>
    #include <SparkFunDMX.h>
    
    SparkFunDMX dmx;
    
    void setup() {  
      Serial.begin(115200);
    
      Serial.printf("\n\n\n\n\n");
      Serial.printf("Let's start reading this:\n\n"); 
    
      dmx.initRead(192);
    }
    
    void loop()
    {
      dmx.update();
    
      for (int i=0; i<193; i++) {
        if (i%32 == 0) {
          Serial.printf("\n(%3i)  ", i);
        }
        Serial.printf("%4d", dmx.read(i));
      }
    
      Serial.printf("\n");
      delay(2000);
    }

    When the program starts, I get a timer error, saying it's not in range. Even though your code is setting it to 2.

    Let's start reading this:
    
    E (16) timer_group: timer_init(275): HW TIMER divider outside of [2, 65536] range error
    E (17) timer_group: timer_set_counter_value(86): HW TIMER NEVER INIT ERROR
    E (22) timer_group: timer_start(97): HW TIMER NEVER INIT ERROR
    E (27) timer_group: timer_isr_callback_add(227): HW TIMER NEVER INIT ERROR
    E (34) timer_group: timer_set_alarm_value(155): HW TIMER NEVER INIT ERROR
    E (41) timer_group: timer_set_auto_reload(132): HW TIMER NEVER INIT ERROR
    E (47) timer_group: timer_set_alarm(179): HW TIMER NEVER INIT ERROR
    
    (  0)     0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
    ( 32)     0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
    ( 64)     0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
    ( 96)     0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
    (128)     0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
    (160)     0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
    (192)     0
    

    And I've checked, your code is setting the divisor to 2:

    timer = timerBegin(0, 2, true);

    Paulo

  13. sfe-SparkFro commented on Oct 2, 2023

    @sfe-SparkFro
    Contributor

    Thanks Paulo, I appreciate your time on this!

    Hmm, that's odd. Could you please double check that you've correctly grabbed the code from #11? Do you happen to have 2 copies of this library downloaded? Also please try restarting Arduino. The fact that you're getting that error message indicates to me that Arduino is not compiling the latest code from #11

  14. pjpmarques commented on Oct 2, 2023

    @pjpmarques

    Hi,

    You are correct. Sorry, my fault (too tired). The build was grabbing the old library. Even so, with the new code it's not correctly reading from a "proper DMX controller". Here's what I get running the code (zeros in all channels):

    ---- Opened the serial port /dev/tty.usbserial-110 ----
    ets Jul 29 2019 12:21:46
    
    rst:0x1 (POWERON_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
    configsip: 0, SPIWP:0xee
    clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
    mode:DIO, clock div:2
    load:0x3fff0030,len:1184
    load:0x40078000,len:13192
    load:0x40080400,len:3028
    entry 0x400805e4
    
    
    
    Let's start reading this:
    
    
    (  0)     0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
    ( 32)     0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
    ( 64)     0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
    ( 96)     0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
    (128)     0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
    (160)     0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
    (192)     0
    

    While I should be getting something like this:

    ---- Opened the serial port /dev/tty.usbserial-110 ----
    ets Jul 29 2019 12:21:46
    
    rst:0x1 (POWERON_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
    configsip: 0, SPIWP:0xee
    clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
    mode:DIO, clock div:2
    load:0x3fff0030,len:1184
    load:0x40078000,len:13192
    load:0x40080400,len:3028
    entry 0x400805e4
    
    
    
    Let's start reading this:
    
    
    (  0)   123 160 184 191 153  86 115   0   0   0   0   0   0   0   0   0 123 160 184 191 153  86 115   0   0   0   0   0   0   0   0   0
    ( 32)   123 160 184 191 153  86 115   0   0   0   0   0   0   0   0   0 123 160 184 191 153  86 115   0   0   0   0   0   0   0   0   0
    ( 64)   123 160 184 191 153  86 115   0   0   0   0   0   0   0   0   0 123 160 184 191 153  86 115   0   0   0   0   0   0   0   0   0
    ( 96)   123 160 184 191 153  86 115   0   0   0   0   0   0   0   0   0 123 160 184 191 153  86 115   0   0   0   0   0   0   0   0   0
    (128)   123 160 184 191 153  86 115   0   0   0   0   0   0   0   0   0 123 160 184 191 153  86 115   0   0   0   0   0   0   0   0   0
    (160)   123 160 184 191 153  86 115   0   0   0   0   0   0   0   0   0 123 160 184 191 153  86 115   0   0   0   0   0   0   0   0   0
    (192)     0
    

    I have the ESP32 connected to a "MKP-DMX192" board. Photo in attachment.

    controller

  15. pjpmarques commented on Oct 2, 2023

    @pjpmarques

    @EdwardDeaver For reference, if it helps, here's the complete implementation of my library, which is reading correctly from the controller:

    dmx.h

    #pragma once
    
    #include <HardwareSerial.h>
    
    #define DMX_MAX_CHANNEL                 512
    #define DMX_BAUD                        250000
    #define DMX_PROTOCOL                    SERIAL_8N2
    #define DMX_START_DELAY                 88  // usec
    #define DMX_TIMEOUT                     25  // msec
    #define DMX_RX_PIN                      16
    #define DMX_TX_PIN                      17
    #define DMX_EN_PIN                      4
    #define DMX_DEFAULT_UART                2
    
    class DMX {
        public:
            DMX();
            DMX(int uart, int rx_pin, int tx_pin, int en_pin);
            ~DMX();
    
            int update();
            uint8_t read(int channel);
    
        private:
            HardwareSerial uart;
            int rx_pin;
            int tx_pin;
            int en_pin;
            uint8_t channel[DMX_MAX_CHANNEL+1] = {};
    };
    

    dmx.cpp

    #include <Arduino.h>
    #include <HardwareSerial.h>
    #include <dmx.h>
    
    DMX::DMX(int uart_number, int rx, int tx, int en) :
        uart(uart_number), rx_pin(rx), tx_pin(tx), en_pin(en) {
    }
    
    DMX::DMX() : DMX(DMX_DEFAULT_UART, DMX_RX_PIN, DMX_TX_PIN, DMX_EN_PIN) {
        uart.setRxBufferSize(DMX_MAX_CHANNEL+1);
        pinMode(en_pin, OUTPUT);
        pinMode(rx_pin, INPUT);
    } 
    
    DMX::~DMX() {
    }
    
    int DMX::update() {
      uart.begin(DMX_BAUD, SERIAL_8N2, rx_pin, tx_pin);
      uart.setTimeout(DMX_TIMEOUT);
      digitalWrite(en_pin, LOW);
    
      bool good_start = false;
      while (!good_start) {
        // Wait while RX is HIGH (idle)
        while (digitalRead(rx_pin) == HIGH)
            ;
    
        // We've detected RX became low, start counting time
        unsigned long t1 = micros();
    
        // Now the signal needs to be low for at least 88 usec
        while (true) {
            // If the signal becomes high before 88usec, it was a false start, if it continues low after that, it's a good start
            if (digitalRead(rx_pin) == HIGH) {
                break;
            }
    
            unsigned long t2 = micros();
            if (t2-t1 >= DMX_START_DELAY) {
                good_start = true;
                break;
            }
        }
      }
    
      // Ok, we have a good start with RX still low. Let's continue to monitor until it becomes HIGH
      while (digitalRead(rx_pin) == LOW)
        ;
    
      // Ok, RX is now HIGH, we can activate the UART for the rest of the decoding
      uart.flush(false);
    
      // Read at most the 512+1 channels within the available timeout (at most 25msec)
      int channelsRead = uart.readBytes(channel, DMX_MAX_CHANNEL);
      uart.end();
    
      // Sanity check. Channel zero always needs to be zero.
      if (channel[0] != 0x00) {
        return -1;
      }
    
      // All ok
      return channelsRead;
    }
    
    uint8_t DMX::read(int channel_num) {
        return channel[channel_num];
    }
  16. sfe-SparkFro commented on Oct 3, 2023

    @sfe-SparkFro
    Contributor

    Darn, that's no good! Glad you have an actual DMX controller to test with though, that's helpful!

    I wonder if it's a synchronization issue, and the first message is just getting missed or something. Are you just reading once? Are you able to get data if you keep reading in a loop?

  17. sfe-SparkFro commented on Oct 3, 2023

    @sfe-SparkFro
    Contributor

    So, I got fed up of trying to hack this library together and basically just rewrote the whole thing (see #12). It should be more platform agnostic (only tested with our ESP32 boards so far), and should be more robust (there could be some edge cases I've not considered). I've updated the first couple examples to demonstrate basic usage; it's fairly similar, but there are some bigger differences.

    @pjpmarques Since you have an actual DMX controller, could you please test out #12? Should be able to use Example 2 with some modifications:

    • Change enPin to 4 for the ESP32 Thing Plus C
    • Change numChannels to 192
    • Read all 192 channels instead of just channel 1
      • The new library also allows you to copy the channels into an array with readBytes() if that's easier

    @raypp2, @EdwardDeaver, and @romkey, I'd also appreciate if any of you have time to take a look and let me know if #12 seems better! In order to use the ESP32-S2 Thing Plus, you'll need to modify Examples 1 and 2 with the following (all before setup():

    • Change the dmxSerial definition to use UART 1 instead of 2
    • Change rxPin to 33
    • Change txPin to 34
    • Change enPin to 3

    Thank you all!

  18. pjpmarques commented on Oct 5, 2023

    @pjpmarques

    Hi @sfe-SparkFro, sorry for the delay. I've tried the new library and I'm getting the correct data from the DMX controller. Kudos for the change.

    Nonetheless, I'm always getting this warning message in the beginning:

    [    32][E][HardwareSerial.cpp:554] setPins(): setPins() shall be called after begin() - nothing done
    

    Here's an example of the complete output that shows the message and the modified example 2, reading in loop all the 192 channels being sent by the controller.

    ---- Opened the serial port /dev/tty.usbserial-110 ----
    ets Jul 29 2019 12:21:46
    
    rst:0x1 (POWERON_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
    configsip: 0, SPIWP:0xee
    clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
    mode:DIO, clock div:2
    load:0x3fff0030,len:1184
    load:0x40078000,len:13192
    load:0x40080400,len:3028
    entry 0x400805e4
    SparkFun DMX Example 2 - Input
    [    32][E][HardwareSerial.cpp:554] setPins(): setPins() shall be called after begin() - nothing done
    
    DMX initialized!
    
    (  1)   100  50 150 200  10  20  30  40 200 150 140 130 120 110 100  90 100  50 150 200  10  20  30  40 200 150 140 130 120 110 100  90 
    ( 33)   100  50 150 200  10  20  30  40 200 150 140 130 120 110 100  90 100  50 150 200  10  20  30  40 200 150 140 130 120 110 100  90 
    ( 65)   100  50 150 200  10  20  30  40 200 150 140 130 120 110 100  90 100  50 150 200  10  20  30  40 200 150 140 130 120 110 100  90 
    ( 97)   100  50 150 200  10  20  30  40 200 150 140 130 120 110 100  90 100  50 150 200  10  20  30  40 200 150 140 130 120 110 100  90 
    (129)   100  50 150 200  10  20  30  40 200 150 140 130 120 110 100  90 100  50 150 200  10  20  30  40 200 150 140 130 120 110 100  90 
    (161)   100  50 150 200  10  20  30  40 200 150 140 130 120 110 100  90 100  50 150 200  10  20  30  40 200 150 140 130 120 110 100  90 
    
    (  1)   100  50 150 200  10  20  30  40 200 150 140 130 120 110 100  90 100  50 150 200  10  20  30  40 200 150 140 130 120 110 100  90 
    ( 33)   100  50 150 200  10  20  30  40 200 150 140 130 120 110 100  90 100  50 150 200  10  20  30  40 200 150 140 130 120 110 100  90 
    ( 65)   100  50 150 200  10  20  30  40 200 150 140 130 120 110 100  90 100  50 150 200  10  20  30  40 200 150 140 130 120 110 100  90 
    ( 97)   100  50 150 200  10  20  30  40 200 150 140 130 120 110 100  90 100  50 150 200  10  20  30  40 200 150 140 130 120 110 100  90 
    (129)   100  50 150 200  10  20  30  40 200 150 140 130 120 110 100  90 100  50 150 200  10  20  30  40 200 150 140 130 120 110 100  90 
    (161)   100  50 150 200  10  20  30  40 200 150 140 130 120 110 100  90 100  50 150 200  10  20  30  40 200 150 140 130 120 110 100  90 
    

    Modified code for reference:

    void loop()
    {
        // Wait until data has been received
        while(dmx.dataAvailable() == false)
        {
            // Update must be called to update received data
            dmx.update();
        }
    
        // Data has been received, read out all channels
        uint8_t data[192];
        dmx.readBytes(data, 192, 1);
        
        for (int i=0; i<192; i++) {
          if (i%32 == 0) {
            Serial.printf("\n(%3d)   ", i+1);
          }
    
          Serial.printf("%3d ", data[i]);
        }
        Serial.printf("\n");
    
        delay(5000);
    }
  19. sfe-SparkFro commented on Oct 5, 2023

    @sfe-SparkFro
    Contributor

    Woo! Glad to hear it's working for you!

    Hmm, I'm not receiving the same error on my end, but looks like I need to adjust where the UART pins are set. I'll fix that and clean up some other things, I think I can cut a new v2.0.0 release some time next week.

    Stay tuned, and thanks again for your help in testing!

  20. sfe-SparkFro commented on Oct 12, 2023

    @sfe-SparkFro
    Contributor

    FYI just made a v2.0.0 release. If you find any problems with it, please open a new issue. Thank you all for your help!

  21. raypp2 commented on Nov 4, 2023

    @raypp2

    Thanks for your hard work on this @sfe-SparkFro !
    I don't have time to implement the new version right now into my code & test with the S2, but it's at the top of my roadmap. Here's the project I'm using this for:
    https://github.com/raypp2/Apollo-Dmx-Bridge

  22. lichtdefekte commented on Mar 13, 2024

    @lichtdefekte

    @raypp2 a Problem seems to persist on my Setup similar to yours (Thing Plus Wroom USB-C / SparkfunDMX).
    I opened a diskussion on Arduino Forum:
    https://forum.arduino.cc/t/sparkfun-dmx-to-led-shield-mit-esp32-thing-plus-c/1233050/2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions