GithubHelp home page GithubHelp logo

edisonvoltage's Introduction

###Disclaimer This code is a proof-of-concept, very little effort has been put in to ensuring it is bug free.

Reading VBAT on the Edison

It is possible to read the Lipo battery voltage on an Intel Edison without using the Yocto battery_voltage. This method of reading battery voltage works on devices running Ubilinux.

There is a system device, bcove_adc, that is connected to various voltage and temperature input lines. These can be read using /sys/devices/platform/bcove_adc/basincove_gpadc.

  • /sys/devices/platform/bcove_adc/basincove_gpadc/channel reads a bitmask of channels to report. Channel 0 is the battery voltage.
  • /sys/devices/platform/bcove_adc/basincove_gpadc/sample triggers an ADC conversion to take place.
  • /sys/devices/platform/bcove_adc/basincove_gpadc/result contains the result of the ADC conversion. It is an integer between 0 and 1023. A result of 1023 is roughly equivalent to 4.5v.
$ echo 0x1 | sudo tee /sys/devices/platform/bcove_adc/basincove_gpadc/channel
1
$ echo 1 | sudo tee /sys/devices/platform/bcove_adc/basincove_gpadc/sample
1
$ cat /sys/devices/platform/bcove_adc/basincove_gpadc/result
sample_result[0] = 980
sample_result[1] = 0
sample_result[2] = 0
sample_result[3] = 0
sample_result[4] = 0
sample_result[5] = 0
sample_result[6] = 0
sample_result[7] = 0
sample_result[8] = 0

In this case, the result is 980. 980 is about 96% of 1023, so the voltage is about 96% of 4.5v. This is 4.3v. In this case, the battery is connected to the charger, so this value is to be expected.

There are two different methods of reading voltage provided. One, voltage.c, requires root access (must be run with sudo). Build it with make voltage. voltage.c takes 1 argument when run, a number. The number dictates the output format.

  • ./voltage text or ./voltage : Full text output
  • ./voltage csv CSV output
  • ./voltage short produces results in the format 100% 4300mV
  • ./voltage percentage reports only the battery percentage
  • ./voltage json gives JSON output of the voltage and percentage.

The other method, voltage_server.c, is a service which watches for accesses to files much like sysfs. These files are set up to be accessable by all users, so once the server process has started, no further root access is required. To start the server, run :

make voltage_server
sudo ./voltage_server &

The interface for this method is located in /tmp. To trigger an ADC read, write 1 to /tmp/battery_trigger

$ echo 1 > /tmp/battery_trigger

After some length of time (0.1 seconds is sufficient), the results are available in 3 files:

  1. /tmp/battery_voltage contains the voltage in mV
  2. /tmp/battery_percentage contains the battery percentage.
  3. /tmp/battery_raw contains the average of 5 ADC readings.

The python script, report_voltages.py, gives an example of how to use this interface.

Running sudo make install will install voltage_server as a service and start automatically when the edison starts. This is thoroughly untested.

For OpenAPS users that want to log voltage to nightscout, I use the following two files: https://gist.github.com/cjo20/42ce5227cc1412513448da17f5f1ab84

Percentage

Percentages generated by this tool are calibrated to hit 0% at 2.95v. 100% is 4.18v. At 0% the edison will shut down completely. Wireless communications will usually cut out before this (around 3.2v).

The voltage/percentage relationship is not linear, as there is a large plateau in battery voltage as capacity is used up. I hope to improve this given some more data.

edisonvoltage's People

Contributors

cjo20 avatar

Watchers

James Cloos avatar John Benjamin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.