[GUIDE] Battery icon indicator guide with MCP3008

Various user-contributed guides for hardware-related things
activex
Posts: 36
Joined: Mon Oct 31, 2016 5:19 am
Has thanked: 10 times
Been thanked: 24 times

Re: [GUIDE] Battery icon indicator guide with MCP3008

Post by activex » Sun Apr 16, 2017 4:39 am

jostie94 wrote:
Sun Apr 16, 2017 4:33 am
The battery connects directly to the MCP3008 and directly to the power boost?

Image
That is correct

Barbosik
Posts: 13
Joined: Wed Jul 20, 2016 1:02 pm
Has thanked: 3 times
Been thanked: 2 times

Re: [GUIDE] Battery icon indicator guide with MCP3008

Post by Barbosik » Mon Apr 17, 2017 9:48 am

jostie94 wrote:
Sun Apr 16, 2017 4:33 am
The battery connects directly to the MCP3008 and directly to the power boost?

Image
That's what i have been looking for.

Thanks

Cyborg_delta1
Posts: 48
Joined: Fri Sep 30, 2016 12:17 am
Has thanked: 11 times
Been thanked: 6 times

Re: [GUIDE] Battery icon indicator guide with MCP3008

Post by Cyborg_delta1 » Sun Apr 23, 2017 9:23 pm

