Getting power and battery info from AXP209

Here is a script that gives some info about battery (when one is plugged)

I think that this page has mistakes (http://linux-sunxi.org/AXP209#Spec_Sheets) because discharging and charging current are inverted.

#!/bin/sh
# This program gets the battery info from PMU
# Voltage and current charging/discharging
#
# Nota : temperature can be more than real because of self heating
#######################################################################
# Copyright (c) 2014 by RzBo, Bellesserre, France
#
# Permission is granted to use the source code within this
# file in whole or in part for any use, personal or commercial,
# without restriction or limitation.
#
# No warranties, either explicit or implied, are made as to the
# suitability of this code for any purpose. Use at your own risk.
#######################################################################

# force ADC enable for battery voltage and current
i2cset -y -f 0 0x34 0x82 0xC3

################################
#read Power status register @00h
POWER_STATUS=$(i2cget -y -f 0 0x34 0x00)
#echo $POWER_STATUS

BAT_STATUS=$(($(($POWER_STATUS&0x02))/2))  # divide by 2 is like shifting rigth 1 times
#echo $(($POWER_STATUS&0x02))
echo "BAT_STATUS="$BAT_STATUS
# echo $BAT_STATUS

################################
#read Power OPERATING MODE register @01h
POWER_OP_MODE=$(i2cget -y -f 0 0x34 0x01)
#echo $POWER_OP_MODE

CHARG_IND=$(($(($POWER_OP_MODE&0x40))/64))  # divide by 64 is like shifting rigth 6 times
#echo $(($POWER_OP_MODE&0x40))
echo "CHARG_IND="$CHARG_IND
# echo $CHARG_IND

BAT_EXIST=$(($(($POWER_OP_MODE&0x20))/32))  # divide by 32 is like shifting rigth 5 times
#echo $(($POWER_OP_MODE&0x20))
echo "BAT_EXIST="$BAT_EXIST
# echo $BAT_EXIST

################################
#read Charge control register @33h
CHARGE_CTL=$(i2cget -y -f 0 0x34 0x33)
echo "CHARGE_CTL="$CHARGE_CTL
# echo $CHARGE_CTL


################################
#read Charge control register @34h
CHARGE_CTL2=$(i2cget -y -f 0 0x34 0x34)
echo "CHARGE_CTL2="$CHARGE_CTL2
# echo $CHARGE_CTL2


################################
#read battery voltage	79h, 78h	0 mV -> 000h,	1.1 mV/bit	FFFh -> 4.5045 V
BAT_VOLT_LSB=$(i2cget -y -f 0 0x34 0x79)
BAT_VOLT_MSB=$(i2cget -y -f 0 0x34 0x78)

#echo $BAT_VOLT_MSB $BAT_VOLT_LSB

BAT_BIN=$(( $(($BAT_VOLT_MSB << 4)) | $(($(($BAT_VOLT_LSB & 0xF0)) >> 4)) ))

BAT_VOLT=$(echo "($BAT_BIN*1.1)"|bc)
echo "Battery voltage = "$BAT_VOLT"mV"

###################
#read Battery Discharge Current	7Ah, 7Bh	0 mV -> 000h,	0.5 mA/bit	FFFh -> 4.095 V
BAT_IDISCHG_LSB=$(i2cget -y -f 0 0x34 0x7B)
BAT_IDISCHG_MSB=$(i2cget -y -f 0 0x34 0x7A)

#echo $BAT_IDISCHG_MSB $BAT_IDISCHG_LSB

BAT_IDISCHG_BIN=$(( $(($BAT_IDISCHG_MSB << 4)) | $(($(($BAT_IDISCHG_LSB & 0xF0)) >> 4)) ))

BAT_IDISCHG=$(echo "($BAT_IDISCHG_BIN*0.5)"|bc)
echo "Battery discharge current = "$BAT_IDISCHG"mA"

###################
#read Battery Charge Current	7Ch, 7Dh	0 mV -> 000h,	0.5 mA/bit	FFFh -> 4.095 V
BAT_ICHG_LSB=$(i2cget -y -f 0 0x34 0x7D)
BAT_ICHG_MSB=$(i2cget -y -f 0 0x34 0x7C)

#echo $BAT_ICHG_MSB $BAT_ICHG_LSB

BAT_ICHG_BIN=$(( $(($BAT_ICHG_MSB << 4)) | $(($(($BAT_ICHG_LSB & 0xF0)) >> 4)) ))

BAT_ICHG=$(echo "($BAT_ICHG_BIN*0.5)"|bc)
echo "Battery charge current = "$BAT_ICHG"mA"

this script gives the AC power status :

#!/bin/sh
# This program gets the power status (AC IN or BAT) for pcDuino3
# I2C interface with AXP209
#
#######################################################################
# Copyright (c) 2014 by RzBo, Bellesserre, France
#
# Permission is granted to use the source code within this
# file in whole or in part for any use, personal or commercial,
# without restriction or limitation.
#
# No warranties, either explicit or implied, are made as to the
# suitability of this code for any purpose. Use at your own risk.
#######################################################################

#read Power status register @00h
POWER_STATUS=$(i2cget -y -f 0 0x34 0x00)
#echo $POWER_STATUS

# bit 7 : Indicates ACIN presence 0: ACIN does not exist; 1: ACIN present
#echo "bit 7 : Indicates ACIN presence 0: ACIN does not exist; 1: ACIN present"
#echo "bit 2 : Indicates that the battery current direction 0: battery discharge; 1: The battery is charged"

AC_STATUS=$(($(($POWER_STATUS&0x80))/128))  # divide by 128 is like shifting rigth 8 times
#echo $(($POWER_STATUS&0x80))
echo "AC_STATUS="$AC_STATUS
# echo $AC_STATUS

Example :

battery charging

rzbo@ubuntu:~$ ./battery_info.sh
BAT_STATUS=0
CHARG_IND=1
BAT_EXIST=1
CHARGE_CTL=0xd0
CHARGE_CTL2=0x47
Battery voltage = 3895.1mV
Battery discharge current = 304.0mA
Battery charge current = 0mA

rzbo@ubuntu:~$ ./power_status.sh
AC_STATUS=1

Battery discharging (USB power unplugged)

rzbo@ubuntu:~$ ./battery_info.sh
BAT_STATUS=0
CHARG_IND=0
BAT_EXIST=1
CHARGE_CTL=0xd0
CHARGE_CTL2=0x47
Battery voltage = 3678.4mV
Battery discharge current = 0mA
Battery charge current = 176.0mA

rzbo@ubuntu:~$ ./power_status.sh
AC_STATUS=0

IMG_20140916_183651 IMG_20140916_183625

 

Asterisk for Banana Pi R1 (FreePBX Image included)

After doing the FreePBX Asterisk Image for Banana Pi, I was asked by SINOVOIP (Banana Pi Manufacturer) to do an Asterisk Image for their router board, i.e. the Banana Pi R1. SINOVOIP has been very kind to send me a complimentary BPi-R1 for testing and developing.

It took me some time to get this done, but the image is finally ready. This image differs from my earlier Banana Pi Asterisk image in that, the earlier image was created by simply replacing the rootfs of a Raspbian based BPi Image, with RasPBX Image’s rootfs. However, this time I have actually been able to compile Asterisk on the latest Bananian Image for R1. This means that you can now have a powerful, complete and rather flexible Asterisk 11 (upgradable to 12!) desktop system with FreePBX, running on the BPi-R1. Further, Bananian offers lightening fast boot and load times with remarkable performance. (You can compare the speed with my earlier RasPBX based Image to see for yourself.)

The image comes preloaded with Asterisk 11, along with most of the standard FreePBX modules. Upgrading to Asterisk 12 should be pretty easy.

Credentials:

  • Login: root
  • Password: root
  • FreePBX Username: asteriskuser
  • FreePBX Password: pi

Note: I have tested this image (before and after upgrading to Asterisk 12) successfully with a BPi-R1 for SIP (using Android devices running Zoiper), along with video calling. Please be aware that 2 extensions (made during testing) already exist in the image and can be removed (I somehow forgot to delete them ;)). Also note that video calling is disabled by default and needs to be enabled from the pbx settings.

