Low battery indicator

Discussion about other hardware (including other Pi-like boards)
User avatar
winnetouch
Posts: 158
Joined: Mon Jul 11, 2016 10:56 am
Has thanked: 2 times
Been thanked: 30 times

Low battery indicator

Post by winnetouch » Tue Nov 08, 2016 1:25 pm

I'm using this type of power boost (adafruit is a bit expensive and the postage to Slovenia even more so :P).
http://www.ebay.com/itm/272084267044?_t ... EBIDX%3AIT

It has no LED indicator that he battery is running low. I tried some solutions, including helders low battery indicator that I made myself looking at his PCB but i probably messed something up since it never worked correctly. I was wonderring though... Is it possible it doesn't work because I'm using a battery with a built-in protection circuit? So basically the battery shuts down even before helders solution has a chance of alarming me the battery is low? I'm just speculating.

If that is not the case is there any other solution? I think i need to take the battery safety circuit in to consideration though.

User avatar
sotasystems
Posts: 160
Joined: Sun Oct 09, 2016 4:56 am
Location: Germany, 127.0.0.1
Has thanked: 95 times
Been thanked: 93 times
Contact:

Re: Low battery indicator

Post by sotasystems » Tue Nov 08, 2016 4:19 pm

winnetouch wrote:I'm using this type of power boost (adafruit is a bit expensive and the postage to Slovenia even more so :P).
http://www.ebay.com/itm/272084267044?_t ... EBIDX%3AIT

It has no LED indicator that he battery is running low. I tried some solutions, including helders low battery indicator that I made myself looking at his PCB but i probably messed something up since it never worked correctly. I was wonderring though... Is it possible it doesn't work because I'm using a battery with a built-in protection circuit? So basically the battery shuts down even before helders solution has a chance of alarming me the battery is low? I'm just speculating.

If that is not the case is there any other solution? I think i need to take the battery safety circuit in to consideration though.
I am using a low battery indicator I made myself from an arduino in my build. If you want, you can check out my original guide on how I did it. If you want, I can also help you out and make a dedicated guide.
Ladies and gentlemen, I would like to inform you that I am currently moving very far away, and therefore I am very busy.

UPDATE: I am still alive! My ISP is setting up my internet on the 19th of January at my new place, explaining my offline-ness.

If you write me a PM, I will very likely take some time to respond.

Also, my 2nd build will soon go on, so if you've been following it, please stay tuned! :)

Many thanks for your understanding!

User avatar
Camble
Posts: 885
Joined: Thu May 05, 2016 2:31 am
Location: Scotland
Has thanked: 269 times
Been thanked: 488 times

Re: Low battery indicator

Post by Camble » Wed Nov 09, 2016 4:17 am

You have a few options when it comes to battery monitoring.

@Helder's Low Battery LED Indicator Board can be bought from OSHPark and will illuminate an LED when the battery gets low. You will need to buy the components and assemble this yourself.

You can use a comparator to detect a particular voltage, like my Safe Shutdown Board uses. An LM393 chip has two comparators so can be used to detect two separate voltage levels.

You can also purchase an analog to digital converter for the Raspberry Pi's GPIO pins and build your own solution. I think this is what @kite uses in his Super-AIO board. Adafruit have a couple of ADCs here. The MCP3008 uses SPI where the ADS1015 is an I²C device.

Also, as @sotasystems has mentioned, you can use an Arduino. So if you're using a Teensy for your button inputs, you can tack on additional battery level monitoring functionality to that.

I'm also working on a battery monitor using an ATTiny85 development board. This will be able to actively monitor the voltage, rather than alert at a certain level. Check out the thread here.

User avatar
winnetouch
Posts: 158
Joined: Mon Jul 11, 2016 10:56 am
Has thanked: 2 times
Been thanked: 30 times

Re: Low battery indicator

Post by winnetouch » Wed Nov 09, 2016 2:29 pm

sotasystems wrote:I am using a low battery indicator I made myself from an arduino in my build. If you want, you can check out my original guide on how I did it. If you want, I can also help you out and make a dedicated guide.
I'll be honest I'm not that knowledgable about electronics. I'm learning as I go, and It's kind of hard to follow the build process so I would really appreciate it if you could help me with a dedicated guide. I am using an arduino clone (spark fun pro micro) but I do have an arduino uno on loan from a friend to maybe program any IC.

User avatar
sotasystems
Posts: 160
Joined: Sun Oct 09, 2016 4:56 am
Location: Germany, 127.0.0.1
Has thanked: 95 times
Been thanked: 93 times
Contact:

Re: Low battery indicator