Voltage calculator website is down :(

krevett
Posts: 2
Joined: Wed Jun 07, 2017 12:55 am

Re: [GUIDE] Battery icon indicator guide with MCP3008

Post by krevett » Wed Jun 07, 2017 1:20 am

Hello everyone.

I'm interested into this battery indicator for a personal project with a raspberry pi3 (but not a game console).
I'm looking at wiring everything, following this picture :
Image

I've got 2 questions :
1/ On this picture, we can see a grey wire connected to #21 on pi gpio, but going nowhere. Do you have an explanation ?

2/ Your white wire is going to CS0 pin, but I can't find it on this GPIO chart ? Does-it correspond to SPI_CE0_N (gpio 8/pin24) ?
Image

Regards !

User avatar
jostie94
Posts: 51
Joined: Sat Apr 01, 2017 3:34 am
Location: the netherlands
Has thanked: 5 times
Been thanked: 28 times

Re: [GUIDE] Battery icon indicator guide with MCP3008

Post by jostie94 » Wed Jun 07, 2017 6:49 am

I do not get any ouput of the battery meter.

Code: Select all

pi@retropie:~/gbzbatterymonitor $ python main.py
Batteries 100% voltage:         4.1
Batteries 75% voltage:          3.76
Batteries 50% voltage:          3.63
Batteries 25% voltage:          3.5
Batteries dangerous voltage:    3.2
ADC 100% value:                 937.441786284
ADC 75% value:                  859.702711324
ADC 50% value:                  829.978947368
ADC 25% value:                  800.255183413
ADC dangerous voltage value:    731.661881978
loadpng: can't open file for reading
unable to load /home/pi/gbzbattery/icons/blank.png
pngview: ../common/imageLayer.c:80: createResourceImageLayer: Assertion `result == 0' failed.
ADC value: 0 (0.0 V)
ADC value: 0 (0.0 V)
ADC value: 0 (0.0 V)
^Cpngview: no process found
my GBZ builds:
1) http://www.sudomod.com/forum/viewtopic.php?f=9&t=3197
------------------------------------------------------------------------------------------

User avatar
muniosi
Posts: 100
Joined: Sun Jan 08, 2017 10:21 pm
Has thanked: 156 times
Been thanked: 31 times

Re: [GUIDE] Battery icon indicator guide with MCP3008

Post by muniosi » Fri Jun 09, 2017 6:50 pm

This looks awesome! Does the battery indicator always show, even on top of games? Or is it only shown on the menu? If the latter, is there a way to configure a button combination to display the indicator so I can check how much battery I have left without exiting the game?

In any case, great work. This looks hella rad.
I've just finished my milk.

activex
Posts: 36
Joined: Mon Oct 31, 2016 5:19 am
Has thanked: 10 times
Been thanked: 24 times

Re: [GUIDE] Battery icon indicator guide with MCP3008

Post by activex » Sat Jun 10, 2017 2:05 am

krevett wrote:
Wed Jun 07, 2017 1:20 am
1/ On this picture, we can see a grey wire connected to #21 on pi gpio, but going nowhere. Do you have an explanation?
Just an editing error, its not supposed to be there in the first place ;)
krevett wrote:
Wed Jun 07, 2017 1:20 am
2/ Your white wire is going to CS0 pin, but I can't find it on this GPIO chart ? Does-it correspond to SPI_CE0_N (gpio 8/pin24) ?
I don't have a RPi3, so cant answer that, but try googling RPI 3 SPI.

activex
Posts: 36
Joined: Mon Oct 31, 2016 5:19 am
Has thanked: 10 times
Been thanked: 24 times

Re: [GUIDE] Battery icon indicator guide with MCP3008

Post by activex » Sat Jun 10, 2017 2:05 am

muniosi wrote:
Fri Jun 09, 2017 6:50 pm
This looks awesome! Does the battery indicator always show, even on top of games? Or is it only shown on the menu? If the latter, is there a way to configure a button combination to display the indicator so I can check how much battery I have left without exiting the game?

In any case, great work. This looks hella rad.
Always on top, even on games :D

activex
Posts: 36
Joined: Mon Oct 31, 2016 5:19 am
Has thanked: 10 times
Been thanked: 24 times

Re: [GUIDE] Battery icon indicator guide with MCP3008

Post by activex » Sat Jun 10, 2017 2:07 am

jostie94 wrote:
Wed Jun 07, 2017 6:49 am
I do not get any ouput of the battery meter.

Code: Select all

pi@retropie:~/gbzbatterymonitor $ python main.py
Batteries 100% voltage:         4.1
Batteries 75% voltage:          3.76
Batteries 50% voltage:          3.63
Batteries 25% voltage:          3.5
Batteries dangerous voltage:    3.2
ADC 100% value:                 937.441786284
ADC 75% value:                  859.702711324
ADC 50% value:                  829.978947368
ADC 25% value:                  800.255183413
ADC dangerous voltage value:    731.661881978
loadpng: can't open file for reading
unable to load /home/pi/gbzbattery/icons/blank.png
pngview: ../common/imageLayer.c:80: createResourceImageLayer: Assertion `result == 0' failed.
ADC value: 0 (0.0 V)
ADC value: 0 (0.0 V)
ADC value: 0 (0.0 V)
^Cpngview: no process found
Have you entered the right pin numbers in the config file? Is the mcp connected properly? Is pngview installed?

User avatar
jostie94
Posts: 51
Joined: Sat Apr 01, 2017 3:34 am
Location: the netherlands
Has thanked: 5 times
Been thanked: 28 times

Re: [GUIDE] Battery icon indicator guide with MCP3008

Post by jostie94 » Mon Jun 12, 2017 4:02 pm

i checked wiring and re installed the battery monitor.
there is a output now:
python main.py outputShow
pi@retropie:~/gbzbatterymonitor $ python main.py
/home/pi/gbzbatterymonitor/mcp3008.py:78: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(SPIMOSI, GPIO.OUT)
/home/pi/gbzbatterymonitor/mcp3008.py:80: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(SPICLK, GPIO.OUT)
/home/pi/gbzbatterymonitor/mcp3008.py:81: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(SPICS, GPIO.OUT)
Batteries 100% voltage: 4.1
Batteries 75% voltage: 3.76
Batteries 50% voltage: 3.63
Batteries 25% voltage: 3.5
Batteries dangerous voltage: 3.2
ADC 100% value: 937.441786284
ADC 75% value: 859.702711324
ADC 50% value: 829.978947368
ADC 25% value: 800.255183413
ADC dangerous voltage value: 731.661881978
ADC value: 314 (1.37331194196 V)
ADC value: 314 (1.37331194196 V)
ADC value: 314 (1.37331194196 V)

^Cpngview: no process found
my config.py fileShow
"""
" Edit below this line to fit your needs
"""
# Path to pngview (raspidmx) and icons
PNGVIEWPATH = "/home/pi/raspidmx/pngview"
ICONPATH = "/home/pi/gbzbatterymonitor/icons"

# Battery icon, LED or videoclips? Or all of them?
LEDS = 0
ICON = 1
CLIPS = 1

# GPIO (BOARD numbering scheme) pin for good voltage LED
GOODVOLTPIN = 18
LOWVOLTPIN = 17

# Fully charged voltage, voltage at the percentage steps and shutdown voltage. This is where you edit when finetuning the batterymonitor
# by using the monitor.py script.
VOLT100 = 4.1
VOLT75 = 3.76
VOLT50 = 3.63
VOLT25 = 3.5
VOLT0 = 3.2

# Value (in ohms) of the lower resistor from the voltage divider, connected to the ground line (1 if no voltage divider).
# Default value (2000) is for a lipo battery, stepped down to about 3.2V max.
LOWRESVAL = 2000

# Value (in ohms) of the higher resistor from the voltage divider, connected to the positive line (0 if no voltage divider).
# Default value (5600) is for a lipo battery, stepped down to about 3.2V max.
HIGHRESVAL = 5600

# ADC voltage reference (3.3V for Raspberry Pi)
ADCVREF = 3.3

# MCP3008 channel to use (from 0 to 7)
ADCCHANNEL = 0

# Refresh rate (s)
REFRESH_RATE = 2

# Display some debug values when set to 1, and nothing when set to 0
DEBUGMSG = 1

# Voltage value measured by the MCP3008 when batteries are fully charged. It should be near 3.3V due to Raspberry Pi GPIO compatibility)
# Be careful to edit below this line.
SVOLT100 = (VOLT100)*(HIGHRESVAL)/(LOWRESVAL+HIGHRESVAL)
SVOLT75 = (VOLT75)*(HIGHRESVAL)/(LOWRESVAL+HIGHRESVAL)
SVOLT50 = (VOLT50)*(HIGHRESVAL)/(LOWRESVAL+HIGHRESVAL)
SVOLT25 = (VOLT25)*(HIGHRESVAL)/(LOWRESVAL+HIGHRESVAL)
SVOLT0 = (VOLT0)*(HIGHRESVAL)/(LOWRESVAL+HIGHRESVAL)

# MCP3008 scaling
ADC100 = SVOLT100 / (ADCVREF / 1024.0)
ADC75 = SVOLT75 / (ADCVREF / 1024.0)
ADC50 = SVOLT50 / (ADCVREF / 1024.0)
ADC25 = SVOLT25 / (ADCVREF / 1024.0)
ADC0 = SVOLT0 / (ADCVREF / 1024.0)

i can't get the pngview working...
Last edited by jostie94 on Wed Jun 14, 2017 3:19 pm, edited 1 time in total.
my GBZ builds:
1) http://www.sudomod.com/forum/viewtopic.php?f=9&t=3197
------------------------------------------------------------------------------------------

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest