Author Topic: Bash script for logging  (Read 2884 times)

0 Members and 1 Guest are viewing this topic.

commanda

  • Hero Member
  • *****
  • Posts: 731
Bash script for logging
« on: April 11, 2009, 02:23:34 PM »
I built a battery monitoring system using a picaxe and an lcd. It monitors battery voltage, charge current, discharge current, remaining battery capacity, and status (charging, discharging, low battery and float). It dumps this info out the serial port at regular intervals. Will post the whole project after I get the final current sensors built, and test the thing for a few weeks.


In the meantime, here's a little bash script I cooked up which collects the data from the serial port, and writes it to a csv file for later spreadsheeting.  The string from the picaxe already has the commas inserted, and looks like this;


  12.84, -16.8, +0.0, 84, DisCharging

  12.84, -16.8, +0.0, 84, DisCharging

  12.82, -16.8, +0.0, 83, DisCharging

  12.82, -0.0, +41.3, 83, Charging

  12.84, -0.0, +41.3, 84, Charging

  12.82, -0.0, +41.3, 84, Charging


The script adds a timestamp to each record, and the saved filename is date coded. It starts a new file every midnight.


Data in the csv file looks like this;


  16:41:13, 12.84, -16.8, +0.0, 84, DisCharging

  16:43:13, 12.84, -16.8, +0.0, 84, DisCharging

  16:45:13, 12.82, -16.8, +0.0, 83, DisCharging

  16:47:13, 12.82, -0.0, +41.3, 83, Charging

  16:49:13, 12.84, -0.0, +41.3, 84, Charging

  16:51:13, 12.82, -0.0, +41.3, 84, Charging


And here's the script.


#!/bin/bash


stty -F /dev/ttyS0 ispeed 9600 ospeed 9600

stty -F /dev/ttyS0


    NOWTIME=`date +%H:%M:%S`

    NOWDATE=`date +%Y%m%d`

    echo  $NOWDATE $NOWTIME


while true

do

    read LINE < /dev/ttyS0

    NOWTIME=`date +%H:%M:%S`

    NOWDATE=`date +%Y%m%d`

    echo  $NOWTIME"," $LINE

    echo $NOWTIME"," $LINE >> $NOWDATE".csv"

done


Amanda

« Last Edit: April 11, 2009, 02:23:34 PM by (unknown) »

Rover

  • Hero Member
  • *****
  • Posts: 788
Re: Bash script for logging
« Reply #1 on: April 11, 2009, 02:00:31 PM »
Out of curiosity, what are you going to use for current sensors.


This is my monitor, based on a stamp, sounds similar. Using 912Mhz tranceiver to transmit data to the house.


The monitor shows battery voltage, (s1) is solar amps in, (w1) is wind turbine 1 (w1 is down for repairs)amps, (w2) is the second turbine,  (out) is outgoing amps... right now its pumping my little waterfall / stream




« Last Edit: April 11, 2009, 02:00:31 PM by Rover »
Rover
<Where did I bury that microcontroller?>

commanda

  • Hero Member
  • *****
  • Posts: 731
Re: Bash script for logging
« Reply #2 on: April 11, 2009, 04:46:18 PM »
Out of curiosity, what are you going to use for current sensors.


Hall effect sensors (UGN3503) mounted inside a powdered iron  toroid, and an amplifier. Working on a better amplifier so the span and zero pots don't interact (at least, that's the theory at this point). Current sensors each connect to main board via a 3 pin header, so the input board can easily be changed. The unit under test has pots connected at the moment.


And there's a spare analog in already reserved for a wind turbine.

And 3 spare digital I/O's (again, seperate 3 pin header for each).

No RTC.

But it does do charge counting, and shows remaining capacity. Charge efficiency defaults to 80%, but gets incremented or decremented every time the batteries reach float voltage. Again, yet to be tested for real, but the theory sounds good. Doesn't yet account for the fact that efficiency decreases the closer you get to full charge. But an overall average figure should be close enough for most people. It will at least show when efficiency is falling due to ageing batteries.


There is a pushbutton menu system, and the user can set battery capacity, low voltage alarm point, logging interval, and see the efficiency.


Maybe I should invest in some wireless telemetry.


Amanda

« Last Edit: April 11, 2009, 04:46:18 PM by commanda »

Rover

  • Hero Member
  • *****
  • Posts: 788
Re: Bash script for logging
« Reply #3 on: April 11, 2009, 08:26:47 PM »
I'm usng 4 amploc's z25's and am I am dropping to punt too... I 'm replacing with  4 shunts instead ( 50 mv drop). Might just be these amploc units but I'm seeing variance .... not good. I'm no mech or elecetrical engineer, ...pretty good programmer though.


I initially thought it might be my ADC and the temp variance, but my voltage divider feeds through the same ADC and is within 50 mv of my meter (full scale) .


...as far as wireless, I 'm using parallax non addresable units.. (going to swap these out shortly for xbee's since I run more than one set.. and I need to be able to address each unit)

« Last Edit: April 11, 2009, 08:26:47 PM by Rover »
Rover
<Where did I bury that microcontroller?>

commanda

  • Hero Member
  • *****
  • Posts: 731
Re: Bash script for logging
« Reply #4 on: April 11, 2009, 08:49:29 PM »
Do you have enough filtering? Long cable run to the Amploc's might be picking up induced hum, or the carrier from the wireless modules?  You need an RC filter on the ADC inputs.


Amanda

« Last Edit: April 11, 2009, 08:49:29 PM by commanda »

Rover

  • Hero Member
  • *****
  • Posts: 788
Re: Bash script for logging
« Reply #5 on: April 11, 2009, 09:27:01 PM »
The ADC is powered through my stamp ,the power source for which i replaced with a switching 5 volt supply , that is fed through a 12 volt filter ( ok , cheap automotive coil noise type filter), but .. no joke see variance in the 500 mA range since calibratin at  stp  (or as near as I could get it).


I still think going through a good shunt, gets a better measurement... but I'm waiting on on some SOIC board before I test (damn I hate SOIC chips)


As with all things... what I think could be wrong, and usually is

« Last Edit: April 11, 2009, 09:27:01 PM by Rover »
Rover
<Where did I bury that microcontroller?>

domwild

  • Sr. Member
  • ****
  • Posts: 357
Re: Bash script for logging
« Reply #6 on: April 11, 2009, 11:37:04 PM »
Amanda,


Well done! Good to read one of your projects again! Keep 'em coming!


Regards

« Last Edit: April 11, 2009, 11:37:04 PM by domwild »