Gemma startup time

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
LXF
 
Posts: 20
Joined: Wed Jan 14, 2015 12:07 pm

Re: Gemma startup time

Post by LXF »

Thanks for the quick answer.
I have only one push button on Pin D2
This one should wake ot up and it works now after having changed the code I copied from the Space Invader project
from
PCMSK |= _BV(PCINT1);
to
PCMSK |= _BV(PCINT2);

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Gemma startup time

Post by adafruit_support_mike »

Ah.. that would be a matter of telling the chip to watch for an interrupt on pin 2 rather than pin 1.

Did that get the overall system working the way you want it to?

User avatar
LXF
 
Posts: 20
Joined: Wed Jan 14, 2015 12:07 pm

Re: Gemma startup time

Post by LXF »

Yes, at least I had it on Battery over night and it came up with the LEDs still bright.
Without that the system would have been dead the next morning.
I'm still not back home so that I cannot measure the currrent beeing drawn.
I want to figure out what these chips on the Neopixel strip are consuming.
Though a big step forward.

Questions:
Is that Gemma when put asleep as shown in the Space Invader project at his absolute minimum in terms of power consumption?
Or could I switch even more things off?
Is voltage projection still active or would it slightly ruin the battery?
I wonder if I could shut down the Neopixel chips by disabling the 5V output?

Thought I should paste the working code here so that others may benefit

Code: Select all


//A sketch to drive a Neopicel strip as Larsson scanner with the ability to 
//change the color of the scanner and a sleep mode after it is switched off
//Referencing the Larsson scanner code and the sleep code from the space Invader project

#include <Adafruit_NeoPixel.h>
#include <avr/power.h>
#include <avr/sleep.h>
 
#define N_LEDS 25
#define PIN 1
 
long lastDebounceTime = 0;   // the last time the output pin was toggled
long debounceDelay = 100;     // the debounce time; increase if the output flickers
int buttonState;             // the current reading from the input pin
int lastButtonState = LOW;   // the previous reading from the input pin
int buttonPin = 2;           // the pin where the pushbutton is attached
long idletime = 0;           // will use this with the timer to enable sleep
        

Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN, NEO_GRB + NEO_KHZ800);

uint32_t Red = strip.Color(255, 0, 0);
uint32_t Green = strip.Color(0, 255, 0);
uint32_t Yellow = strip.Color(255, 255, 0);
uint32_t Blue = strip.Color(0, 0, 255);
 
void setup() {
  strip.begin();
  pinMode(buttonPin, INPUT_PULLUP); //Define Pin 2 as Input and set the internal pullup
  clear_all(); //Take care that the strip is switched off when Battery connected
  
power_timer1_disable();    // Disable unused peripherals
power_adc_disable();       // to save power
PCMSK |= _BV(PCINT2);      // Set change mask for pin 1
}

bool laser_once = true; //flag to ensure that the Laser2 function is left immediately after it was visited once
int pos = 0, dir = 1;   // Position, direction of "eye"

// this enum is used to store the different states
enum sLaser {
  STOP = 0,
  CHOOSERED,
  CHOOSEGREEN,
  CHOOSEBLUE,
  CHOOSEYELLOW,
  HEADLIGHT,
  NB_STATES
};

int state = STOP; // Start with a switched off strip after start

void loop() {
     int reading = digitalRead(buttonPin);   // read the state of the switch into a local variable:
     if (reading != lastButtonState) {
       lastDebounceTime = millis();
     } 
     if ((millis() - lastDebounceTime) > debounceDelay) {
       if (reading != buttonState) {
         buttonState = reading;
         if (buttonState == LOW) {
           state += 1;
           if (state >= NB_STATES)
           state = STOP;
         }
       }
     }
     switch (state)
     {
       case CHOOSERED:
       Laser1(Red);
       break;
       case CHOOSEGREEN:
       Laser1(Green);
       break;
       case CHOOSEBLUE:
       Laser1(Blue);
       break;
       case CHOOSEYELLOW:
       Laser1(Yellow);
       break;
       case HEADLIGHT:
       Headlight();
       break;
       case STOP:
       default:
       laser_once = true;
       clear_all();
     }     
     switch (state)          // seperate to query the time nothing happened when LEDS are switched off
     {
     case STOP:
     if (millis() - idletime > 2000)
     goSleep();              // start sleep function
     break;
     default:
     idletime = millis();    // reset timer
     }
     delay(10);
     lastButtonState = reading;
   }

