Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 2 1 2 LastLast
Results 1 to 25 of 31

Thread: Possible WS2812 Library conflict with USBMidi?

  1. #1

    Possible WS2812 Library conflict with USBMidi?

    Hi guys,

    I'm having an issue using the Non-Blocking WS2812B library (https://www.pjrc.com/non-blocking-ws2812-led-library/) with USBMidi. Using the example code for the WS2812B basic library test, if I put USBMidi.read() inside the loop, the program crashes. Are the two libraries incompatible or something? I can provide code if desired but I'm literally just adding the USBMidi.read() line inside the basic test.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,692
    Quote Originally Posted by vince.cimo View Post
    I can provide code if desired but I'm literally just adding the USBMidi.read() line inside the basic test.
    Yes, please give us the exact program.

  3. #3
    Code:
    #include <WS2812Serial.h>
    #include <Arduino.h>
    
    const int numled = 12;
    const int pin = 24;
    DMAMEM byte displayMemory[numled*12]; // 12 bytes per LED
    byte drawingMemory[numled*3];         //  3 bytes per LED
    WS2812Serial leds = WS2812Serial(numled, displayMemory, drawingMemory, pin, WS2812_GRB);
    
    void setup()
    {
      leds.begin();
      Serial.begin(9600);
    }
    
    void loop()
    {
      Serial.print("looping");
      while (usbMIDI.read()) {
      }
    }
    Curiously, this seems to run fine if compiled using the Arduino IDE, but not when using VSCode (PlatformIO). I'm fairly perplexed as it's about as easy as it gets. If I pull out leds.begin(), I see the Serial.print() fine in VSCode. Not sure what's going on. If I had to guess, I'm guessing there's some environment variables that need to be set in the platformio.ini file.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,692
    I'm not sure if PlatformIO really supports the non-Serial options (all the stuff in the Tools > USB Type menu in Arduino).

    Maybe just using the Arduino IDE for now?

    Sent a quit email to Ivan just now. Maybe he'll have some insight on this....

  5. #5
    The platform io system allows you to specify build flags which are essentially the same thing as the usb type setting in the arduino IDE. I've had a pretty complicated usb midi project build just find with serial logging working perfectly, so it's quite odd that there is this weird conflict.

    I have all my code in a .h and .cpp format with a load of custom libraries...so its outside of the default .ino workflow I'm used to with the arduino ide. I'll have to look into getting the project working with the arduino ide again...vs code is pretty buggy anyway. Will keep you posted. Please let me know if Ivan comes back with any suggestions. Pretty stuck on this...

  6. #6
    Ok quick update, i've ported everything over to the Arduino IDE and things work great. To be honest, I may even like this setup better. It's slightly annoying to have to tab over to Arduino and press build, but it's a helluva lot more reliable than any of the other build systems I have used, with Platform IO being the next in line, and then Sloeber (worked like 20% of the time). Now, I'm using Eclipse to have a robust C++ dev environment and Arduino to build. For those curious, to make this work, you just have to have a .ino file that does basic stuff in the setup and loop functions, then you can put all your functionality into the custom libraries and edit those using your dedicated IDE. You just need to put your libraries in the Arduino libraries folder....yes this is kind of annoying, but it works Also...Paul...thanks so much for being so dedicated to helping people like me out. Without your help I would not have gotten this far.

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,692
    Arduino also has a "use external editor" setting in File > Preferences which might help.

    I'm still holding hope than Ivan might see this soon and be able to offer some guidance to get PlatformIO to build the code correctly as Arduino does.

  8. #8
    Do you use the same optimization profiles? USB settings? See docs how to configure them https://docs.platformio.org/en/lates...#configuration

    Can I reproduce this issue without MIDI device? I have Teensy 3.1 and 3.6.

    Thanks!

  9. #9
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,692
    Quote Originally Posted by ikravets View Post
    Can I reproduce this issue without MIDI device?
    This problem is where Teensy is acting as a USB MIDI device, as seen by your PC. It doesn't involve connecting any MIDI device to Teensy.

  10. #10
    Quote Originally Posted by PaulStoffregen View Post
    This problem is where Teensy is acting as a USB MIDI device, as seen by your PC. It doesn't involve connecting any MIDI device to Teensy.
    I've tried multiple optimization profiles and have the USB type set to USB_MIDI_SERIAL.

  11. #11
    Quote Originally Posted by vince.cimo View Post
    I've tried multiple optimization profiles and have the USB type set to USB_MIDI_SERIAL.
    Any more insight on this guys?

  12. #12
    Sorry for the delay. We have reproduced this issue and will come soon with updates. Thanks!

  13. #13
    Quote Originally Posted by ikravets View Post
    Sorry for the delay. We have reproduced this issue and will come soon with updates. Thanks!
    Awesome thanks so much Ivan!

  14. #14
    Ok, that was the wrong message by me before. Actually, it works in the same way as with Arduino IDE. Could you provide non-working PlatformIO project? I used the next configuration:

    Code:
    [env:teensy31]
    platform = teensy
    board = teensy31
    framework = arduino
    build_flags = -D USB_MIDI_SERIAL
    What do you mean under `the program crashes`?

    Please run `$ pio device monitor`. Do you use any output?

    See project example https://www.dropbox.com/s/g3cyhmr6rm...issue.zip?dl=0

  15. #15
    Just ran your project. Same result. What I mean by 'the program crashes' is that I don't see any serial output when using pio device monitor. I should be seeing 'looping' be spit out over and over again. If I remove the leds.begin() call, the message is printed to the serial monitor.

    Here's the example project I was using. I think it's pretty much the exact same except I'm using a Teensy LC board.

    https://www.dropbox.com/s/tdxyuwd6fxjy4cn/test.zip?dl=0

  16. #16
    Hm... We've reproduced this issue now. The problem is linked only with Teensy LC. The only for this board a default optimization profile is "Smallest code". We introduced optinization profiles a few weeks ago. You can read more here https://docs.platformio.org/en/lates...l#optimization

    Could you try the next configuration?
    Code:
    [env:teensylc]
    platform = teensy
    board = teensylc
    framework = arduino
    build_flags = -D USB_MIDI_SERIAL -DTEENSY_OPT_SMALLEST_CODE
    Does it work now?

  17. #17
    @Paul, should we use "Smallest code" as default optimization profile for all Teensy boards?

  18. #18
    Still not working with new configuration.

  19. #19
    1. Do you use the latest Teensy dev/platform for PlatformIO? Please run `$ pio update` in IDE Terminal
    2. Could you try USB_MIDI_SERIAL + Faster Optimization profile in Arduino IDE. Does it work for you?

  20. #20
    The update fixed it! I was on 4.0. Works with smallest optimization profile. Thanks! You are a wizard!

  21. #21
    Please try this

    2. Could you try USB_MIDI_SERIAL + Faster Optimization profile in Arduino IDE. Does it work for you?
    It seems that this combination also does not work with Teensyduino. Am I right?

  22. #22
    Quote Originally Posted by ikravets View Post
    Please try this



    It seems that this combination also does not work with Teensyduino. Am I right?
    Using "-D TEENSY_OPT_FASTER", the test project does not correctly output the Serial.print()...indicating a crash.

  23. #23
    I mean to use Teensyduino:

    - USB Type: Serial + Midi
    - Optimization: Faster

    See https://pasteboard.co/I083nQL.png

  24. #24
    Hi Ivan, sorry for the delay. Yes, I can confirm that this code snipped DOES NOT work with the Arduino IDE using Faster optimization & Serial + Midi setting. Sounds like Platform IO is all good.

  25. #25
    Thanks!

    @PaulStoffregen, could we use `TEENSY_OPT_SMALLEST_CODE` as default optimization profile?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •