Itsy Bitsy 32u4. - Onboard Red LED Flashing, no code workin

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
cc_top
 
Posts: 3
Joined: Sun Mar 06, 2022 8:56 am

Itsy Bitsy 32u4. - Onboard Red LED Flashing, no code workin

Post by cc_top »

Hi everybody, I'm a total noob and just started.

I'm having a little problem with my Itsy Bitsy 32u4 with 5V. I am using two reed switches to make a Jewel light up in two different colours.

When I power it with the USB port, everything works fine. But when I use a powerbank, every now and then the onboard red LED flashes for around 10 seconds. In that time, the reed switches don't react, which is very annoying.

That problem doesn't occur when the Jewel is turned on.

Can someone point me out to why it does that and how to fix it? I don't think it's a problem with the code (as it works without trouble when powered via PC) but I'm putting it here anyway :)

Unfortunately I have one these two power sources available atm.

The powerbank can provide [email protected] and 1.2A but it doesn't make a difference where I plug it in. I also used both the USB power output as well as 5V out on the ItsyBitsy to power the Jewel but that doesn't change anything either.

I uploaded a video which should show the problem better: https://youtu.be/ahiSKK00P9g

Thanks a lot!

Code: Select all

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
 #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif

// Digital IO pin connected to the button. This will be driven with a
// pull-up resistor so the switch pulls the pin to ground momentarily.
// On a high -> low transition the button press logic will execute.
#define BUTTON_PIN1   10
#define BUTTON_PIN2   11
#define PIXEL_PIN    5  // Digital IO pin connected to the NeoPixels.

#define PIXEL_COUNT 7  // Number of NeoPixels

// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)

boolean oldState1 = HIGH;
boolean oldState2 = HIGH;
int     mode     = 0;    // Currently-active animation mode, 0-9

void setup() {
  pinMode(BUTTON_PIN1, INPUT_PULLUP);
  strip.begin(); // Initialize NeoPixel strip object (REQUIRED)
  strip.show();  // Initialize all pixels to 'off'
  pinMode(BUTTON_PIN2, INPUT_PULLUP);
  strip.begin(); // Initialize NeoPixel strip object (REQUIRED)
  strip.show();  // Initialize all pixels to 'off'
}
// Linear interpolation of y value given min/max x, min/max y, and x position.
float lerp(float x, float x0, float x1, float y0, float y1)
{
  // Clamp x within x0 and x1 bounds.
  x = x > x1 ? x1 : x;
  x = x < x0 ? x0 : x;
  // Calculate linear interpolation of y value.
  return y0 + (y1-y0)*((x-x0)/(x1-x0));
}

// Set all pixels to the specified color.
void fill_pixels(Adafruit_NeoPixel& pixels, uint32_t color)
{
  for (int i=0; i < pixels.numPixels(); ++i) {
    pixels.setPixelColor(i, color);
  }
  strip.show();
}

// Get the color of a pixel within a smooth gradient of two colors.
uint32_t color_gradient(uint8_t start_r, // Starting R,G,B color
                        uint8_t start_g,
                        uint8_t start_b, 
                        uint8_t end_r,   // Ending R,G,B color
                        uint8_t end_g,
                        uint8_t end_b,
                        float pos)       // Position along gradient, should be a value 0 to 1.0
{
  // Interpolate R,G,B values and return them as a color.  
  uint8_t red   = (uint8_t) lerp(pos, 0.0, 1.0, start_r, end_r);
  uint8_t green = (uint8_t) lerp(pos, 0.0, 1.0, start_g, end_g);
  uint8_t blue  = (uint8_t) lerp(pos, 0.0, 1.0, start_b, end_b);
  return Adafruit_NeoPixel::Color(red, green, blue);
}