Post by sotasystems » Wed Nov 09, 2016 5:54 pm

winnetouch wrote:
sotasystems wrote:I am using a low battery indicator I made myself from an arduino in my build. If you want, you can check out my original guide on how I did it. If you want, I can also help you out and make a dedicated guide.
I'll be honest I'm not that knowledgable about electronics. I'm learning as I go, and It's kind of hard to follow the build process so I would really appreciate it if you could help me with a dedicated guide. I am using an arduino clone (spark fun pro micro) but I do have an arduino uno on loan from a friend to maybe program any IC.
As you are using a sparkfun pro micro (which I also did in my build), there are several options for you to realize this:

- Use the sparkfun pro micro as your gaming controller and at the same time monitor the battery with it and do stuff on battery states when it's supposed to.

- Use an arduino uno seperately which does nothing else but battery monitoring and stuff that should happen on certain battery states.

The reason I did not use my sparkfun controller to do exactly that, is because my sparkfun pro micro uses ALL available I/O's it has. (14 buttons and 2 analog sticks, so I am literaly using all 18 input pins).

If you want to replicate what I have build, there are a few things I would like to know, though:

- Do you use your analog pins on your sparkfun controller, or are they free?
- Do you have any I/O's free on it? If yes, how many?
- Do you have an adjustable lab bench power supply or access to one? (Would make things quite a bit easier, but is not a requirement)
- Do you have an multimeter handy?
Ladies and gentlemen, I would like to inform you that I am currently moving very far away, and therefore I am very busy.

UPDATE: I am still alive! My ISP is setting up my internet on the 19th of January at my new place, explaining my offline-ness.

If you write me a PM, I will very likely take some time to respond.

Also, my 2nd build will soon go on, so if you've been following it, please stay tuned! :)

Many thanks for your understanding!

User avatar
winnetouch
Posts: 158
Joined: Mon Jul 11, 2016 10:56 am
Has thanked: 2 times
Been thanked: 30 times

Re: Low battery indicator

Post by winnetouch » Wed Nov 09, 2016 11:35 pm

Ok, here goes :P

1. I have 3 of the 4 analogue pins free.

2. I'm using pins 0-10 and I believe pin A0 or A1 (I don't know exactly the circuit is at my folks house).

3. I do not have a bench power supply.

4. I do not have a multimeter handy but I could probably borrow one somewhere.

I also have one or two spare arduino micro's handy, an arduino nano (got them after the fact) and another sparfun pro micro somewhere in the mail.

User avatar
sotasystems
Posts: 160
Joined: Sun Oct 09, 2016 4:56 am
Location: Germany, 127.0.0.1
Has thanked: 95 times
Been thanked: 93 times
Contact:

Re: Low battery indicator

Post by sotasystems » Thu Nov 10, 2016 12:20 am

winnetouch wrote:Ok, here goes :P

1. I have 3 of the 4 analogue pins free.

2. I'm using pins 0-10 and I believe pin A0 or A1 (I don't know exactly the circuit is at my folks house).

3. I do not have a bench power supply.

4. I do not have a multimeter handy but I could probably borrow one somewhere.

I also have one or two spare arduino micro's handy, an arduino nano (got them after the fact) and another sparfun pro micro somewhere in the mail.
Okay, great, thank you. :)
You can actualy use your leonardo to do the battery monitoring and indication.

The arduino I have put in my GameBoy has the following features:
[THIS ONLY APPLIES TO MY PARTICULAR BATTERY, BUT WITH SOME TWEAKING, IT CAN ALSO WORK WITH YOURS!]
- It will detect when the battery is at 3.54 Volts, that means the battery is LOW. When the battery is low, an red LED will come on.
- About 10-15 minutes later, the battery will be at 3.20 Volts. This is the "critical point" and my arduino will then send a signal to the raspberry pi via GPIO to safe-shutdown it
- When a charger is plugged in, all shutdown actions will be surpressed

Without a lab bench power supply though, it will take quite a bit longer depending on the battery's mAh you use.
You will also need two resistors to form a so called "voltage divider". Let me explain what it does:

In this case, the voltage divider simply breaks down let's say a maximum voltage from 4-5 volts to 2.56 volts.
Since your leonardo has an internal voltage reference of 2.56 volts, we don't want to give it voltages above that, because otherwise we won't be able to read them.

Could you tell us what battery you are using (chemistry [LiPo, LiOn, NiMH, etc.] , voltage, capacity in mAh, maybe brand, or simply a link to it)?