DOWNLOAD :

Pay 22.50 USD  (this will support our work)




Download both files and then un-rar using WinRar or any other appropriate program

 

Asterix for Banana Pi (FreePBX img file for Banana Pi included)

What is Asterix?

Asterisk is a software implementation of a telephone private branch exchange (PBX); it was created in 1999 by Mark Spencer of Digium. Like any PBX, it allows attached telephones to make calls to one another, and to connect to other telephone services, such as the public switched telephone network (PSTN) and Voice over Internet Protocol (VoIP) services. Its name comes from the asterisk symbol, *. [Source: Wikipedia]

Asterisk is like a box of Legos for people who want to create communications applications. It includes all the building blocks needed to create a PBX, an IVR system, a conference bridge and virtually any other communications app you can imagine. [Source: Official Asterix Website]

What is Banana Pi?

Banana Pi is a single-board computer built with ARM Cortex-A7 Dual-core (Allwinner A20 based) CPU and Mali400MP2 GPU, and open source software, Banana Pi can serve as a platform to make lots of applications for different purposes.

The RasPBX Project

This is a project dedicated to Asterisk and FreePBX running on the Raspberry Pi. Later, the Beaglebone folks ported RasPBX for the BeagleBone Black (BBB).

Asterix for Banana Pi

Sadly, the RasPBX project doesn’t support the Banana Pi yet. I looked everywhere on the net for an Asterix based PBX image for Banana Pi, but looks like no one has done this yet or they did but didn’t share . So, I decided to make one myself.

