Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 17:36 19 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : 12v Battery Mon using Explore 28

Author Message
MikeO
Senior Member

Joined: 11/09/2011
Location: Australia
Posts: 275
Posted: 06:19pm 29 May 2017
Copy link to clipboard 
Print this post

Just a quick post, my latest project using the fantastic little gem from Grogster and Rob. Its a 12v Battery monitor (inspired by BMPRO Device no doupt ) , +-30amps. It outputs on wifi and Usb serial Actual Voltage and current , accumulated Load and Charge AmpHrs , Battery temperature and State of Charge.



Photo shows 3D printed enclosure , Battery terminals, from left ESP8266 wifi, ASC711EX current sense, Explore 28,bottom left Temp sensor and DC to DC PSU.



This photo shows the Output @ 5sec intervals.
Temp, Volts, Current, Load AmpHrs, Charge AmpHrs, %State of Charge
The photo shows a Windows app displaying data stream via wifi (UDP) and below is the USB serial. The Windows app I wrote some time ago to communicate with ESP8266 UDP protocol, I will probably write a more specific app to communicate with the Battery Monitor for windows, I am also trying to learn(get to grips with) B4A so I can make one for Android phone which would possibly be more convenient. Alternately another uMite backpack with LCD display could be used displaying the serial data.

I will post more soon.


Codenquilts
 
greybeard
Senior Member

Joined: 04/01/2010
Location: Australia
Posts: 158
Posted: 12:36am 30 May 2017
Copy link to clipboard 
Print this post

nice
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9083
Posted: 03:44am 30 May 2017
Copy link to clipboard 
Print this post

Clever.
Smoke makes things work. When the smoke gets out, it stops!
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 09:38pm 30 May 2017
Copy link to clipboard 
Print this post

Really nice job Mike - amazing how neatly a 3D printer can tidy up a heap of modules! What are the dimensions of the 'box'?

Greg
 
MikeO
Senior Member

Joined: 11/09/2011
Location: Australia
Posts: 275
Posted: 12:07am 31 May 2017
Copy link to clipboard 
Print this post

Thank's Greg

Dimensions are 120 x 50 x 30mm

Mike
Codenquilts
 
MikeO
Senior Member

Joined: 11/09/2011
Location: Australia
Posts: 275
Posted: 11:59pm 01 Jun 2017
Copy link to clipboard 
Print this post

Update, I have written a very simple android app now running on my phone to receive the data stream from the Battery Monitor. This has other possibilities as well i think.




Mike
Codenquilts
 
GoodToGo!

Senior Member

Joined: 23/04/2017
Location: Australia
Posts: 188
Posted: 12:18am 02 Jun 2017
Copy link to clipboard 
Print this post

Nice!
...... Don't worry mate, it'll be GoodToGo!
 
expo
Newbie

Joined: 10/01/2016
Location: Australia
Posts: 24
Posted: 02:55pm 02 Jun 2017
Copy link to clipboard 
Print this post

Hello Mike,
Would you post the code for your Android App? I am keen to do something similar and it would be a good reference point for me.
Also what formula did you use to calculate the accumulated Load and Charge AmpHrs?

Regards,

expo
 
MikeO
Senior Member

Joined: 11/09/2011
Location: Australia
Posts: 275
Posted: 05:50pm 02 Jun 2017
Copy link to clipboard 
Print this post

I have made a package of all the files for the project. Some of the code is still a work in progress ie the State of Charge estimations - "lap of the gods" at best.

The monitor could be run without the wifi with just a local or serial fed remote display perhaps but the wifi and mobile phone is my current favorite for checking a battery bank (caravan, solar etc). As it is there is code to install in the ESP8266 running ESPbasic plus program, code for the Explore28 main program and library file. I have included 3D files for the enclosure for the current design.

Here is a listing of the main program but all the files are in the attached Zip file.

@expo the Voltage,Current and AmpHr routines and calculations are towards the end of the listing and are reasonably well commented but please ask if you have any queries.
I have included in the Zip an export of the Android code from the B4A IDE, you can download a trial copy of Basic for Android you should be able to import the files but i think you need to get a full copy to do anything meaningful.

