@lburelli thanks for bearing with me, okay so it seems like it's my sketch causing it, once it gets installed and running, messes up any subsequent uploads.
Using the following blink example...
https://docs.arduino.cc/built-in-examples/basics/Blink
PC has been rebooted since plugging in anything Arduino related.
First upload fails, not in bootloader mode, and my sketch is running on it.
Download [ ] 0% 0 bytesdfu-util: Error during download get_status (LIBUSB_ERROR_PIPE)
Failed uploading: uploading error: exit status 74
Going into bootloader mode, works...
Download [ ] 0% 0 bytes
Download [= ] 4% 12288 bytes
Download [== ] 8% 24576 bytes
Download [=== ] 12% 36864 bytes
Download [==== ] 16% 49152 bytes
Download [===== ] 21% 61440 bytes
Download [====== ] 25% 73728 bytes
Download [======= ] 28% 81920 bytes
Download [======== ] 32% 94208 bytes
Download [========= ] 36% 106496 bytes
Download [========== ] 40% 118784 bytes
Download [=========== ] 45% 131072 bytes
Download [=========== ] 46% 135168 bytes
Download [============ ] 49% 143360 bytes
Download [============= ] 52% 151552 bytes
Download [============== ] 56% 163840 bytes
Download [=============== ] 60% 176128 bytes
Download [================ ] 64% 188416 bytes
Download [================= ] 69% 200704 bytes
Download [================== ] 73% 212992 bytes
Download [=================== ] 76% 221184 bytes
Download [==================== ] 80% 233472 bytes
Download [===================== ] 84% 245760 bytes
Download [====================== ] 88% 258048 bytes
Download [======================= ] 93% 270336 bytes
Download [======================== ] 97% 282624 bytes
Download [=========================] 100% 286192 bytes
Download done.
DFU state(7) = dfuMANIFEST, status(0) = No error condition is present
DFU state(2) = dfuIDLE, status(0) = No error condition is present
Done!
Yellow onboard LED blinks.
Touching nothing and just trying another upload straight away, works, woohoo.
Several repeated uploads all upload fine.
Switching back to my sketch, first one uploads okay (as the blink is installed on it), but then subsequent ones fail.
Trying to upload the blink again (but with my sketch running)...
Download [ ] 0% 0 bytes
Download [ ] 2% 8192 bytes
Download [= ] 4% 12288 bytes
Download [== ] 8% 24576 bytes
Download [=== ] 12% 36864 bytes
Download [==== ] 16% 49152 bytes
Download [===== ] 21% 61440 bytesdfu-util: Error during download get_status (LIBUSB_ERROR_PIPE)
Failed uploading: uploading error: exit status 74
Going back to bootloader, blink uploads fine.
Then all subsequent ones work fine.
So now it's down to debugging my code, and most importantly figuring out the WHY.
The code controls 4 separate LED strips, showing various flame effects.
I have 2 pots to control brightness and which effect/palette to display, plus an LED to light if the brightness would result in more than 3A being pulled from the power supply.
I'll include the full sketch, with some commented out tests, etc.
Any advice welcome...
#include <Arduino.h>
#include <FastLED.h>
#include <math.h>
#define NUM_LEDS 51
#define COOLING 50
#define SPARKING 60
#define FPS 30 // 60 is ideal
#define ARM_1_PIN 2
#define ARM_2_PIN 3
#define ARM_3_PIN 4
#define ARM_4_PIN 5
#define VOLT_LIMIT 5
#define MILLIAMP_LIMIT 3000
#define AMP_LIMIT_LED_PIN 7
#define MIN_BRIGHTNESS 10
#define MAX_BRIGHTNESS 255
#define BRIGHTNESS_PIN A4
#define PALETTE_PIN A2
#define NUM_AVERAGE_SAMPLES 30
byte heat[ 4 ][ NUM_LEDS ] = { 0 };
CRGB leds[ 4 ][ NUM_LEDS ] = { 0 };
void setup()
{
delay( 2000 ); // power-up safety delay
FastLED.addLeds<WS2812B, ARM_1_PIN, GRB>( leds[ 0 ], NUM_LEDS );
FastLED.addLeds<WS2812B, ARM_2_PIN, GRB>( leds[ 1 ], NUM_LEDS );
FastLED.addLeds<WS2812B, ARM_3_PIN, GRB>( leds[ 2 ], NUM_LEDS );
FastLED.addLeds<WS2812B, ARM_4_PIN, GRB>( leds[ 3 ], NUM_LEDS );
pinMode( AMP_LIMIT_LED_PIN, OUTPUT ); // just in case it's not set
set_max_power_indicator_LED( AMP_LIMIT_LED_PIN );
FastLED.setMaxPowerInVoltsAndMilliamps( VOLT_LIMIT, MILLIAMP_LIMIT );
FastLED.setBrightness( MAX_BRIGHTNESS );
Serial.begin( 115200 );
if ( 0 )
{
all_white( leds[ 0 ] );
all_white( leds[ 1 ] );
all_white( leds[ 2 ] );
all_white( leds[ 3 ] );
FastLED.show();
}
}
CRGBPalette16 palettes[] = {
HeatColors_p,
RainbowColors_p,
CloudColors_p,
ForestColors_p,
OceanColors_p
};
void loop()
{
EVERY_N_MILLISECONDS( 1000 / FPS ){
// update the brightness
FastLED.setBrightness( _get_normalised_brightness_value() );
for ( int i = 0; i < 4; i++ )
{
fire( leds[ i ], heat[ i ] );
// knight_rider( leds[ i ] );
// all_white( leds[ 0 ] );
// all_white( leds[ 1 ] );
// all_white( leds[ 2 ] );
// all_white( leds[ 3 ] );
}
FastLED.show();
}
}
int _get_normalised_brightness_value()
{
int brightness_pin_value = analogRead( BRIGHTNESS_PIN );
int brightness_value = map(
brightness_pin_value,
0, 1023,
MIN_BRIGHTNESS, MAX_BRIGHTNESS
);
return brightness_value;
}
void fire( CRGB leds[], byte heat[] )
{
// cool down every cell a little
for ( int i = 0; i < NUM_LEDS; i++ )
{
heat[ i ] = qsub8( heat[ i ], random8( 0, ( ( COOLING * 10 ) / NUM_LEDS ) + 2 ) );
}
// heat from each cell drifts 'up' and diffuses a little
for ( int i = NUM_LEDS - 1; i >= 2; i-- )
{
heat[ i ] = ( heat[ i - 1 ] + heat[ i - 2 ] + heat[ i - 2 ] ) / 3;
}
// randomly ignite new 'sparks' of heat near the bottom
if ( random8() < SPARKING )
{
int y = random8( 7 );
heat[ y ] = qadd8( heat[ y ], random8( 160, 255 ) );
}
// map from heat cells to LED colors
CRGBPalette16 palette = HeatColors_p; // default
int num_palettes = sizeof( palettes ) / sizeof( CRGBPalette16 );
// map the analogue input (0-1023) to an index in our array of palettes
int analogue_value = analogRead( PALETTE_PIN );
int averaged_analogue_value = _averageAnalogueRead( PALETTE_PIN );
int mapped_value = map(
averaged_analogue_value,
0, 1023,
0, num_palettes - 1
);
char serial_out[255];
sprintf( serial_out, "Total palettes %d, analogue pin %d, averaged analogue value %d, mapped %d", num_palettes, analogue_value, averaged_analogue_value, mapped_value );
// Serial.println( serial_out );
palette = palettes[ mapped_value ];
for ( int i = 0; i < NUM_LEDS; i++ )
{
// Scale the heat value from 0-255 down to 0-240
// for best results with color palettes.
byte colorindex = scale8( heat[ i ], 240 );
CRGB color = ColorFromPalette( palette, colorindex );
leds[ i ] = color;
}
}
int _averageAnalogueRead( int pin )
{
static int values[ NUM_AVERAGE_SAMPLES ] = { 0 };
static int last_element = -1;
last_element ++;
if ( last_element == NUM_AVERAGE_SAMPLES )
{
last_element = 0;
}
int value = analogRead( pin );
values[ last_element ] = value;
int average = 0;
for ( int i = 0; i < NUM_AVERAGE_SAMPLES; i++ )
{
average += values[ i ];
}
return average / NUM_AVERAGE_SAMPLES;
}
void all_white( CRGB leds[] )
{
fill_solid( leds, NUM_LEDS, CRGB::White );
}
void knight_rider( CRGB leds[] )
{
uint8_t sinBeat = beatsin8( 120, 0, NUM_LEDS - 1, 0, 0 );
leds[ sinBeat ] = CRGB::Red;
fadeToBlackBy(leds, NUM_LEDS, 10);
}
I'd love to know what could be causing this behaviour.