void Laser1(uint32_t LEDColor)
{
  int j;
  strip.setPixelColor(pos-2, setBrightness(LEDColor,20));
  strip.setPixelColor(pos-1, setBrightness(LEDColor,70));
  strip.setPixelColor(pos , setBrightness(LEDColor,255)); // Center pixel is brightest
  strip.setPixelColor(pos+1, setBrightness(LEDColor,70));
  strip.setPixelColor(pos+2, setBrightness(LEDColor,20));
  strip.show();
  delay(50);
  for(j=-2; j<= 2; j++) strip.setPixelColor(pos+j, 0);   //Deleting all pixels
  // Bounce off ends of strip
  pos += dir;
  if(pos < 0) {
    pos = 1;
    dir = -dir;
  } else if(pos >= strip.numPixels()) {
    pos = strip.numPixels() - 2;
    dir = -dir;
  }
}


void Headlight(){           //function toswitch on some LEDs in the middle of the strip as a headlight

  if (laser_once == false)    //check if this funcion was visited before and if
    return;                   //leave
  laser_once = false;         //if not go on and set the visited flag
  clear_all();                //clear the strip
  int center = N_LEDS/2;     // Calculate the center of the strip (assumed that you have even LEDs)
  for (int i=0; i<3;i++)      // And set the number of LEDs to brightest white
  {
  strip.setPixelColor(center+i, 0xFFFFFF); 
  strip.setPixelColor(center-i, 0xFFFFFF); 
  }
  strip.show();
}

void clear_all(){           //helper function to clear the strip
  int j=0;
  for(j=0; j<N_LEDS; j++) strip.setPixelColor(j, 0);
    strip.show();
}

uint32_t setBrightness (uint32_t LEDColor,uint8_t Brightness){ //Helper function to adjust brightness of a single Pixel

  uint8_t
      r = (uint8_t)(LEDColor >> 16),
      g = (uint8_t)(LEDColor >>  8),
      b = (uint8_t)LEDColor;
  
      r = (r * Brightness) >> 8;
      g = (g * Brightness) >> 8;
      b = (b * Brightness) >> 8;
  uint32_t result = ((uint32_t)r << 16) | ((uint32_t)g <<  8) | b;
  return result;
}

void goSleep(){

GIMSK = _BV(PCIE);     // Enable pin change interrupt
power_all_disable();   // All peripherals off
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sei();                 // Keep interrupts disabled
sleep_mode();          // Power down CPU (pin 1 will wake)
// Execution resumes here on wake.
GIMSK = 0;             // Disable pin change interrupt
power_timer0_enable(); // Re-enable timer
power_usi_enable();    // Re-enable USI
idletime = millis();  //need to reset the timer, otherwise it will immeadeatly go beack to sleep again
}
ISR(PCINT0_vect) {}

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Gemma startup time

Post by adafruit_support_mike »

LXF wrote:Is that Gemma when put asleep as shown in the Space Invader project at his absolute minimum in terms of power consumption?
These two lines shut off all the peripherals that are available:

Code: Select all

  power_timer1_disable();    // Disable unused peripherals
  power_adc_disable();       // to save power
LXF wrote:Is voltage projection still active or would it slightly ruin the battery?
The voltage regulator will still be active, but shutting it off would force the Gemma to restart completely.
LXF wrote:I wonder if I could shut down the Neopixel chips by disabling the 5V output?
That would work, yes. You might get a random flash when you reconnect power though. You'll have to try it and see.

User avatar
LXF
 
Posts: 20
Joined: Wed Jan 14, 2015 12:07 pm

Re: Gemma startup time

Post by LXF »

I did a few measurements and the power consumption is like that:

5 LEDS in bright white = 112 mAh (goes well with the 20 mAh per Pixel on bright whithe and the 12mAh for the board)
Scanner running =30 mAH (sounds also good since not all lights are bright and even colored)
No lights on = 12 mAh (this seems to be the normal power consumption of the Gemma)
Sleep mode drops down to 6.8 mAh with 5 Pixels attached.
I detached the 5 Pixel strip and ended with 3.1 mAh
I did the same test with a 25 Pixel strip and I got a sleep consumption of 20.1 mAH! So it seems that this is not at al negligible at all. Each pixel adds a lot of current draw to the system.


How could I disable this strip?


Thanks again for all your help

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Gemma startup time

Post by adafruit_support_mike »

You'd need a free IO pin to control something like a transistor. Do you have any to spare?

User avatar
LXF
 
Posts: 20
Joined: Wed Jan 14, 2015 12:07 pm

Re: Gemma startup time

Post by LXF »

You mean IO pin or transistor? :-)
Actually both.
But I am really noob at electronics and I will have to ask someone else how this transistor should be dimensioned.
Or did you guys have this question already answered?
Actually it would help a lot of people with the wearable stuff.
Since I have Pin 0 free:
Should I use the internal pull-up to have that one not floating?
Is that a NPN or PNP transistor then?
Sorry for this dumb question.

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Gemma startup time

Post by adafruit_support_mike »

You can use either a PNP or an NPN. You just need one that can handle the amount of current your system will need.

