I'm still working on the TailBrain (Arduino-based trailer tilt controller), having fixed coding issues which were causing random reboots and overheating issues resulting from trying to power
my Arduino with 13.8V. I think I just lost another photosensor so not quite there yet.
Having figured out most of the details related to setting up bi-directional communication between an Arduino and an iPhone, I decided to procrastinate by taking on a little side project I've been calling the DrainBrain. Using
a more modern Arduino based on a 3.3V processor on a board with built-in Bluetooth LE, I tapped into the serial data connection between my CA3 and GPS Analogger and piped the data to my iPhone. The hardware looks like this:
I can view the raw serial data stream on my phone like so:
Or I can parse and reformat the data on the Arduino to create features which aren't available on the CA3. The user interface on the phone can be anything I want as long as what I want is either a screen full of text or a live plot. The idea is that I can avoid writing a single line of code that needs to run on the iPhone by using a general-purpose Bluetooth LE app, written by Adafruit. The app is available for
iPhone and
Android. One of the trade-offs is that I'm not going to get a cool dashboard interface on my phone but I can live with it. I'm not trying to replace the CA3 screen, only augment it.
So, now I'm rolling down the road entering text commands into a terminal console. I think Steven Roberts is my spirit animal.
My first feature was to calculate the time remaining until the solar chargers enter CV charging mode under current conditions ("CV Min" above). This is useful for planning breaks if I'm concerned about trying to use every bit of available sun. I can keep an eye on the charge status using my phone from up to 15 meters away: handy for taking a noontime siesta under some nice shade while the bike charges.
To calculate this time from the CA3 data took some effort. I needed to figure out the battery's current State of Charge (SoC). Since I'll be resetting the CA3 at the start of each day and the battery will not always be fully charged at that point, I could not use Ah to make the initial SoC determination and had to use voltage instead.
I modeled the
LG MG1 18650 cell's discharge and charge curves under different loads and came up with some simple linear formulas to interpolate SoC. This is reasonably accurate as long as the battery is at steady state and over 30% SoC. From that point on, I track the total Wh load and Wh solar charge and use those to update the SoC. The total Wh capacity of the battery is dependent on the rate of discharge and the State of Health (SoH) so I include those in the estimate of Wh remaining in the battery. I also had to switch to an external shunt for battery load measurements since since of my accessory loads do not go through the PhaseRunner motor controller.
Now that I have a reasonably accurate measure of Wh remaining in the battery (within 10 Wh based on 3 road tests so far), I can do all kinds of interesting things with that data. For example, I can estimate the remaining range in miles based on current energy consumption or based on Wh/mile since the start of the current session. I calculate both based on battery alone (in case clouds roll in) and battery plus solar. I can decide on the fly which number best represents the road ahead. This works best when the road ahead has the same elevation changes, headwind and solar irradiance as the road behind.
Alternately, I can enter a desired range and plot the Wh/mile I need to maintain to arrive before the battery's BMS cut-off. These are calculations I've tried doing in my head in the past and they take away from just enjoying the ride.
Ideas for future upgrades include hooking up one the Arduino's analog output pins to the ThIn (throttle input) signal on the CA3 so the Arduino looks like a manual throttle input and using it to create some custom auto-cruise modes.
- Automatically adjust motor power based on distance remaining to destination and Wh remaining in battery.
- Automatically match motor power to solar generation to maintain 0 net watts in/out of battery to prevent overheating the cells in extreme temperatures such as those encountered in desert crossings (40°C / 104°F and up).
And finally, a little eye candy. I had some strips of individually-addressable RGB LEDs laying around (
Adafruit NeoPixels) and it occurred to me that I could hook these up to the Arduino to communicate battery and solar charging status in a way that's easier to read at a glance and will be easier to explain for roadside show and tell. Red/green is SoC (about 65% in this photo) and yellow is solar charge watts. LED brightness adjusts automatically based on current solar power. Each green dot corresponds to the energy needed for 100 meters of elevation gain so that's handy for budgeting.
Some intermediate steps during the prototyping phase:
I encapsulated the whole thing with clear heat-shrink tubing and silicone. The board status LEDs remain visible, I can still press the reset button and I can take it apart later if I need to change or fix something. The USB cable powers the device and enables updating the code if I want to make changes.