I simply replaced the rootfs on the Banana Pi’s Raspbian based image with RasPBX’s rootfs. The image should work on any Banana Pi variant with the Allwinner A20 processor (including Banana Pi, Banana Pro and Sinovoip’s Banana Pi M1).

Download links

The image file is 3.7GB, I am uploading a winrar compressed version that is approximately 437MB . Use a suitable application to un-compress it after download.
Pay 22.5 USD  (this will support our work)




CREDENTIALS

root/raspberry

  • FreePBX Username: asteriskuser
  • FreePBX Password: pi

Screenshots

FreePBX UIFreePBX_admin_screen

Further  Resources:

Directions to write the image to SD card

Read Documentation from RasPBX’s official website

 

PS: I have tested the image and it’s working fine. If you are facing any problems with it, feel free to post a comment and I’ll be happy to help. 🙂

 

Beagle Bone linux images

What is BeagleBone Black?

BeagleBone Black is a low-cost, community-supported development platform for developers and hobbyists. Boot Linux in under 10 seconds and get started on development in less than 5 minutes with just a single USB cable.

MKCCE3-0_grandeMKCCE3-1_grande

Processor: AM335x 1GHz ARM® Cortex-A8

  • 512MB DDR3 RAM
  • 4GB 8-bit eMMC on-board flash storage
  • 3D graphics accelerator
  • NEON floating-point accelerator
  • 2x PRU 32-bit microcontrollers

Connectivity

  • USB client for power & communications
  • USB host
  • Ethernet
  • HDMI
  • 2x 46 pin headers

Software Compatibility

  • Debian
  • Android
  • Ubuntu
  • Cloud9 IDE on Node.js w/ BoneScript library
  • plus much more

 

 

 

 

 

The following link hosts all beagle-bone images and is actively maintained.It includes flasher and SD card images of angstrom, debian and ubuntu builds. Those who wish to compile the kernel from source may also do so.

https://rcn-ee.net/deb/