'Battery Monitor for Micromite
'M Ogden June 2017
'http://www.codenquilts.com.au

'Versions
'1.2

Option Explicit
Option Default Integer
Option autorun On
const HalfVccRef=1.65
const mvPerAmp=0.044
const Vcal=4.68
const zeroA=0.1
const SWVer="1.20"
'Variables
dim BatVpin=26 'Battery Voltage
dim BatApin=25 'Battery Current
dim BatTpin=18 'Battery Temperature
dim BatFpin=24 'Battery Fault

Dim Flags(10)

dim BatV as float
dim BatA as float
dim BatT as float
dim TLoadAmps as float
dim AvgLoadAmps as float
dim float LoadAmpHrs,LoadAmpHrs1,LoadAmpHrs2,AmpHrs
dim TChgAmps as float
dim AvgChgAmps as float
dim float ChgAmpHrs,ChgAmpHrs1,ChgAmpHrs2,expired,hrsleft
dim Sample,ChgSample,BatF,msTimer,SOC,backup


setpin(BatVpin),ain
setpin(BatApin),ain
setpin(BatFpin),din


initWiFifile 1 'call initialise WiFi file transfer library, set comm port to use



settick 250, ReadBatt,1
settick 5000, Update,2
settick 3600, SaveToFlash,3
var restore
if MM.WATCHDOG=1 then 'restart due to prog fail
print "BMon "+swver+ " Restart-SW failure ........."
timer=msTimer
else 'normal restart
print "BMon "+swver+ " Normal Startup ........."
timer=0
end if

If backup = 0 Then 'this is a completely fresh startup
backup=1
LoadAmpHrs2=0:LoadAmpHrs1=0:LoadAmpHrs=0:ChgAmpHrs2=0:ChgAmpHrs1=0:ChgAmpHrs=0:amphrs=18:soc=50
var save LoadAmpHrs2,LoadAmpHrs1,LoadAmpHrs,ChgAmpHrs2,ChgAmpHrs1,ChgAmpHrs,AmpHrs,SOC,backup
end if

'Incorporate into main loop
'*** Start User main program loop
Do

Watchdog 8000

'***** mxWiFi Hook ****
if userprocessflag=1 then
StartTime = Timer
UserProcess
UserProcessFlag=0
xbsend "udp.cast:|"+from$+"|"+chr$(4)+"|"
Print "Processing elapsed time"; Timer-StartTime
endif
'***** End mxWiFi Hook ****

loop
'***** End main program loop

'External command processing sub Routine if required
sub extCmd
print "External Commands:- From:";from$;" Cmd:";cmd$;" Config:";cfg$;" Data:";strin$
local temp$,ext$
select case cmd$

case "Log"

case "uMsavetoflash"
SavetoFlash
case "uMusage"

case "uMconfig"

end Select
end sub

sub SaveToFlash
msTimer=timer
backup=1
var save LoadAmpHrs2,LoadAmpHrs1,LoadAmpHrs,ChgAmpHrs2,ChgAmpHrs1,ChgAmpHrs,msTimer,AmpHrs,SOC
end sub

sub update
batT=tempr(battpin)
estsoc
print str$(hrsleft,2,1);" ";str$(batT,2,1);" ";str$(batV,2,1);" ";str$(batA,2,2);" ";str$(loadAmphrs,2,2);" ";str$(ChgAmphrs,2,2);" ";str$(SOC)
xbsend "udp.cast:||,"+str$(hrsleft,2,1)+","+str$(batT,2,1)+","+str$(batV,2,1)+","+str$(batA,2,2)+","+str$(loadAmphrs,2,2)+","+s tr$(ChgAmphrs,2,2)+","+str$(SOC)
end sub

sub EstSOC
print bata
if batA<=-0.3 then 'only calculate if load current > 300mA
print batv
if batv =<11.5 Then soc=10
if batv =<11.6 Then soc=20
if batv =<11.8 Then soc=30
if batv =<11.96 Then soc=40
if batv =>12.10 then soc=50
if batv =>12.24 then soc=60
if batv =>12.37then soc=70
if batv =<12.5 Then soc=80
if batv =<12.62 Then soc=90
if batv =<12.75 Then soc=95
if batv =>12.75then soc=98
else 'charging
if batv>13.5 and bata<amphrs/100 then
soc=99
elseif batv>13.5 and bata<((amphrs/100)*2) then
soc=95
elseif batv>13.5 and bata<((amphrs/100)*3) then
soc=90
else
soc=50
end if
end if
end sub

