18650 Battery Capacity Tester

I scrounge electronic parts from dead things all the time.  I’ve collected about 20 18650 cells in the last few years from drill battery packs and laptop batteries.  I’ve made a few 7.2v packs for my RC car, but I hesitate to do much with the rest until I find out the capacity of each cell.  I’ve also been wanting to play with a MOSFET and my DigiSpark.  So I built this capacity tester.  It basically connects the 18650 to a load (a hot water heating element, about 10Ohms of resistance).  The DigiSpark monitors the voltage of the battery using an analogRead call on pin p2.  It keeps the relay closed (via the MOSFET) until the battery voltage drops below a preset voltage (3.1v is what I’m checking for, but some people say it can go as low as 2.7 v without damage).  Once the voltage drops below the preset value, the relay opens, and a variable is set so that the digispark won’t try to re-engage the relay until it is reset.

I used Deans connectors to connect the 18650 holder I made with the circuit.  This allows me to easily swap in other batteries with a Deans connector once I add a voltage divider so higher voltages can be read.  If you haven’t seen deans connectors before, you may want to check them out.  The knock offs are cheap, and they work really well.  Some people have difficulty soldering them, and I had a problem for my first 10 pairs or so, but now, it’s a piece of cake.

Although it looks like a jumble of wires, all the connections are soldered and covered with heat shrink tubing, and it turned out pretty nice.

2015-09-29 21.39.03

The relay and the clock both get their ground from the MOSFET, so when the digispark opens the relay, the analog clock stops as well, recording how long it took to discharge the battery.

2015-09-29 21_32_06-SchemeIt _ Free Online Schematic Drawing Tool _ DigiKey Electronics

All the while, the Digispark tells me the analogRead value via morse code and the LED.  Thanks to Mark Fickett’s arduinomorse library.  To convert the analogRead value to voltage, divided by 2 (5v = 1024, so 205 per volt, if we divide by 2 we get the number of hundredths of a volt).

It’s not a perfect system, since the battery voltage drops as it discharges so the current changes over time.  But it works good enough for me to match cells based on approx capacity.

The code is really simple:

#include "morse.h"
#include <math.h>

#define PIN_STATUS 1
#define BATT_LOW_VOLTAGE 3.11 

int sensorValue = 0;
double voltage = 0;
bool stopped = false;
LEDMorseSender morseSender(PIN_STATUS);

