ESP32 with WS2813 LED strip glitch

Thread Starter

zazas321

Joined Nov 29, 2015
936
Hello. I am working with ESP32 and LED strip WS2813. I have cut an LED strip and currently using just 6 LEDS

The function that I use:

Code:
void Read_sensor(){
  //IF ITEM ACTIVATED, SET GREEN LIGHT AND WAIT FOR PERSON TO TOGGLE THE DEVICE
    if(number_to_pick>0){// LED TURNS GREEN IF WE NEED TO TAKE ITEM FROM THE BOX
      digitalWrite(LED_GREEN,1); 
    }
    sensor=digitalRead(SENSOR);//ALWAYS TAKE SENSOR READING EVERY 50MS
    
    if(sensor==LOW && sensor_prev_state==HIGH){ // IF SENSOR IS TRIGGERED ON
      sensor_prev_state=LOW; // set the previous state to LOW
      Serial.print("sensor triggered\n"); // output serial monitor
      if (number_to_pick==0){ // IF NUMBER TO PICK ITEMS IS 0, SET RED LIGHT TO SHOW OPERATOR WRONG BOX
        digitalWrite(LED_RED,1);     //if the sensor active flag is 0 (item not activated), set the RED light on to indicate the wrong selection  
        //tone(BUZZER, frequency);
        pixels.fill(magenta, 0, 6);
        pixels.show();   // Send the updated pixel colors to the hardware.
      }
    }
      
    
    else if(sensor==HIGH && sensor_prev_state==LOW){ //sensor deactivated
      if(number_to_pick > 0){ // if we still need to take items from this box after
        char buffer2 [33];
        digitalWrite(LED_GREEN,0); //turn off GREEN LED // set the green LED off and reset the flag
        number_to_pick--;
        item_inside.quantity--;
        itoa (number_to_pick,buffer2,10);
        client.publish(number_to_pick_topic, buffer2); // publish a message that the sensor has been triggered    
        create_JSON_object();  // publish item_inside topic to update quantity
        //OLED_display(item_inside.quantity,number_to_pick);
        Serial.print("number_to_pick=");
        Serial.println(number_to_pick);
        sensor_prev_state = HIGH;
        delay(200);
        if(number_to_pick==0){ // if we finished collecting items from this box, blink yellow LED to notify operator 
          client.publish(status_topic,"DONE");
          client.publish(number_to_pick_topic,"0");// respond to topic that 0 items lef       }
        }
    }
        else{
          sensor_prev_state = HIGH;
          digitalWrite(LED_RED,0);
          pixels.clear(); // Set all pixel colors to 'off'
          pixels.show();   // Send the updated pixel colors to the hardware.
          //noTone(BUZZER);
        }
    }
}
I simply read the proximity sensor and turn on an LED when I detect a humand hand
When the sensor detects a hand:
Code:
        pixels.fill(magenta, 0, 6);
        pixels.show();   // Send the updated pixel colors to the hardware.
when hand is no longer detected:
Code:
          pixels.clear(); // Set all pixel colors to 'off'
          pixels.show();   // Send the updated pixel colors to the hardware.

It works almost okay - I put my hand in front of the sensor and the LED strip lights in purple (the colour magenta that I have set). When I take hand away from the sensor, 95% of the time, the led strip will clear and turn off. The remaining 5% off the time, the LED will glitch and turn ON a random led random colour. Most of the time its either first LED or the last LED colour green or blue.

Is this expected behaviour from WS2813 LED strip? Is there any way to overcome this problem
 

Thread Starter

zazas321

Joined Nov 29, 2015
936
I have managed to make a little video to demonstrate what I mean:
I hope the link works. The blue led randomly remains ON
 

BobTPH

Joined Jun 5, 2013
8,813
No, it is not normal. I have been using them for years, and, if the circuit and software are good, the are very reliable.

I suspect the sensor is triggering back and forth rapidly and your code getting confused.

One thing to look for, are you allowing time for the reset after writing to the strip?

Bob
 

Thread Starter

zazas321

Joined Nov 29, 2015
936
No, it is not normal. I have been using them for years, and, if the circuit and software are good, the are very reliable.

I suspect the sensor is triggering back and forth rapidly and your code getting confused.

One thing to look for, are you allowing time for the reset after writing to the strip?

Bob
What do you mean by that? Should i include a few milisecond delay after i reset. The sensor I use is panasonic cx-421 and is capable of much higher frequencies than I use. I call this read_sensor function in my void_loop every 50ms using millis function . I will try to inspect the code more tommorow see if I can find any obvious problems.
 
Last edited:

Thread Starter

zazas321

Joined Nov 29, 2015
936
I found a strange thing. I use a 12V external DC power supply to supply power to my sensor. I also have a DC-DC buckboost converter module that I use to stepdown this voltage to 5V for my arduino. When no load connected, I notice that the output of DC DC converter is 5V. When connected to a circuit , it drops to 4.8V. When driving 20 neopixels, it further drops to 4.1V
 

Thread Starter

zazas321

Joined Nov 29, 2015
936
Okay I have found an issue but have no clue how to fix it. I also use my ESP32 to connect to my home network. If I comment out the code which has the wifi functionality, the LEDS behave properly. If I enable the wifi back again, the leds starts doing crazy things again. I have read few other forum threads about the exact same issue such as:
https://esp32.com/viewtopic.php?t=3980
but cannot find solution
 

BobTPH

Joined Jun 5, 2013
8,813
Did you disable interrupts when writing to the strip? This is essential, if your WiFi code is using interrupts, it will mess up the data stream yo the strip.

Bob
 

Thread Starter

zazas321

Joined Nov 29, 2015
936
Did you disable interrupts when writing to the strip? This is essential, if your WiFi code is using interrupts, it will mess up the data stream yo the strip.

Bob
I havent. That is the problem but from the research I have done, disabling WIFI interrupt will generate more problems and generally not advised. Still doing research trying to find a proper solution
 

djsfantasi

Joined Apr 11, 2010
9,156
I found a strange thing. I use a 12V external DC power supply to supply power to my sensor. I also have a DC-DC buckboost converter module that I use to stepdown this voltage to 5V for my arduino. When no load connected, I notice that the output of DC DC converter is 5V. When connected to a circuit , it drops to 4.8V. When driving 20 neopixels, it further drops to 4.1V
What model of Arduino are you using? Most can be supplied with up to 12V supply. Thus, you don’t need a DC to DC converter. Thus the loaded voltage won’t drop. Supply 12V to the Arduino and the on board regulator will convert that to the 5V that the Arduino uses. I can be more specific if you tell me the specific Arduino model.
 
Top