sub ReadBatt
'StartTime = Timer
local msec
local Etime as float
local AmpSeconds as float
local LbatA as float
local CbatA as float
if pin(batfpin)=0 then 'set Battery Current sense error
flag(0)=1
exit sub
end if
msec = timer ''elapsed time in miliseconds
Etime=msec/1000 'elapsed time in seconds
expired=Etime/3600 'Expired period in Hrs
HrsLeft=24-expired
if etime=>86400 then '24 hrs reached
'save parameters
LoadAmpHrs2=LoadAmpHrs1
LoadAmpHrs1=LoadAmpHrs
ChgAmpHrs2=ChgAmpHrs1
ChgAmpHrs1=ChgAmpHrs
ChgAmpHrs=0:LoadAmpHrs=0
var save LoadAmpHrs2,LoadAmpHrs1,LoadAmpHrs,ChgAmpHrs2,ChgAmpHrs1,ChgAmpHrs
timer=0
exit sub
end if
sample=sample+1
'read battery voltage and current sense
BatV=ReadVoltage(batvpin,vCal,16) 'battery voltage
BatA=ReadCurrent(batApin,HalfVccRef,mvPerAmp,zeroA,16) 'battery Load current
'nb Charge discharge depends on way sensor is wired so may have to invert BatA for display
if sgn(BatA)=0 then 'Zero current
lbatA=0:cbatA=0
elseif sgn(BatA)=-1 then 'Charging battery
cbatA=0:lbatA=abs(BatA)
bata=lbatA 'invert number
else 'discharge battery
cbatA=BatA:lbatA=0
batA=batA-(bata*2) 'invert number
end if
'load current
TLoadAmps=TLoadamps+LbatA 'total load current
AvgLoadAmps=TLoadAmps/sample 'calculate avg load current
ampseconds=AvgLoadAmps*etime 'calculate avg load current/sec
LoadAmpHrs=ampseconds/3600 'calculate load amphours
'charge current
TChgAmps=TChgamps+CbatA 'total Charge current
AvgChgAmps=TChgAmps/sample 'calculate avg load current
ampseconds=AvgChgAmps*etime 'calculate avg load current/sec
ChgAmpHrs=ampseconds/3600 'calculate load amphours
end sub


Function ReadCurrent(InputPin,VoltageOffset as float,Cal as float,zA as float,Smoothing)as float
Local Count
Local Voltage as float
Local AccVoltage as float
For Count = 1 To Smoothing 'take mulpiple reads
Voltage=Pin(InputPin)
AccVoltage = AccVoltage+Voltage
Next Count
'print ((AccVoltage/smoothing)-VoltageOffset)
AccVoltage = ((AccVoltage/smoothing)-VoltageOffset)/cal '
If abs(AccVoltage)<=zA Then accvoltage=0 'trap zero range numbers
Readcurrent=AccVoltage
End Function

Function ReadVoltage(InputPin,Cal as float,Smoothing)as float
Local Count
Local Voltage as float
Local AccVoltage as float
For Count = 1 To Smoothing 'take mulpiple reads
Voltage=Pin(InputPin)
AccVoltage = AccVoltage+Voltage
Next Count
'print accVoltage/smoothing
AccVoltage = (AccVoltage/smoothing)*cal '
If AccVoltage<0 Then accvoltage=0
ReadVoltage=AccVoltage 'trap negative numbers
End Function


2017-06-03_042247_Battery_monitor.zip

MikeEdited by MikeO 2017-06-04
Codenquilts
 
expo
Newbie

Joined: 10/01/2016
Location: Australia
Posts: 24
Posted: 04:13pm 03 Jun 2017
Copy link to clipboard 
Print this post

