18650 Battery capacity checker

Some of you know, I really like lithium ion batteries

*shocked*

Shut it!  This is a short post, I don’t need you hamming up the works.

Just wait till I show up in your videos….

You wouldn’t….

Hello….

Oh hell…..

Ok, lets not worry about that now.

I picked up a pretty sweet haul of batteries this week.

 

 

 

 

22lbs.  I counted 107 2cell packs.  214 cells to check out.  This is great, but I have a single opus charger that can do 4 cells at a time.

So 214 cells will take some time to process.  I have done that game.  So I wanted to do more cells.  There are examples online of doing this with arduino’s and what not and since I am big fan of arduino’s anyways I decided to give that a shot.  I built it out initially with an arduino uno.  Using the awesome guidance of Adam Welch.  If you don’t know who Adam is, you gotta check out his work.

Website: http://adamwelch.co.uk/ 
Youtube: https://www.youtube.com/channel/UCm5sG3-BXQZfVy3st2T_XKg

His work I used for this is here.

I modified the code a little as I didn’t have that screen.  I have a 20×4 screen.  I also updated mine to calculate the voltage reference from the internal 1.1v reference.


/*
* Battery Capacity Checker
* Uses Nokia 5110 Display
* Uses 1 Ohm power resister as shunt - Load can be any suitable resister or lamp
*
* YouTube Video: https://www.youtube.com/embed/qtws6VSIoYk
*
* http://AdamWelch.Uk
*
* Required Library - LCD5110_Graph.h - http://www.rinkydinkelectronics.com/library.php?id=47
*/

#include <LiquidCrystal_I2C.h>
#define gatePin 2
#define highPin A0
#define lowPin A1

boolean finished = false;
int interval = 5000; //Interval (ms) between measurements

float mAh = 0.0;
float shuntRes = 1.0; // In Ohms - Shunt resistor resistance

float current = 0.0;
float battVolt = 0.0;
float shuntVolt = 0.0;
float battLow = 2.9;

LiquidCrystal_I2C lcd(0x27,20,4);
unsigned long previousMillis = 0;
unsigned long millisPassed = 0;

void setup() {
analogReference(INTERNAL);
Serial.begin(115200);
lcd.init(); //initialize the lcd
lcd.backlight(); //open the backlight
Serial.println("Battery Capacity Checker v1.1");
Serial.println("battVolt current mAh");

pinMode(gatePin, OUTPUT);
digitalWrite(gatePin, LOW);

lcd.setContrast(68);

lcd.clear();

lcd.print("Battery");
lcd.print("Check");
lcd.print("Please Wait");
lcd.print("AdamWelch.Uk");

delay(2000);
lcd.clear();
}

void loop() {
voltRef = readVcc() / 1024.0;
Serial.print("Volt Ref: ");
Serial.println(voltRef);
battVolt = analogRead(highPin) * voltRef / 1024.0;
Serial.print("Batt Vol: ");
Serial.println(battVolt);

shuntVolt = analogRead(lowPin) * voltRef / 1024.0;
Serial.print("Shunt Val: ");
Serial.println(shuntVolt);
Serial.println();
Serial.println();
/*
Serial.print(battVolt);
Serial.print("\t");
Serial.print(current);
Serial.print("\t");
Serial.println(mAh);
*/
if(battVolt >= battLow && finished == false)
{
digitalWrite(gatePin, HIGH);
millisPassed = millis() - previousMillis;
current = (battVolt - shuntVolt) / shuntRes;
mAh = mAh + (current * 1000.0) * (millisPassed / 3600000.0);
previousMillis = millis();

lcd.setCursor(0,0);
lcd.print("Discharge ");
lcd.setCursor(0,1);
lcd.print("Volt:");
lcd.print(battVolt);
lcd.print("v ");
lcd.setCursor(0,2);
lcd.print("Current:");
lcd.print(current);
lcd.print("a ");
lcd.setCursor(0,3);
lcd.print(mAh);
lcd.print("mAh ");
lcd.print("Running ");



}
if(battVolt < battLow)
{
digitalWrite(gatePin, LOW);

finished = true;



lcd.clear();
lcd.print("Discharge");
lcd.print("Voltage:");
lcd.print(battVolt);
lcd.print("v");

lcd.print(mAh);
lcd.print("mAh");
lcd.setCursor(0,1);
lcd.print("Complete");


}
delay(interval);
}

long readVcc() {
long result;
// Read 1.1V reference against AVcc
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Convert
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result = 1126400L / result; // Back-calculate AVcc in mV
return result;
}

Next step is to add a “charging” function with a tp4056 so I can charge then discharge.

 

Amazon – 5 for 6.95

Ebay – 10 for 4.95

Aliexpress – 10 < 2 bucks.

 

Once that is working I should be able to add a couple more modules.  I have been really looking towards doing something with Brett Wattys 8 module charger.  That things is INTENSE!!!

If you want to see all the info check out the secondlifestorage forum.

https://secondlifestorage.com/t-Brett-s-Arduino-8x-Smart-Charger-Discharger

He also has a portal he is setting up to help aggregate some numbers on how many cells the community has recycled.

 

 

Until later!!!

bye!!!!

Find my Sh*T!!! – The lost iphone saga

Ok, we have all done it.  Where the hell is my phone?  Where’s the ipad?   Home alone trying to find it and you have no way of calling it because, well, no land line.

 

A week or so ago I finally replaced my Jurassic period thermostat with something a little newer.  I know, weird right.  I do all this stuff and I had a thermostat that was 1 step above this

old_honeywell_t87

So I got a 2gig CT100 with z-wave.
61cUaIUZOLL._SL1024_

 

 

55553046So as any self respecting geek would do.  As soon as I got it hooked up, I tied it in to my home automation system.

 

So I have basic items configured, mainly so I can see the temps ect.  But there is another thing we can do with this.  Got the idea from the thread

https://community.openhab.org/t/find-my-iphone-from-my-nest/5663

If you look you will see I have contributed and written a simple php service for finding an iphone 🙂

Here is the github for that simple php service https://github.com/brunkj/FindMyIphonePHPService
So I have my PHP service setup.  I have my home automation system.  I have my z-wave thermostat.  I have rythm.  I have style..  $%^& what’s wrong with me…..

So I created a simple rule


rule "Find iPhone via thermostat"
  when
    Item HVAC_CoolSetPoint changed to 69
  then
    sendHttpGetRequest("http://xx.xx.xx.xx/findmyiphone/?phone=jason")
    sendCommand(HVAC_CoolSetPoint, 75)
  end

 

Simple description.  Set the thermostat to 69.. hehe hehe 69….  {giggle} 61832143

 

 

 

 

 

 

 

 

Ok, I’m better.  Set to 69.  Openhab sees it’s now set to 69, realizes that’s way out of character and runs the rule “Find iPhone via thermostat” which sends the call to my php service, then sets the temp back to our standard 75.

I am implementing 1 additional rule for 68 degrees for the wife’s phone.

OpenHab crashing with Z-Wave FIX IT FIX IT FIX IT FIX IT!!

So,  my openhab system periodically decides to leave the building.  Appears there is a problem from time to time when the z-wave binding loses communication to the z-wave stick it gets upset and tells openhab to take a hike.

This is bad.  Once because it exposed something I missed in my fault tolerance.   I had compensated for network issues and full machine failover.  But the actual process going belly up…. ooops.  My Bad.

Soooo I see it crash while at the gym today and the only thing in my head….

gSHIj

So I appear to have done that.

Let me bring you up to speed on the current state of my home automation.  After the great NAS failing of 2015 I was forced to reduce some of my virtual environment.   I have not brought my secondary HA controller back online yet.  However, it appears that still using keepalived I am able to help address this random problem.

I have added in a new option in my keepalived.conf

 


vrrp_script chk_hahealth {
    script "/usr/local/sbin/healthcheck.sh"
    interval 10 # check every 10 seconds
    fall 2 # require 2 failures for KO
    rise 2 # require 2 successes for OK
}

vrrp_instance VI_1 {
   state MASTER
   interface eth0
   virtual_router_id 220
   priority 150
   notify /usr/local/sbin/notify-keepalived.sh
   advert_int 1
   authentication {
        auth_type PASS
        auth_pass fakepass
   }

   virtual_ipaddress {
      192.168.2.90
   }
   track_script {
     chk_hahealth
   }
}

So what this does is add a keepalived health check.   Every 10 seconds keepalived runs the script /usr/local/sbin/healthcheck.sh and gets an exit code of 0 or 1.  0 if all is good.  1 if the world fell apart.

Environmental concept. Some images in montage provided by NASA (http://visibleearth.nasa.gov/)

The code for this script is


#!/bin/sh
SERVICE=openhab;

if ps ax | grep -v grep | grep $SERVICE &amp;gt; /dev/null
then
 echo "$SERVICE service running, everything is fine"
 /usr/bin/logger "$SERVICE service running, everything is fine"
 exit 0
else
 echo "$SERVICE is not running"
 /usr/bin/logger "$SERVICE is not running"
 /etc/init.d/openhab restart
 exit 1
fi


Explanation:

So this script just checks to see if the openhab process is running.  If its good, exit 0.  If its not, exit 1 but go ahead and try to restart openhab.  When keepalived gets the exit 1 code it keeps track of it.  You will see in the config that there is a fall 2 line.  That means that if there are 2 exit 1 status’s keepalived will go into a failed state.  When the second HA box is back online this will force openhab to move over to the other one.  However, I have not seen this happen so far as openhab loads pretty quick so since there is 10 seconds between the checks the second check comes back with an exit 0 and resets the fall count.