Leonardo used in commerical applications hanging up

Our company (anonymous, sorry) uses an Arduino Leonardo in commercial application. Its been used for a good 4-5 years without problems with hundred of units shipped each year.
POLOLU2128 POLOLU.COM ITEM NO: 3101 A-Star 32U4 Micro

Its a very simple program of maybe 50 lines of code (not including libraries). The basic function of the microcontroller is 2 fold. The first function is that we read a polulu VL53L0X Time-of-Flight Distance Sensor and then when the computer requests a measurement, we report it back. The second function is that we send color codes to a LED timing strip which is model: BTF-LIGHTING WS2811 and these functions allow it to blink and shut off. Im not sure hy the previous engineer picked these devices but I think its is because they came with Arduino libraries for easy integration.

What is odd is that Im not sure what has initiated the events as the firmware has not changed, nor have the PCBs. or any of the hardware. that we are aware of.

We are having an issue that started on 3 systems in the last 2 weeks of which 3 were yesterday. Im a little worried now that it seems to be happening more than 1 time. In each case is that notice the LEDs on our systems shut off. The LEDs are controlled by the contact side of relay k7. Overall this entire Leonardo electrical system is isolated as there is a relay involved, opening and closing the relay contacts pass outside of the circuit but its isolated. There is also a ground goes out of the schematic but even this should not be needed but shouldn’t hurt.
image

When the issue seems to happen, the technicians are reporting this occurs around every hour that the LEDs seem to shut off. However, what is odd is that when i go to trouble shoot it, it seems that it never occurs but I think that I am inducing this effect while trouble shooting and possible reprogramming rather than it being just luck.

Im not 100% sure of what the issue is. However, it appears the firmware is corrupted when trouble shooting The reason I believe this is that if I open up the Arduino IDE and reprogram the microcontroller, it will start to work again. However, in 2 of the cases, we had to replace the height sensor but also had to reprogram the Leonardo in all 3.

In the latter case today, I connected the serial monitor to the device and it would hang up if a command M was sent (no reprogramming used).. However, after it was reprogrammed, I could resend the serial commands from the IDE and get an appropiate responce.

What is also weird is that in 2 of the 3 cases, it seemed like the USB driver for the Leonardo was corrupt as it produced an error in device manager that prevented it from showing up as a comm port. Image below.

So there are 3 main things Im looking at there and again, nothing has changed 4-5 years but we are seeing somehow

  1. height sensors somehow failing (2 cases)
  2. USB driver drops out for Leonardo (2 cases)
  3. Leonardo requires reprogramming and it just starts to work again (at least for a few days)

Any help is appreciated, even if its just where to start debugging

For some reason, the system is not letting me upload the code or simple schematic image.

this is the error we got on 2 of the systems whne the polulu height snesor was attached. It causes the leonardo to drop out

image

this is the main body of the code
The libararies are not attached, they come from the vendor for the LED strip and height sensor
I cant attach them as i am new user

/*

    1. VOICE COMMAND LIGHT CONTROL
    1. DETECTION PROGRAM
  • LAST MODIFIED: 05/13/2019
    */
    #include <Wire.h>
    #include "VL53L0X.h"
    #include "FastLED.h"

/Voice light settings START/
#define BRIGHTNESS 250
#define NUM_LEDS 4
#define PWM_PIN 6
#define DATA_PIN 5
/Voice light settings END/

/Commands START/
#define OPEN 'O' /Open Voice Recognition/
#define CLOSE 'C' /Close Voice Recognition/
#define BLINK 'B' /Blink Voice Light/
#define MEASURE 'M' /(TOF sensor) distance measurement/
/Commands END/

#define HIGH_ACCURACY /High accuracy distance measurement/

VL53L0X sensor; //TOF sensor

bool g_active = false; //VCC indicator
const int CNT = 300; //30 seconds (timer, no-command timeout) hardware timer changed to 5 minutes for demo purposes
const int THOUSAND = 990; //990ms~1 second
int cnt = 1; //counter
int sec = 0; //second(s)

CRGB leds[NUM_LEDS]; //leds LUT

void setup()
{
Serial.begin(9600);
Wire.begin();

sensor.init();
sensor.setTimeout(500);

FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
FastLED.setBrightness( BRIGHTNESS );
pinMode(PWM_PIN,OUTPUT);
digitalWrite(PWM_PIN, LOW);

//End VCC initially
EndVCC();

#if defined LONG_RANGE
// lower the return signal rate limit (default is 0.25 MCPS)
sensor.setSignalRateLimit(0.1);
// increase laser pulse periods (defaults are 14 and 10 PCLKs)
sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18);
sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14);
#endif

