Teensy 3.2 or 4.0 / WS2812BSerial / USB MIDI hanging problem

royshearer

New member
Hi there,

I'm having a peculiar problem with a Teensy 3.2 (and alternatively the Teensy 4.0) taking 2 digital button inputs and outputting animation to an addressable LED strip (WS2812BSerial library) and midi on/off to USB MIDI (the regular teensy functionality) on 4 channels. The buttons, placed at each end of the LED strip trigger 'pulses' of light that travel down the strip from either end, along with musical notes. While the pulses collide they trigger a new note and their colour changes. A video here:
https://drive.google.com/file/d/1gG5TE_Ih6drOWGV8DnDzquKKXmvBGJl5/view?usp=sharing
and a schematic here:
https://drive.google.com/file/d/19rPwNceiDRpEENzUpxHya2ntvdTc2BN_/view?usp=sharing
(NB. LEDs are now running via pin 8 (not 5) for Teensy 4.0, and via a 74AHCT125 level shifter)

The issue:
The code is running fine for a period of time, but then at one point in time stops outputting both MIDI and the LED strip control (the LED animation freezes). This period of time is consistently between 2 and 3 hours when the system is running without any button presses (therefore no LED animation), and more like 30-45mins when it is running with regular button presses (lots of animation). I have the onboard LED blinking to indicate that the main loop is running - this continues after the other outputs freeze, indicating the entire board is not crashing.

The code is fairly large and it is hard to post a relevant snippet here, however the whole project is on Github here:
https://github.com/SoundplayProjects/LEDStrip

Things I have tried:
  • I have tried in vain to pinpoint an area in the code that is causing the behaviour (switching off the input and output sections of code in turn).
  • I have tried switching LED library to Adafruit Neopixel, with no luck.
  • Accelerating the code in order to test changes more quickly - reducing the delayMicroseconds delay in the loop to 25000 to 1000 - not sure if this could actually be exacerbating the issue?


I am left thinking the problem is intrinsic to the way I am handling the data, or some conflict in the hardware itself - I am aware I am using a lot of Serial functionality - could this be causing issues? Could the problem be memory related (although the issue still occurs when the could is running idly)?

Things I am planning to try are:
  • Switching out to fastLED library - investigating ways of flushing any buffers in the library.
  • Switching the microSecond delay in the loop to a timer based 'delay' instead.
  • Switching off serial debugging output and finding some other method of debugging.
  • Trying out using the OctoWS2811 board and library.
  • Switching to a different microcontroller (Eg. Adafruit Feather)
  • Switching from USB MIDI to OSC, or hardwired GPIO output.
  • Removing the 'collision detection' animation functionality (detecting when sprites collide and rendering them differently - added a lot of complexity)
  • Masking collisions towards the end of the strip (these collisions add a lot of complexity, and I don't fully understand how my code is handling it)


I realise this is a very general question but does anyone have any other ideas of possible causes or things I could try?
 
Back
Top