ODROID C0 Battery Measurments

Moderators: mdrjr, odroid

ODROID C0 Battery Measurments

Unread postby Mzahana » Sat Apr 28, 2018 4:10 pm

Hi.

I am using this battery (http://www.hardkernel.com/main/products ... 5353298878) to power ODROID C0. Is there a way to get the battery level on ODROID?
Mzahana
 
Posts: 36
Joined: Mon Dec 15, 2014 3:08 am
languages_spoken: English, Arabic
ODROIDs: Odroid U3, C0, XU4

Re: ODROID C0 Battery Measurments

Unread postby odroid » Sat Apr 28, 2018 4:24 pm

User avatar
odroid
Site Admin
 
Posts: 28741
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID

Re: ODROID C0 Battery Measurments

Unread postby Mzahana » Tue May 01, 2018 5:24 am

Thank you. Can I get this value in a Python script?
Mzahana
 
Posts: 36
Joined: Mon Dec 15, 2014 3:08 am
languages_spoken: English, Arabic
ODROIDs: Odroid U3, C0, XU4

Re: ODROID C0 Battery Measurments

Unread postby odroid » Tue May 01, 2018 8:18 am

Yes, Python can access "sysfs" nodes.
Search google with "Python sysfs".
User avatar
odroid
Site Admin
 
Posts: 28741
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID

Re: ODROID C0 Battery Measurments

Unread postby Mzahana » Tue May 01, 2018 5:33 pm

So, I wrote the following commands in a file as mentioned on the above link:
Code: Select all
#!/bin/sh
#
# Read Battery Voltage on ODROID-C0
#
 
ADCRES=0.004106
ADCVAL=$(cat /sys/class/saradc/saradc_ch0)
BATTVOL=$(echo $ADCRES*$ADCVAL | bc)
echo Battery voltage is $BATTVOL V


And I get the following error after executing it,

Code: Select all
bc: not found


What is the problem here?
Mzahana
 
Posts: 36
Joined: Mon Dec 15, 2014 3:08 am
languages_spoken: English, Arabic
ODROIDs: Odroid U3, C0, XU4

Re: ODROID C0 Battery Measurments

Unread postby Mzahana » Tue May 01, 2018 5:40 pm

It worked after I installed 'bc'

Code: Select all
sudo apt-get install bc
Mzahana
 
Posts: 36
Joined: Mon Dec 15, 2014 3:08 am
languages_spoken: English, Arabic
ODROIDs: Odroid U3, C0, XU4

Re: ODROID C0 Battery Measurments

Unread postby Mzahana » Tue May 01, 2018 7:44 pm

Here is a sample Python code I used to get the battery measurements.

Code: Select all
 #!/usr/bin/env python

import subprocess

sp = subprocess.Popen(['cat','/sys/class/saradc/saradc_ch0'],
    stdout=subprocess.PIPE)

output = sp.stdout.read()
output=output.strip('\n')
output = float(output)

# voltage levels
ADCRES=0.004106

BATFULL = 4.2
BATLOW = 3.65
DELTA = 1.0/(BATFULL-BATLOW)

BATVOLT = ADCRES*output

percent = DELTA*(BATVOLT-BATLOW)*100.
print percent
Mzahana
 
Posts: 36
Joined: Mon Dec 15, 2014 3:08 am
languages_spoken: English, Arabic
ODROIDs: Odroid U3, C0, XU4

Re: ODROID C0 Battery Measurments

Unread postby rooted » Wed May 02, 2018 6:41 am

Thanks for sharing your method.
User avatar
rooted
 
Posts: 5610
Joined: Fri Dec 19, 2014 9:12 am
Location: Gulf of Mexico, US
languages_spoken: english
ODROIDs: C1, C1+, C2
XU3 Lite, XU4
N1
VU7+
HiFi Shield 2
Smart Power (original)


Return to Hardware and peripherals

Who is online

Users browsing this forum: No registered users and 2 guests