After that, I can calculate the resistor values, make a hook up plan you need to see how to connect things up, and then explain what you need to do to get your baseline voltage readings for further use.
Ladies and gentlemen, I would like to inform you that I am currently moving very far away, and therefore I am very busy.

UPDATE: I am still alive! My ISP is setting up my internet on the 19th of January at my new place, explaining my offline-ness.

If you write me a PM, I will very likely take some time to respond.

Also, my 2nd build will soon go on, so if you've been following it, please stay tuned! :)

Many thanks for your understanding!

User avatar
winnetouch
Posts: 158
Joined: Mon Jul 11, 2016 10:56 am
Has thanked: 2 times
Been thanked: 30 times

Re: Low battery indicator

Post by winnetouch » Thu Nov 10, 2016 2:46 am

This is the battery that I am using:

http://www.ebay.com/itm/221988155540?_t ... EBIDX%3AIT

I rigged it so I can unplug it but that just means I connected a small plastic connector to it.

User avatar
sotasystems
Posts: 160
Joined: Sun Oct 09, 2016 4:56 am
Location: Germany, 127.0.0.1
Has thanked: 95 times
Been thanked: 93 times
Contact:

Re: Low battery indicator

Post by sotasystems » Fri Nov 11, 2016 5:09 pm

Okay, you will need two additional resistors for battery measurement with 100kΩ each.

You have to solder your circuit like that:

Image

First, you have to add this before your "void setup()" line:

Code: Select all

int BatFlag[3] = {0,0,0};
int BatLow = 0;
Then you have to add this into your "void setup()" line in your sketch:

Code: Select all

  analogReference(INTERNAL);
  pinMode(A1, INPUT);
  pinMode(15, OUTPUT);
  digitalWrite(15, LOW);
  Serial.begin(9600);
And finaly, this right into your "void loop()" line:

Code: Select all

  if (analogRead(A1) <= BatLow) {
    BatFlag[0] = 1;
  }
  else {
    BatFlag[0] = 0;
  }
  if (BatFlag[0] == 1) {
    digitalWrite(15, LOW);
  }
  else {
    digitalWrite(15, HIGH);
  }
  Serial.println(analogRead(A1));
  delay(500);
