Possible WS2812 Library conflict with USBMidi?

Status
Not open for further replies.

vince.cimo

Well-known member
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.
 
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.
 
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....
 
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...
 
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.
 
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.
 
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/g3cyhmr6rmrrngo/teensy_WS2812_issue.zip?dl=0
 
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
 
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/latest/platforms/teensy.html#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?
 
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?
 
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?
 
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.
 
Status
Not open for further replies.
Back
Top