void animate_gradient_fill(Adafruit_NeoPixel& pixels, // NeoPixel strip/loop/etc.
                           uint8_t start_r,           // Starting R,G,B color
                           uint8_t start_g,
                           uint8_t start_b, 
                           uint8_t end_r,             // Ending R,G,B color
                           uint8_t end_g,
                           uint8_t end_b,
                           int duration_ms)           // Total duration of animation, in milliseconds
{
  unsigned long start = millis();
  // Display start color.
  fill_pixels(pixels, Adafruit_NeoPixel::Color(start_r, start_g, start_b));
  // Main animation loop.
  unsigned long delta = millis() - start;
  while (delta < duration_ms) {
    // Calculate how far along we are in the duration as a position 0...1.0
    float pos = (float)delta / (float)duration_ms;
    // Get the gradient color and fill all the pixels with it.
    uint32_t color = color_gradient(start_r, start_g, start_b, end_r, end_g, end_b, pos);
    fill_pixels(pixels, color);
    // Update delta and repeat.
    delta = millis() - start;
  }
  // Display end color.
  fill_pixels(pixels, Adafruit_NeoPixel::Color(end_r, end_g, end_b));
}
void loop() {
  // Get current button state.
  boolean newState1 = digitalRead(BUTTON_PIN1);
  boolean newState2 = digitalRead(BUTTON_PIN2);

  // Check if state changed from high to low (button press).
  if((newState1 == LOW) && (oldState1 == HIGH)) {
    // Short delay to debounce button.
    delay(20);
    // Check if button is still low after debounce.
    newState1 = digitalRead(BUTTON_PIN1);
    if(newState1 == LOW) {      // Yes, still low
      if(++mode > 1) mode = 0; // Advance to next mode, wrap around after #8
      switch(mode) {           // Start the new animation...
        case 0:
            animate_gradient_fill(strip,         
                      255, 0, 0,
                      0, 0, 0,
                      500);
          break;
        case 1:
            animate_gradient_fill(strip,         
                      0, 0, 0,
                      255, 0, 0,
                      500);
          break;
          }
    }
  }

  // Set the last-read button state to the old state.
  oldState1 = newState1;

  // Check if state changed from high to low (button press).
  if((newState2 == LOW) && (oldState2 == HIGH)) {
    // Short delay to debounce button.
    delay(20);
    // Check if button is still low after debounce.
    newState2 = digitalRead(BUTTON_PIN2);
    if(newState2 == LOW) {      // Yes, still low
      if(++mode > 1) mode = 0; // Advance to next mode, wrap around after #8
      switch(mode) {           // Start the new animation...
       case 0:
            animate_gradient_fill(strip,         
                      0, 255, 0,
                      0, 0, 0,
                      500);
          break;
        case 1:
            animate_gradient_fill(strip,         
                      0, 0, 0,
                      0, 255, 0,
                      500);
          break;
          }
    }
  }

  // Set the last-read button state to the old state.
  oldState2 = newState2;
}
Last edited by cc_top on Sun Mar 06, 2022 9:42 am, edited 2 times in total.

User avatar
rubble
 
Posts: 29
Joined: Fri Mar 14, 2014 5:46 am

Re: Itsy Bitsy 32u4. - Onboard Red LED Flashing, no code wo

Post by rubble »

I think I have the same problem as you and posted a couple of days ago: viewtopic.php?f=62&t=189083

I have a feeling the Itsy bitsy is trying to contact a computer for some reason. I am using CircuitPython.

User avatar
cc_top
 
Posts: 3
Joined: Sun Mar 06, 2022 8:56 am

Re: Itsy Bitsy 32u4. - Onboard Red LED Flashing, no code wo

Post by cc_top »

Ok, interesting. I plugged the USB cable into a power adapter now that has a 1A 5V output. This works fine too. But why won't it work with the powerbank? Would it work with a different one, maybe with less capacity?

User avatar
alpierce
 
Posts: 208
Joined: Mon May 13, 2013 2:44 am

Re: Itsy Bitsy 32u4. - Onboard Red LED Flashing, no code wo

Post by alpierce »

Many power banks require a certain amount of current to be drawn from them in order to keep the output active. They are meant for powering/charging phones or tablets that draw a fair amount of current. That is why it works if you have leds connected , but not when it is only the microcontroller.
If it is charging a phone or tablet, when the charging circuit in the device detects it is fully charged it stops drawing current from the power bank, and the power bank shuts off. There are many articles on the internet about how to fool them into working with low power devices. It’s usually simpler to just use a battery, with a boost converter if needed. The battery is not “smart” enough to cause problems.

User avatar
cc_top
 
Posts: 3
Joined: Sun Mar 06, 2022 8:56 am

Re: Itsy Bitsy 32u4. - Onboard Red LED Flashing, no code wo

Post by cc_top »

Thank you, that sounds plausible! It doesn't explain why it works for every 20 seconds and it doesn't for the next 10 seconds but knowing it wouldn't change anything :D
I received my lipo battery today so I'll see if powering it from a battery works (which it should).

Locked
Please be positive and constructive with your questions and comments.

Return to “Itsy Bitsy Boards”