Monday, February 15, 2016

The Evolution of Pi - Part II

This is a continuation of Part I.

Another possibility came about arising from my son's science project:

Q: How do you test the capacity of [rechargeable] batteries?

There are multiple possibilities:

  • After some research, I bought a battery capacity tester (DC 60V 100A RC Boat Heli Watt Meter Battery Power Analyzer Digital LCD Display) for $13.42. A quick testing found it wasn't accurate for AA batteries. For example, the current shown on the LCD display is way off when a multi-meter is wired in the circuit. 
  • Then I got inspired by this Denis Hennessy article. There is no reason I can't do the same thing with the Pi with a few modifications
    • I don't need the casing for the science project. I would also use a bread board instead of proto board since I fully intent to tear it apart once my son's project is over.
    • Would like auto-shutoff at the drop off voltage. This will prevent over-draining the battery, which will kill the battery or cause other damage in the house. 
    • Would also like some kind of notification.
The Design:
The diagram is functional yet not fancy.

  • K1 is a manual switch -- the "master" shutoff.
  • The Relay is controlled by the Raspberry Pi to close or open the circuit so we can programmatically start/stop the testing.
  • The battery is drained through "R" (10.5 Ohm wire wound resister, mounted on an aluminum bracket as the heatsink)
  • "r" and LED provide visual indicator whether the circuit is on/off. We also blink it anytime we sample the data.
  • V-in0 is the input to an ADS1115 ($4.69 shipped from China). It is a four channel analog to digital converter that is a wonderful little device. The downside of Pi (compared to Arduino) is the lack of analog input, hence the need for something like the ADS1115.
  • So the Pi eventually reads the voltage over "R", then calculates the current, wattage, and WaHr.
We also use a small fan to blow at "R" so it wouldn't over-heat, as well keeping the "10.5" Ohm accurate. Actually we adjusted it down to "9.1 Ohm" to count for the effect of "r" and the LED. The following is a picturing showing the resistor (R), the relay and ADS1115. The 8-channel relay can be replaced with a single channel one. But the price was right and we can use it for other projects later on. The white stuff between the resistor and the heatsink is thermal paste, conducting heat from the resistor to the heatsink.


The Coding:
We decided to use the Python RPi.GPIO library which works with the ADS1115. Once things are initialized, the code goes into a loop: measure the voltage, flash the LED, print out the values, sleep 60 seconds, and start over again.

When the cut-off voltage is reached, it turns off the relay, and prints out the final output.

Another nice feature is we used the Notify My Android application and the PyNMA client library to send notifications to Android devices. Works pretty well. The follow is one sample test:



Epilogue:
In my son's project, he would SSH to the Pi, run the command line, and walk away to do his things. I showed him to use GNU screen to prevent the program from terminating due to timeout.

At this point, Python turns out to be a very handy language for prototyping. You can start doing things with little planning, and learn while you experiment.

A few weeks after my son completed his science project, I dismantle the whole thing. The Pi continues to announce incoming calls as covered in Part I

No comments:

Post a Comment