The sketch you just made is to light up an LED at a certain voltage (which we don't have yet) and to get your baseline readings.

To get the baseline readings, you do the following:

Charge your battery up until it is completely full and then read the voltage with a multimeter AND your leonardo at the same time. Then turn your gameboy on. Then open the Arduino Serial monitor on your computer, and note the approx. value you get there and the voltage you read with the multimeter. Now either play a game or just let a game run on your gameboy to make use of the battery and note the approximate readings you get from the serial monitor and the multimeter like every 10 minutes until the battery is depleted, but don't go below 3.20 Volt. Please also write the exact time! If you don't even get to 3.20 Volt, please tell at which voltage it started to cut off. If you have all your readings, please report back.
Ladies and gentlemen, I would like to inform you that I am currently moving very far away, and therefore I am very busy.

UPDATE: I am still alive! My ISP is setting up my internet on the 19th of January at my new place, explaining my offline-ness.

If you write me a PM, I will very likely take some time to respond.

Also, my 2nd build will soon go on, so if you've been following it, please stay tuned! :)

Many thanks for your understanding!

User avatar
winnetouch
Posts: 158
Joined: Mon Jul 11, 2016 10:56 am
Has thanked: 2 times
Been thanked: 30 times

Re: Low battery indicator

Post by winnetouch » Fri Nov 18, 2016 12:54 pm

Hy. Sorry for the late reply. I wanted to get that multimeter before doing anything.

I wired everything up as in the diagram but I'm in a bit of a pickle. I'm using this script for the controller.

Code: Select all

#include <Keyboard.h>

#define BUTTONS 20

int keycode_arr[] =
{
  216,  // LEFT
  218,  // RIGHT
    217,  // DOWN
  215,  // UP
  46,  // .
  32,  // +

  118,  // 'v'
  119,   // 'w'
  120,  // 'x'
  121,   // 'y'

  97,  // 'a'
  117,  // not in use
  117,   // not in use
  117,  // not in use

  98,  // 'b'
  117,  // not in use

  117,  // not in use

  117,  // not in use

  117,  // not in use
  117   // not in use
};

int key_state[BUTTONS];

void setup()
{
  PRR1 = PRR1 |
         (
           (1 << PRTIM2) |
           (1 << PRTIM3) |
           (1 << PRUSART1)
         );
  PRR0 = PRR0 |
         (
           (1 << PRTWI) |
           (1 << PRSPI) |
           (1 << PRTIM1) |
           (1 << PRADC)
         );

  DDRB = DDRB & ~
         (
           (1 << DDB1) |
           (1 << DDB2) |
           (1 << DDB3) |
           (1 << DDB4) |
           (1 << DDB5) |
           (1 << DDB6) |
           (1 << DDB7)
         );

  PORTB = PORTB |
          (
            (1 << PB1) |
            (1 << PB2) |
            (1 << PB3) |
            (1 << PB4) |
            (1 << PB5) |
            (1 << PB6) |
            (1 << PB7)
          );

  DDRC = DDRC & ~
         (
           (1 << DDC6) |
           (1 << DDC7)
         );
  PORTC = PORTC |
          (
            (1 << PC6) |
            (1 << PC7)
          );

  DDRD = DDRD & ~
         (
           (1 << DDD0) |
           (1 << DDD1) |
           (1 << DDD2) |
           (1 << DDD3) |
           (1 << DDD4) |
           (1 << DDD6) |
           (1 << DDD7)
         );
  PORTD = PORTD |
          (
            (1 << PD0) |
            (1 << PD1) |
            (1 << PD2) |
            (1 << PD3) |
            (1 << PD4) |
            (1 << PD6) |
            (1 << PD7)
          );

  DDRE = DDRE & ~ (1 << DDE6);
  PORTE = PORTE | (1 << PE6);

  DDRF = DDRF & ~
         (
           (1 << DDF0) |
           (1 << DDF1) |
           (1 << DDF4) |
           (1 << DDF5) |
           (1 << DDF6) |
           (1 << DDF7)
         );
  PORTF = PORTF |
          (
            (1 << PF0) |
            (1 << PF1) |
            (1 << PF4) |
            (1 << PF5) |
            (1 << PF6) |
            (1 << PF7)
          );

  Keyboard.begin();
  //Serial.begin(115200);
}

void loop()
{
  int port_b;
  int port_c;
  int port_d;
  int port_e;
  int port_f;

  port_b = PINB;
  port_c = PINC;
  port_d = PIND;
  port_e = PINE;
  port_f = PINF;

  key_state[0] = ((port_d & (1 << PD2)) == 0); // PIN0
  key_state[1] = ((port_d & (1 << PD3)) == 0); // PIN1
  key_state[2] = ((port_d & (1 << PD1)) == 0); // PIN2
  key_state[3] = ((port_d & (1 << PD0)) == 0); // PIN3
  key_state[4] = ((port_d & (1 << PD4)) == 0); // PIN4
  key_state[5] = ((port_c & (1 << PC6)) == 0); // PIN5
  key_state[6] = ((port_d & (1 << PD7)) == 0); // PIN6
  key_state[7] = ((port_e & (1 << PE6)) == 0); // PIN7
  key_state[8] = ((port_b & (1 << PB4)) == 0); // PIN8
  key_state[9] = ((port_b & (1 << PB5)) == 0); // PIN9
  key_state[10] = ((port_b & (1 << PB6)) == 0); // PIN10
  key_state[11] = ((port_b & (1 << PB7)) == 0); // PIN11
  key_state[12] = ((port_d & (1 << PD6)) == 0); // PIN12
  key_state[13] = ((port_c & (1 << PC7)) == 0); // PIN13
  key_state[14] = ((port_f & (1 << PF7)) == 0); // A0
  key_state[15] = ((port_f & (1 << PF6)) == 0); // A1
  key_state[16] = ((port_f & (1 << PF5)) == 0); // A2
  key_state[17] = ((port_f & (1 << PF4)) == 0); // A3
  key_state[18] = ((port_f & (1 << PF1)) == 0); // A4
  key_state[19] = ((port_f & (1 << PF0)) == 0); // A5

  //Serial.println(key_state[6]);

  for (int i = 0; i < BUTTONS; i++)
  {
    if (key_state[i] == 1)
    {
      //Serial.println(keycode_arr[i]);
      Keyboard.press(keycode_arr[i]);
    }
    else
    {
      Keyboard.release(keycode_arr[i]);
    }
  }
}
The reason there are multiple buttons marked as "not in use" is because I had no idea how to remove these specific buttons from the code. I just took a code myPiZero wrote up for me that included all the sparkfun pro pins (I didn't know how to add them on my own and he just added all of them). The thing is as far as I'm aware pin A0 and 15 are assigned to do something in this code. I have no idea how to remove that so I can enter the code that you wrote up for me.

As far as I understand myPiZeros code the order the buttons are in determines witch pin is witch button (in keycode_arr). If I remove any of the unused keycodes it just messes up the buttons and pins. I have no idea how to remove specific pins from the code.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest