ODROID C0 Battery Measurments

Post Reply
Mzahana
Posts: 36
Joined: Mon Dec 15, 2014 3:08 am
languages_spoken: English, Arabic
ODROIDs: Odroid U3, C0, XU4
Contact:

ODROID C0 Battery Measurments

Unread post by 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?

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

Re: ODROID C0 Battery Measurments

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


Mzahana
Posts: 36
Joined: Mon Dec 15, 2014 3:08 am
languages_spoken: English, Arabic
ODROIDs: Odroid U3, C0, XU4
Contact:

Re: ODROID C0 Battery Measurments

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

Thank you. Can I get this value in a Python script?

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

Re: ODROID C0 Battery Measurments

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

Yes, Python can access "sysfs" nodes.
Search google with "Python sysfs".

Mzahana
Posts: 36
Joined: Mon Dec 15, 2014 3:08 am
languages_spoken: English, Arabic
ODROIDs: Odroid U3, C0, XU4
Contact:

Re: ODROID C0 Battery Measurments

Unread post by 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
Contact:

Re: ODROID C0 Battery Measurments

Unread post by 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
Contact:

Re: ODROID C0 Battery Measurments

Unread post by 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

User avatar
rooted
Posts: 6256
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Contact:

Re: ODROID C0 Battery Measurments

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

Thanks for sharing your method.

Post Reply

Return to “Hardware and peripherals”

Who is online

Users browsing this forum: No registered users and 1 guest