void setup() { 
  // initialize the digital pin as an output.
  pinMode(1, OUTPUT); //LED on Model B 
  pinMode(0, OUTPUT); //Relay 
  digitalWrite(0, HIGH); 

// the loop routine runs over and over again forever:
void loop() {
  sensorValue = analogRead(1); //P2 
  voltage = (sensorValue * 1.0) / 205.0;
  voltage = round(voltage * 100) / 100.0;
  if(voltage > BATT_LOW_VOLTAGE && !stopped){
    digitalWrite(0, HIGH); 
  } else {
    stopped = true;
    digitalWrite(0, LOW); 
  morseSender.setMessage(sensorValue / 2);


Using a Raspberry Pi to get started with SPI

I am working on a USB Credit Card reader for iOS and it’s going to require some serious hacking, and using SPI.  SPI is a simple protocol that many electronic components / microchips use to talk to each other.  I’ve never used it before, and am new to microchips so I hesitate to jump right in without some experience.   Electronics and microchips can be a pain / impossible to debug so I want to get something working before I start really hacking so that I always have a point of reference to come back to.  While the best solution would be a protocol analyzer so I can visualize the communication between devices and troubleshoot that way, instead, I’m going to setup a loop back on a Raspberry Pi using both the Raspberry Pi’s built in SPI feature, and bit banging on a few of the Pi’s GPIO pins.   This should result in me being able to send data from the built-in SPI feature and receive it on the bit-banging program.   For quick reference, SPI can be a 3 wire system.  With a clock pin, a read and a write pin (SCLK, MOSI, MISO).

But, before I get there, I’m first going to setup just the Raspberry Pi’s SPI feature to echo and run some test programs to make sure I’m using that correctly.

gpio-led2015-09-22 00.24.06To do this, we just need to short the read and write (MOSI / MISO) pins together.  They are side by side on the GPIO header, so you can short them with just a jumper.  Unfortunatly, I couldn’t find any, so I used a random connector that fit and shorted the wires together (See my lincoln log case, sweet huh?).  Be very careful here, there are a few places on the GPIO where GND and 5v or 3.3V are present and attaching this jumper would be a bad thing there.

Now, we need to enable the SPI port, it’s disabled by default, just do “sudo raspi-config” and go to Advanced Options, then look for the SPI option and enable it, then reboot.  This should take all of 10 seconds (other then the reboot).

2015-09-22 00.46.55Once you are rebooted, type “ls /dev” you should see “spidev0.0” and “spidev0.1”  SPI has a 4th wire called “Chip Select”, If you have more then 2 devices on the SPI “bus” the master device can set chip select high for the chip you want to send / receive data to / from.  Both of the SPI devices are the same, they just make different GPIO pins high to select a different chip on the bus…  blah blah blah…  In our case, we’re just ignoring this.

At this point, we should be able to echo data…  There is a SPI test program as part of the linux kernel, but we need to get an older version, so “wget -O spidev_test.c https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/plain/Documentation/spi/spidev_test.c?id=95b1ed2ac7ffe3205afc6f5a20320fbdb984da92 ”  then, “gcc -o spidev_test spidev_test.c”, and finally “./spidev_test -D /dev/spidev0.0”  You should get results like the ones on this page: https://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md  If you remove the jumper and run it again, you should get all zeros…  Now, it’s time to do some bit banging….

2015-09-22 22_50_16-Console2 - MINGW32__c_u_wwwgpio-led-miso 3.3vFirst, let’s verify that connecting MISO to 3.3v will produce what we want.  Remember when we have MISO and MOSI not shorted we get all zeros back from the test program.  If we connect 3.3v to MISO we should get all FFs.

And we do!!!  Yay!!!  Now, lets connect MISO to a GPIO pin and see if we can get the pin to go High (+3.3v) on demand.

First, let’s install a python library to help us work with the GPIO easier.  Follow Step 3 here: http://openmicros.org/index.php/articles/94-ciseco-product-documentation/raspberry-pi/217-getting-started-with-raspberry-pi-gpio-and-python

Now, I was tired of doing all this through a terminal, so I took a break and installed samba, according to these instructions: http://raspberrywebserver.com/serveradmin/share-your-raspberry-pis-files-and-folders-across-a-network.html

gpio-led 18tomisoThe script I created is:

import RPi.GPIO as GPIO
import time
GPIO.setup(12, GPIO.OUT)
GPIO.output(12, True)

I then connected Pin 18 (to RPi.GPIO this is Pin 12).  Ran my python program, and ran the test program.  Viola!!! It works.  All FFs again.

Now we change the Program to:

import RPi.GPIO as GPIO
import time
GPIO.setup(12, GPIO.OUT)
while True:
GPIO.output(12, True)
GPIO.output(12, False)

Run it, and while it’s running run our test script.  We should get a mix of FFs, and 00s, and between the sets of FFs and 00s there will be smaller numbers (like FC).

To Be Continued…

Raspberry Pi GPIO Connectors

I have had a Pi  for a long time…  I’ve wanted to play with the GPIO on several occasions, but connecting to the GPIO header seemed difficult.  Well, I was stupid.  Connecting to the GPIO is SO SO EASY.  See…  PC Board manufacturers are pretty sharp and there are some standard dimensions for components and pin headers.  And, as it turns out, there are A LOT of connectors that use these same pin sizes and dimensions.  Some examples I’ve found are:

Small Stepper Motor Connectors, PC Fan Connectors, old IDE and Floppy Disk ribbon cables, That collection of 1, 2, and 3 pin connectors that attach a motherboard to buttons and lights in a pc case.  R/C Servo connectors, and lots of other random connectors inside consumer electronics…  Odds are that you’ve got a connector that will work in your random parts and wires bucket (you’ve got one of those, right?).  If not, go buy something like an old tape deck or vcr from a thrift store and cannibalize them for some Pi GPIO connectors.

2015-09-22 00.32.37 2015-09-22 00.32.48 2015-09-22 00.32.28



The Chateau Sport FSM / Shop Manual

An uncle on my wife’s side has an RV, and it broke recently.  He asked if I could look at it, which I was happy to do.  Unfortunatly, for those who don’t know, getting technical information on the vehicle part of an RV is not easy.  The RV comes with all kinds of books, schematics, etc…  For the RV itself, but the engine, transmission, body, etc…  Can be a mystery.

The Chateau Sport (which is manufactured by Four Winds) came / comes in two chassis options.  A Ford, or a Chevy / GM.  The RV itself is almost identical for both, but the wheels, engine, transmission, cab, etc… is what changes.  It took me about 3 hours of googling to find out that the Chateau Sport (2004) is built on a GM Van Chassis (which you wouldn’t expect since it is a dually in the back).  So, the whole reason for this post, is to hopefully help some poor soul who is looking for the Factory Service Manual for the GM Chassis of a 2004 Chateau Sport.  GM has a website dedicated to “Up Fitters” (people who buy incomplete vehicles, and built purpose built vehicles, like ambulances, utility trucks, and RVs).

So, if you are looking for the electrical diagrams for a 2004 – 2006ish? Maybe 2007/8 go here:   Look under “Light Duty 2006”, and “G/H Full Size Vans”.  There it is.

Once I had the manual in hand, I easily found that the problem with the RV was that a fuse was blown (there are a lot of fuses, so I’m not surprised we missed one the first time around.)


Chateau Sport FSM PDF


The “Water Survival Pill”

Someone should make a “Water Survival Pill”.  It is a pill that helps you float by giving you really bad gas…  According to this page: http://hypertextbook.com/facts/2000/JonathanCheng.shtml The stomach can hold up to 4 liters when it stretches, but my guess is that that is terribly painful.  Wikipedia’s article on the Gallon Challange (aka Milk Chug)  says the stomach holds about 2 liters.  2 liters of water weighs 4.4 lbs.  So filling your stomach with 2 liters of gas would be the equivalent of dropping 4.4 lbs of weight.  It’s not much, but when treading water for days at a time, 4.4 lbs could make a big difference.

Could you just swallow enough air to make it work?

Paul’s Ace Hardware

Recently I started racing RC cars as a hobby.  Right next to the Local Hobby Shop where the races take place is an Ace Hardware.  Paul’s Ace Hardware is a hardware store that has survived the birth of big chain home improvement stores (Home Depot, Lowe’s, etc…).  Paul’s Ace Hardware is a really cool store.  Lots of people to help you, yet they don’t come up and ask you every 10 seconds if you need help (which is nice).  They also provide free popcorn, and have enough of the important stuff that 99% of the time, they have exactly what I need.  And, because of their awesome location between Cafe Rio and Hobby Town (two of my favorite places) makes them a convenient place for me to shop.  Now if only I could get their free wifi to work from the race track in the parking lot…

Science Based Leadership

I remember back to my childhood in SC and thinking how stupid people were.  As I grew, I realized not all adults are stupid, however there are adults who lack balance, and quickly latch on to an idea just because the presenter made a good case (this is one way in which Hitler came to power, he was one of the most talented public speakers our world has ever seen).  I am the leader of Novak Solutions, LLC.  We have 5 team members currently, with 2 other owners, for a total of 7 people.  To me the MOST important role I have is to establish a culture that will take us where we want to go.   I believe a lot of  traditional “Corporate Culture” is not the best.

Tonight, I heard JFK’s Moon Speech (https://ia600506.us.archive.org/11/items/jfks19610525/jfk_1961_0525_moon_64kb.mp3).  At a rousing moment he says “We choose to go to the moon in this decade and do the other things, not because they are easy, but because they are hard”.  It is inspiring, and gets you excited, it is tempting to share this with the company, and make it a quote to put on the wall.  But, the companies goals don’t align with that.  We don’t want to do things just because they are hard.  That is stupid. (Yes, it does have benefits, and sometimes doing something just because it is hard is great, for example, when you need to learn, or want experience, or are trying to build muscle)  However, when given two paths that end at the same direction, and one is hard, and one is easy.  Save your energy for times when the only path is hard, and take the easy one now.



Wow! Multiple Profiles in Chrome (i.e. log into multiple accounts for the same site simultaneously)!

I run two small businesses and my own personal life.  I have 3 gmail accounts, 3 amazon.com accounts, 3 google calendars, 3 google drive accounts etc…  Google handles multiple accounts ok (but not Google drive), but Amazon doesn’t handle multiple accounts at all.  I need to log into all 3 Amazon accounts daily, finaly I looked for a solution and found this and ran across this little known feature of Google Chrome…  http://www.howtogeek.com/100999/how-to-use-multiple-profiles-in-google-chrome-like-a-ninja/  Now, not only can I be logged into all 3 amazon accounts in seperate windows, I also get a ninja in the upper left corner of the window!!

MS Sql Server via PHP On Linux

MSSQL Server on Linux can be a pain.  I’ve spent the last few days trying to come up with a good, reliable, stable, upgrade able stack to deploy on our Novak Solutions servers, and then presented it to our team this morning as a training.  Here is the graphic I used.  If you have any questions, post them in the comments.  Essentially, there are about a half dozen ways to connect php to MSSQL, but only 1 of them really works well.  That is using unixODBC or iODBC (just use unixODBC, it is the more mature of the two) (Linux people, don’t leave me here, as much as I hate ODBC, it is pretty much the only way (without installing MS stuff on your Linux Server (and that only works if you use RedHat or Suse)) to connect to MSSQL from a Linux server) via FreeTDS.

RC Car: Vaterra Kemora


Saturday I bought a Vaterra Kemora (It’s an RC Car, not a real one…)  and I had to do a lot of searching to find the info on it I wanted, so here is a summary of what I’ve found…

First, it is a bad little car…  Practically indestructible, crazy fast out of the box for $150, and tons of fun.

I took it bashing at a Skate Park close by and had a blast.  It survived 12 foot jumps landing on the roof, sliding all over the place, rolls, tumbles, it was awesome.  Finally, a shock end gave out just like this guys: http://www.rctech.net/forum/12325599-post125.html But we were REALLY abusing it, so I’ve got to give it 5 stars for durability (and a little cleaning and some super-glue and it’s back in use).  The NiMH that came with it was bad (getting it replaced), but I’d just bought a few Black & Decker 20v Max drill drivers on black friday for cheap, and build 2 li-ion packs for it with the cells from one of the drills.  I converted the battery connectors over to Deans connectors on the advice of my new friend and recently hired employee at Hobby Town in Gilbert, AZ – George

Ok, on to the good stuff.

3s LiPo – This thing already screams but you can make it scream lots more if you get the optional 3s LiPo, you can buy it here from Vaterra: http://www.vaterrarc.com/Products/Default.aspx?ProdID=DYN1477  Or just google DYN1477 (It is made by Dynamite and the part number is “DYN1477”)

Maintenance – Keep the dust out, check the pinion mesh occasionaly, and put a dab of oil on the bearings (Regular Synthetic motor oil, or marvel mystery oil will do).  If you get it wet, dry it, blow out any left behinds with compressed air, and then use a water displacement lube (like wd-40) to get the water out of the bearings, I recommend you re-lube with something else other then wd40, as wd-40 tends to not really lube stuff all that well or very long.  And, use a can of electronics cleaner to blow out the motor.