Thanks Mike. I'm afraid it will take me a while to digest that as "spare" time has to be split many ways at the moment.
Regards,
Greg
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 08:23pm 05 Jun 2017
Copy link to clipboard 
Print this post

That's a nice box Mike. Did you design it yourself? Did you print it yourself?

Can you help with designing and printing boxes for me?

Paul in NY
 
MikeO
Senior Member

Joined: 11/09/2011
Location: Australia
Posts: 275
Posted: 12:09am 06 Jun 2017
Copy link to clipboard 
Print this post

Hi Paul, Yes its my design and print. Sure I can help what did you have in mind. I started myself about a year ago as like with most things I had a specific need. I have to say I am no cad design person but I get by using simple online tools and quite enjoy it when i am able to construct something that has a real purpose.

Mike
Codenquilts
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1664
Posted: 11:18am 06 Jun 2017
Copy link to clipboard 
Print this post

  MikeO said  
Here is a listing of the main program but all the files are in the attached Zip file.
'Battery Monitor for Micromite
'M Ogden June 2017
'http://www.codenquilts.com.au

'Versions
'1.2
settick 3600, SaveToFlash,3
..
..
..
sub SaveToFlash
msTimer=timer
backup=1
var save LoadAmpHrs2,LoadAmpHrs1,LoadAmpHrs,ChgAmpHrs2,ChgAmpHrs1,ChgAmpHrs,msTimer,AmpHrs,SOC
end sub



Is something else controlling the SaveToFlash other than the interrupt?

ATM it will be writing to the chip 24,000 times in a 24 hour period if may maths is correct?

Phil.

Edit:- I can see where you VAR SAVE every 24hrs, (86,400), but nothing to stop the 3600 settick.Edited by Phil23 2017-06-07
 
MikeO
Senior Member

Joined: 11/09/2011
Location: Australia
Posts: 275
Posted: 12:06pm 06 Jun 2017
Copy link to clipboard 
Print this post

One chip dead! Phil. Its supposed to be every hour! missing zeros.

Thanks.
Codenquilts
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2294
Posted: 01:42pm 06 Jun 2017
Copy link to clipboard 
Print this post

is that a version 1A board? if so, the MX170 can possibly be lifted by using solderwick around the edges to remove all the solder. with the QFN packaced MX170 the intention was that the solder would flow under the device and bond the pins down to the pads, but it never quite worked out, and the only attachment (beyond a tind drop of nail varnish underneath the centre) was via the fillets on the edge. this made soldering them a right pain!

this is assuming the chip is completely dead, even after re-flashing. i'd have hoped that wearing out the flash used for saved variables would not prevent the rest of mmbasic from operating.


cheers,
rob :-)
 
MikeO
Senior Member

Joined: 11/09/2011
Location: Australia
Posts: 275
Posted: 02:16pm 06 Jun 2017
Copy link to clipboard 
Print this post

Oh, Oh, I was just being dramatic!!

Its still working , Its only ran for a few hours anyway so it would have not done that many cycles. It was a good observation anyway as I had "carefully considered" that aspect when I settled on every hour as a backup, I remember thinking that @ 24 per day etc that would give at least 5 years use! then I enter the value in seconds instead of mSecs.

It doesn't need an interrupt anyway so i will probably move it and use a MOD instruction.

Cheers Mike.
Codenquilts
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 01:24am 07 Jun 2017
Copy link to clipboard 
Print this post

Hi Mike,

I'm not exactly sure what I had in mind for the box. I've been working on a Geothermal Heating System controller for about a year and the thing is still in flux. The problem is that Geoff and his henchmen keep kicking this thing up to bigger, faster and more sophisticated chips faster than I can figure out what to do with them.

I need to recess a box into a sheetrock wall pocket in the kitchen with a big touch display on the front. It has to take readings from about 14 DS18B20 temperature sensors and 2 hall effect flow sensors and then control about 12 relays. I intend to use pre-fabricated Amphenol cable assemblies to connect to breakout and relay boards in the attic and the cellar and thence to the sensors.

The recessed box in the kitchen wall is the stumbling point for me.

Do you have your own printer? What is the maximum size gizmo that it can print?

Paul in NY
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024