projects:electronics:dualpressuresensor

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
projects:electronics:dualpressuresensor [2014/11/13 10:50] – external edit 127.0.0.1projects:electronics:dualpressuresensor [2014/11/13 14:12] (current) photonicsguy
Line 52: Line 52:
  
 http://www.chrisgood.com/uav/avionics/airspeed_slide0024.htm http://www.chrisgood.com/uav/avionics/airspeed_slide0024.htm
- 
-== gnuplot == 
-Perl logging script 
----- 
-<code perl> 
-#!/usr/bin/perl -w 
- 
-use DateTime::Format::Excel; 
-use DateTime; 
- 
-$pidfile="/root/baro/barolog.pid"; 
-$csvfile="/root/baro/log/barometer.csv"; 
-$gnpfile="/root/baro/log/barolog.gnp"; 
-$logfileshort="/root/baro/log/barolog-"; 
-$device="/dev/ttyUSB0"; 
- 
-open(FILE, ">".$pidfile); 
-print FILE $$; 
-close(FILE); 
- 
-open(CSV,  ">>".$csvfile); 
-print CSV "\n"; 
-close(CSV); 
- 
-($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); 
-$syear=substr($year,1,2); 
-$year+=1900; 
-$mon++; 
-$logfile=$logfileshort.$syear.$mon.$mday; 
-#print "Logfile: $logfile\n"; 
- 
- 
-$dt = DateTime->new( year => $year, month => $mon, day => $mday); 
- 
-open(USB, "<".$device); 
- 
-while (1) { 
- $curhour=$hour; 
- $qtr=1+int($min/15); 
- $curqtr=$qtr; 
- $dt = DateTime->new( year => $year, month => $mon, day => $mday); 
- $count=0; 
- $avgtally=0; 
- 
- print "Opening $device\n"; 
- while (<USB>) { 
- ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); 
- $mon++; 
- $year+=1900; 
- $qtr=1+int($min/15); 
- $dt = DateTime->new( year => $year, month => $mon, day => $mday); 
- 
- if($curqtr==$qtr) { 
- } else { 
- $average=$avgtally/$count; 
- $pressure=(($average/1023)+0.095)/0.009; 
- $pressure = sprintf("%g", $pressure); 
- print "$baro, "; 
- $oldcount=$count; 
- $count=0; 
- $avgtally=0; 
- # Print Average here 
- $logfile=$logfileshort.$syear.$mon.$mday; 
- 
- open(LOG, ">>".$logfile); 
- print "Pressure for $hour.$qtr: $pressure kPa\n"; 
- $quarter=15*int($min/15); 
- print LOG "$hour.$quarter $average $pressure\n"; 
- close(LOG); 
- 
- $now=time(); 
- $foravg=sprintf("%g", $average); 
- open(GNP, ">>".$gnpfile); 
- print GNP "$now $pressure $foravg $oldcount\n"; 
- close(GNP); 
- 
- $excel = DateTime::Format::Excel->format_datetime( $dt ); 
-# print "Hour: $hour\tQuarter: $quarter\n"; 
- $exceltime=($hour/24)+($quarter/1440); 
-# print "Excel: ".($excel+$exceltime)."\n"; 
- open(CSV,  ">>".$csvfile); 
- print CSV $excel+$exceltime; 
- print CSV ",$pressure"; 
- print CSV ",".sprintf("%g", $average); 
- print CSV ",$oldcount"; 
- print CSV "\n"; 
- close(CSV); 
- 
- $dt = DateTime->new( year => $year, month => $mon, day => $mday); 
- $curhour=$hour; 
- $curqtr=1+int($min/15); 
- 
- } 
-# if($count==6) { 
-# $curqtr++; 
-# } 
- 
- $count++; 
- @baro=split(/ /,$_); 
- $baro=$baro[1]; 
- $avgtally+=$baro; 
- } 
- sleep(1); 
-} 
-</code> 
-Gnuplot 
----- 
-<code gnuplot> 
- 
-set terminal png size 800 
-set title "PIC18F based Barometer\nhttp://photonicsguy.ca/projects/electronics/dualpressuresensor" 
-set nokey 
-#set xlabel "Date\nTime" 0,-1 
-set grid 
-set xrange [1226454300:] 
-set bmargin 3 
-set ylabel 'Pressure (kPa)' 
-set xdata time 
-set timefmt "%s" 
-set format x "%b-%d\n%H:%M" 
-set xlabel "Date" 
- 
-plot\ 
-'/root/baro/log/barolog.gnp' using ($1-(5*3600)):2 ti "Values" with impulses lt 2,\ 
-'/root/baro/log/barolog.gnp' using ($1-(5*3600)):2 ti "Barometer" with lines lt 3 lw 3 
- 
-</code> 
-<HTML> 
-<IMG SRC="http://photonicsguy.ca/sqlfile.php?id=1"> 
-</HTML> 
  
 ---- ----
  • projects/electronics/dualpressuresensor.txt
  • Last modified: 2014/11/13 14:12
  • by photonicsguy