Arduino intermittent hang up?


Hey I'm working on a NeoPixel Arduino and Millumin integration with an Uno board. I've gotten the libraries to work and correctly trigger the digital pins, but every once in a while the pins don't read the data track from the the dashboard. About 1 in every 20-30 toggles, and it gets hung up for a few seconds up to 30 seconds before it corrects itself. Is there something I'm missing in the code?

#include <Adafruit_NeoPixel.h>
#include <Arduino.h>
#include <MilluminStream.h>

// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1:
#define LED_PIN    6

// How many NeoPixels are attached to the Arduino?
#define LED_COUNT 16

// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);

int inten = 0; // Global instensity for sharing and cross fading effects

void setup() {
  // These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
  // Any other board, you can remove this part (but no harm leaving it):
  Serial.begin(9600);

  MilluminStream:setup();
  MilluminStream::setLoopIdleTime(16);
  pinMode(13, INPUT_PULLUP);
  pinMode(LED_BUILTIN, OUTPUT);
  strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
  strip.show();            // Turn OFF all pixels ASAP
  strip.setBrightness(100); // Set BRIGHTNESS

}


void loop() {

 // First, we need to update MilluminStream
  MilluminStream::update();

  

  int digPin13 = digitalRead(13);

  if (digPin13 == 1) {
    digitalWrite(LED_BUILTIN, HIGH);
    //rainbow(10);
  } else {
    digitalWrite(LED_BUILTIN, LOW);
    //pulseWhite(5);
  }

  MilluminStream::sendDigitalForID(13);

  // Finally we send just one frame with all our values 
  MilluminStream::sendFrame();

}
//... Rest of functions below don't affect the code.


Comments

  • Hello @whataweirdguy,

    I see a first error in MilluminStream:setup() : it should be MilluminStream::setup()

    Also, LED_BUILTIN is usually the pin 13, so in your program you are reading and writing at the same time, which is not a good practice. You should rather use a variable to do so, and MilluminStream can help you with this.

    Please check this project and this sketch that update a variable on both sides :

    #include <MilluminStream.h>
    
    int ledValue = LOW;
    
    void onInputValue(uint8_t key, uint8_t index, uint16_t value)
    {
     if( key == 'V' && index == 7 )
     {
       ledValue = value;
     }
    }
    
    void setup() {
     MilluminStream::setup();
     MilluminStream::setInputCallback(onInputValue);
     pinMode(LED_BUILTIN, OUTPUT);
    }
    
    void loop() {
     MilluminStream::update();
     digitalWrite(LED_BUILTIN, ledValue);
     MilluminStream::sendVariableForID(7, ledValue);
     MilluminStream::sendFrame();
    }
    


    Best. Philippe

  • Thanks Philippe, I will give this a try and report back

  • Got the variables working. Love this option. Allows for many more triggers. But I am still getting the hung data like the previous version.

    This is good enough for my immediate needs, but hoping to figure this out for other more sensitive projects down the road. May be by hardware on my side, so I will try different cables, etc.

    #include <Adafruit_NeoPixel.h>
    #include <Arduino.h>
    #include <MilluminStream.h>
    
    // Which pin on the Arduino is connected to the NeoPixels?
    // On a Trinket or Gemma we suggest changing this to 1:
    #define LED_PIN    6
    
    // How many NeoPixels are attached to the Arduino?
    #define LED_COUNT 16
    
    // Declare our NeoPixel strip object:
    Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);
    
    int inten = 0; // Global instensity for sharing and cross fading effects
    
    int ledValue = LOW; // Sets M4 variable value
    
    void onInputValue(uint8_t key, uint8_t index, uint16_t value)
    {
     if( key == 'V' && index == 7 )
     {
       ledValue = value;
     }
    }
    
    void setup() { 
    
      MilluminStream::setup();
      MilluminStream::setInputCallback(onInputValue);
      
      strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
      strip.show();            // Turn OFF all pixels ASAP
      strip.setBrightness(100); // Set BRIGHTNESS
    
    }
    
    
    void loop() {
    
     // First, we need to update MilluminStream
      MilluminStream::update();
    
      if (ledValue == 0) {
        //digitalWrite(LED_BUILTIN, HIGH);
        //rainbow(10);
      } else if (ledValue == 1) {
        //digitalWrite(LED_BUILTIN, LOW);
        //rainbow(10);
        //pulseWhite(5);
      } else if (ledValue == 2) {
        //digitalWrite(LED_BUILTIN, LOW);
        //rainbow(10);
        //pulseWhite(5);
      }
    
      MilluminStream::sendVariableForID(7, ledValue);
    
      // Finally we send just one frame with all our values
      MilluminStream::sendFrame();
    
    }
    
    
  • Hello @whataweirdguy,

    I just tested without any NeoPixels leds, and it works fine.

    Please use my sketch above only, and let us know if the problem persists.

    Best. Philippe

Sign In or Register to comment.