#if defined HIGH_SPEED
// reduce timing budget to 20 ms (default is about 33 ms)
sensor.setMeasurementTimingBudget(20000);
#elif defined HIGH_ACCURACY
// increase timing budget to 200 ms
sensor.setMeasurementTimingBudget(200000);
#endif
}

void loop()
{
//check timer
if (g_active)
{
cnt++;
delay(1);
if (!(cnt % THOUSAND))
{
sec++;

        //VCC timeout, no command recieved
        if (sec == CNT)
        {
            cnt = 0;
            sec = 0;
            g_active = false;
            EndVCC();
        }
    }
}

//dispatching PC commands
if(Serial.available())
{
  char cmd = Serial.read();
  switch (cmd)
  {
    case MEASURE:
    {
      Measure();
      break;
    }
    case OPEN:
    {
      StartVCC();
      break;
    }
    case BLINK:
    {
      BlinkVCC();
      break;
    }
    case CLOSE:
    {
      EndVCC();
      break;
    }
  }
}

}

//Measure distance (mm)
void Measure()
{
int x = sensor.readRangeSingleMillimeters();
char buf[12];
sprintf(buf, "*%010d#", x);
Serial.print(buf);
}

//start VCC
void StartVCC()
{
cnt = 0;
sec = 0;
g_active = true;

//turn on VCC light
digitalWrite(PWM_PIN, HIGH);
leds[0] = CRGB(255,0,0);// b r g
leds[1] = CRGB(255,0,0);
leds[2] = CRGB(255,0,0); 
leds[3] = CRGB(255,0,0); 
FastLED.show();
Serial.print(OPEN);
return;

}

//blink VCC
void BlinkVCC()
{
//renew timeout counter
cnt = 0;
sec = 0;
g_active = true;
Serial.print(BLINK);
digitalWrite(PWM_PIN, HIGH);
leds[0] = CRGB(255,0,0);
FastLED.show();
delay(90);
leds[0] = CRGB(0,0,0);
delay(50);
leds[1] = CRGB(255,0,0);
FastLED.show();
delay(90);
leds[1] = CRGB(0,0,0);
delay(50);
leds[2] = CRGB(255,0,0);
FastLED.show();
delay(90);
leds[2] = CRGB(0,0,0);
delay(50);
leds[3] = CRGB(255,0,0);
FastLED.show();
delay(90);
leds[3] = CRGB(0,0,0);
delay(30);
leds[2] = CRGB(255,0,0);
FastLED.show();
delay(90);
leds[2] = CRGB(0,0,0);
delay(50);
leds[1] = CRGB(255,0,0);
FastLED.show();
delay(90);
leds[1] = CRGB(0,0,0);
delay(50);
leds[0] = CRGB(255,0,0);
FastLED.show();
delay(90);
leds[0] = CRGB(0,0,0);
delay(50);
leds[0] = CRGB(255,0,0);
leds[1] = CRGB(255,0,0);
leds[2] = CRGB(255,0,0);
leds[3] = CRGB(255,0,0);
FastLED.show();
return;
}

//end VCC
void EndVCC()
{
int cnt = 0;
int sec = 0;
g_active = false;
Serial.print(CLOSE);
digitalWrite(PWM_PIN, LOW);
leds[0] = CRGB(0,0,0);
leds[1] = CRGB(0,0,0);
leds[2] = CRGB(0,0,0);
leds[3] = CRGB(0,0,0);
FastLED.show();
}

Can you post more schematic diagram information?

Also, you say the Leonardo is isolated, from where comes its operating supply voltage?

Has anything changed in other parts of the system or the circumstances of its deployment? Like a new microwave oven in the cafeteria?

a7

Please edit your post and place the code inside code tags so it doesn't get all scrambled like it did. Do us a big favour and also auto-format the code with ctrl-T in the IDE before you re-post it.

Check the size of the buffer that you use with sprintf; e.g. in Meause() (but possibly not limited to it)

  char buf[12];
  sprintf(buf, "*%010d#", x);

10 digits plus '*' plus '#' plus '\0' does not fit in 12 bytes. You're probably corrupting the functionality that takes care of the USB communication.

If you use the USB port, you're advised to use while(!Serial) after Serial.begin() unless your system must be able to start up with a terminal program connected.

If you have a connection with a terminal program established and pull out the USB cable, your 32U4 code can hang when trying to print; this applies of your setup has to work stand-alone (with an external power supply).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.