In this case, a PN2222 on the LED strip's GND connection should work:
npn.jpg
npn.jpg (14.9 KiB) Viewed 635 times

User avatar
LXF
 
Posts: 20
Joined: Wed Jan 14, 2015 12:07 pm

Re: Gemma startup time

Post by LXF »

Thanks for the drawing.
I think this will work.
Just need some time to do it, I will post the result.
Great support guys.

User avatar
LXF
 
Posts: 20
Joined: Wed Jan 14, 2015 12:07 pm

Re: Gemma startup time

Post by LXF »

Found some time to get back to that project.
It did not do the Job - and guess what:
The whole setup works (though with some wrong colors) if I remove ground completely from the strip.
Seems like some current runs over the signal line ???

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Gemma startup time

Post by adafruit_support_mike »

If current is flowing through the signal line, you have a major problem. An Arduino pin can't handle enough current to run even a single NeoPixel, let along a strip of them.

Post a photo showing your hardware and connections and we'll take a look. 800x600 images usually work best.

User avatar
LXF
 
Posts: 20
Joined: Wed Jan 14, 2015 12:07 pm

Re: Gemma startup time

Post by LXF »

Here you go.
Datei 10.03.16, 10 32 34.jpeg
Datei 10.03.16, 10 32 34.jpeg (417.31 KiB) Viewed 468 times
I soldered a JR plug to the Gemma. so with that setup I can do my tests.
Ground from the strip goes to ground od the Power Pin.
The Push button on Digital 2 switches my strip, The yellow wire should later drive the Transistor to switch off the ground to save power

Look at this video:
https://youtu.be/Ne6POnTrc-o
I do not get it. This strip should not be lit at all when I remove the ground

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Gemma startup time

Post by adafruit_support_mike »

That is wierd.

The LEDs are dimmer when you remove the GND connection, so apparently you're getting a parasitic connection to GND through the DI line.

That's technically possible. Dave Jones over at the EEVBlog did a video showing the effect a couple months ago: https://www.youtube.com/watch?v=2yFh7Vv0Paw

The key pieces of the puzzle would be an input protection diode on the NeoPixel's DI pin, the Gemma's GPIO pin being LOW between updates, and the debounce capacitors on the NeoPixel strip holding enough power for the LED drivers to keep running during an update.

If the Gemma's GPIO pin is low between updates, it will sit about 3.3v lower than the VCC line. The NeoPixel strip is connected to both VCC and the GPIO pin, so it will see that 3.3v difference. If the NeoPixel has an input protection diode between its DI pin and GND, the cathode of that diode will be connected to the Gemma's GPIO pin, and will be about 3.3v lower than the VCC rail. The voltage across the diode will be about 0.7v, putting the strip's GND rail about 2.7v lower than the VCC rail.

Apparently that's enough headroom for the LED drivers in the NeoPixels to operate.

That kind of connection should fail when the Gemma's GPIO pin sends data to the NeoPixel. As soon as the GPIO pin goes high, there isn't enough voltage difference between the pin and the VCC rail for the LED drivers to work any more.

The strip has debounce capacitors though, and those will charge to the difference between the VCC and GND rails while the GPIO pin is low. When the GPIO pin goes high, the debounce caps act like tiny, short-lived batteries that keep the LED drivers running. The GPIO pin's high pulses will be short, and the LED drivers probably don't use much current when handling the input signal, so it's possible for the capacitors to keep the LED drivers running during an update.

You could test the theory by setting the Gemma's pin high between updates, but I wouldn't advise it. If my theory is right, running the strip that way risks killing the DI pin on the first pixel, and without that the whole strip will stop responding to input.

User avatar
LXF
 
Posts: 20
Joined: Wed Jan 14, 2015 12:07 pm

Re: Gemma startup time

Post by LXF »

Wow, that's a very detailed explanation.
I will try to understand this but I need to solve my original issue - the power save mode.
With my original setup there I have 25 Neopixels and they consume much more then this circuit with 5.
What if I switch the positive part with a Transistor?
Any recommendation for such a solution?

If I manually detach the cable I end up with 3.1 mA in sleep mode, 6.4 with this setup, my original is much higher as written above.
Is 3.1 mA the absolute minimum for the Gemma with the onboard LED still working?

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Gemma startup time

Post by adafruit_support_mike »

Yeah, you should be able to switch the VCC line with a PNP transistor. The circuit would be pretty much the same as the one above, but with the transistor's emitter and the 10k resistor connected to VCC instead of GND.

For 25 NeoPixels, you'll probably want a PNP transistor that can handle an amp of current or more. I happen to use the SS8550, which can do up to 1.5A:
https://www.digikey.com/product-detail/ ... ND/1047357

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

Return to “Other Arduino products from Adafruit”