Create a Folder home/pi/charger
Make a new python Script using Python Software.
Instead of measuring the voltage or current, this project gets the information directly from the phone using the ADB package. Android Debug Bridge (ADB) is a versatile command line tool that lets you communicate with an emulator instance or connected Android device. It facilitates a variety of device actions, such as installing and debugging apps, and it provides access a Unix shell that you can use to run a variety of commands on an emulator or connected device. When the phone reaches 100% recharge, the Python script gets this information and it send the signal using GPIO 17 and it turns off the power using the relay.
The phone needs to be "developer mode
". To use ADB with a device connected over USB, you must enable USB debugging in the device system settings, under Developer options.
import sched, time
import subprocess
import time
import RPi.GPIO as GPIO
import os
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(17,GPIO.OUT)
GPIO.output(17,False)
s = sched.scheduler(time.time, time.sleep)
def do_something(sc):
print ("Doing stuff...")
os.system("adb shell cat /sys/class/power_supply/battery/capacity > curr_batt.txt")
from itertools import islice
with open("full_batt.txt",'r') as myfile:
head = list(islice(myfile, 3))
from itertools import islice
with open("curr_batt.txt",'r') as myfile:
headh = list(islice(myfile, 3))
if headh != head:
os.system("adb shell cat /sys/class/power_supply/battery/capacity > curr_batt.txt")
else:
GPIO.output(17,True)
sc.enter(1, 1, do_something, (sc,))
s.enter(1, 1, do_something, (s,))
s.run()
Make two text files in same path home/pi/charger
1) File name full_batt.txt
Enter the data in file:
100
Step 2: Make a launcher script$ cd bbt
$ nano launcher.sh
Type in this script:
#!/bin/sh
# launcher.sh
# navigate to home directory, then to this directory, then execute python script, then back home
cd /
cd home/pi/charger
sudo python charger.py
cd /
100
Save it!
Step 3: Make it executableMake the launcher script an executable:
$ chmod 755 launcher.sh
$ sh launcher.sh
This will run your Python code.
Step 4: Add logs directory$ cd
$ mkdir logs
Step 5: Add to your Crontab$ sudo crontab -e
This will bring up a Crontab window:
@reboot sh /home/pi/bbt/launcher.sh >/home/pi/logs/cronlog 2>&1
Step 6: WiringNow connect the wire as shown in image:
If you want to charge your phone faster with some Qualcomm fast charge we can give the power supply from the external power which will maintain the speed of charging. Now just attach your smartphone and it will automatically turn off power supply when smartphone battery is full.
Comments