General Weather Station Code Examples

From dataTaker Wiki (FAQ)

Contents

Weather Related Applications

Automatic Weather Station Code

9 am reporting of data

DT80 V9.08 Firmware and latter

Version 9 firmware introduce CRON like schedule triggering which greatly simplifies this task. The schedule can now be triggered at any time of the day or month etc with a simple CRON like expression. For more details please refer to the section on Schedule Triggers in the DT80 range user manual.

BEGIN

RA[0:0:9]  'Trigger schedule @ 0 seconds, 0 minutes, 9 hours
  1HSC(R) 'Report and clear 1HSC
END


DT800 and DT80 Pre V9.08 firmware

Most weather stations report the previous days minimum, maximum and average data at 9.00 am. This code is one method for reporting at 9.00 am. It reads system timer 3 (Hours in the day), subtracts 9 (The hour of the day to report) and saves the result to a CV. This CV is then used to trigger a schedule to report the values and reset the counters when the value of the CV goes to zero.

This code is for the DT800/DT8x loggers

BEGIN

RA1M   'Read schedule A every 1 minute
  1HSC 'Read High speed counter 1
  3ST(=1CV,W)  'Read the hour of the day (0 to 23)
  2CV(W)=1CV-9 'Subtract 9 and save to 2CV. (2CV = 0 at 9 AM)

RB2-CV  'Trigger schedule B when 2CV changes to zero.
  1HSC(R) 'Report and clear 1HSC
END

Wind Gust calculation

This program calculates the 3 second wind gust by using a 3 second moving average and reports the maximum wind gust every 10 minutes. The sensor used in this example was a RM Young Wind Monitor, but it is basically applicable to other pulse or frequency output wind sensors.

BEGIN"Gust"
S1=0,0.1904,0,1"Kts"

RA10M		'Set the reporting speed for the calculated statistical data
	5CV("Gust~Kts")		'Reprot the 3 second maximum gust speed in last 10 minutes
	10CV("Ave~Kts")=6CV/7CV	'Report the average wind speed for the last 10 minutes
	5..7CV(W)=0			'Clear the variables for the above calculations.


RB1S		'Set the sample speed for the calculated statistical data
	3CV(W)=2CV			'Wind speed at T-3 seconds
	2CV(W)=1CV			'Wind speed at T-2 seconds
	1HSC(R,RS,LT,=1CV,S1,W)	'Read the wind speed for the last second
	4CV(W)=(1CV+2CV+3CV)/3 	'Calculate the average 3 second wind speed.
	5CV(W)=5CV*(4CV<=5CV)+4CV*(4CV>5CV)	'Keep the Peak wind speed till 5CV is reset (From schedule A)
	6CV(W)=6CV+1CV		'Calculate sum of the wind speed.
	7CV(W)=7CV+1			'Calculate the number of samples
END

Wind Directions Calculations

Bureau of Meteorology method

This code uses the methods described in the Bureau of Meteorology standards.

Program for monitoring a wind set and calculating;

  • mean wind speed
  • mean wind direction
  • standard deviation of wind speed
  • standard deviation of wind direction

The program assumes that the wind speed and wind direction sensors are; anemometer with output of 0 - 1000 mV for 0 - 50 m/s windspeed wind vane with output of 0 - 1000 mV for 0 - 360 deg wind direction Other types of wind speed and wind direction sensors are easily supported by changing the sensor calibration polynomials and the sensor signal types below.

BEGIN
/D /T  'Turn on automatic time and date stamp of data.

'Define the wind sensor calibrations (Polynomials)
Y1=0,0.050"m/s"                ' Wind speed      0-1000mV = 0-50 m/s
Y2=0,0.360"Deg"                ' Wind direction  0-1000mV = 0-360 deg

'Define units text for calculations (Polynomials with unity scaling)
Y3=0,1"m/s"                    ' Units text for wind speed
Y4=0,1"Deg"                    ' Units text for wind direction

'Clear accumulators used to sum intermediate data (Channel variables)
10..16CV(W)=0

'Schedule to scan wind set and sum intermediate data every 5 seconds
RA5S
  1V(Y1,=1CV,W)                  ' Scan wind speed and save
  2V(Y2,=2CV,W)                  ' Scan wind direction and save
  2CV(W)=2CV/57.29               ' Convert wind direction to radians for Datataker trig functions
  10CV(W)=10CV+COS(2CV)          ' Sum of COS(wd)
  11CV(W)=11CV+SIN(2CV)          ' Sum of SIN(wd)
  12CV(W)=12CV+1CV               ' Sum of ws
  13CV(W)=13CV+(1CV*1CV)         ' Sum of ws * ws
  14CV(W)=14CV+(1CV*COS(2CV))    ' Sum of ws * COS(wd)
  15CV(W)=15CV+(1CV*SIN(2CV))    ' Sum of ws * SIN(wd)
  16CV(W)=16CV+1.0               ' Number of scans
    'Schedule to calculate wind data, and log and return the data every minute

RB1M
  20CV(W)=14CV/16CV              ' Mean ws * COS(wd)
  21CV(W)=15CV/16CV              ' Mean ws * SIN(wd)
    'Calculate and log/display/return mean wind speed
  22CV(W)=SQRT((20CV*20CV)+(21CV*21CV))
  22CV("Mean Wind Speed",Y3,FF2)
    'Calculate and log/display/return mean wind direction
  23CV(W)=ATAN(21CV/20CV)*57.29
    'Find quadrant for mean wind direction
  23CV(W)=23CV+((20CV>0)AND(21CV<0))*360     ' 4th quadrant : +Cos -Sin
  23CV(W)=23CV+((20CV<0)AND(21CV<0))*180     ' 3rd quadrant : -Cos -Sin
  23CV(W)=23CV+((20CV<0)AND(21CV>0))*180     ' 2nd quadrant : -Cos +Sin
  23CV(W)=23CV+((20CV>0)AND(21CV>0))*0       ' 1st quadrant : +Cos +Sin
  23CV(W)=23CV-(12CV=0)*(23CV+1)             ' No wind speed, return -1.0
  23CV("Mean Wind Dirn",Y4,FF2)
    'Calculate and log/display/return standard deviation of wind speed
  24CV(W)=13CV-((12CV*12CV)/16CV)
  24CV(W)=SQRT(24CV/16CV)
  24CV("SD Wind Speed",Y3,FF2)
    'Calculate and log/display/return standard deviation of wind direction
  25CV(W)=10CV/16CV
  26CV(W)=11CV/16CV
  27CV(W)=SQRT((25CV*25CV)+(26CV*26CV))
  27CV(W)=SQRT(-2.0*LN(27CV))*57.29
  27CV("SD Wind Dirn",Y4,FF2)
    'Clear accumulators
  10..16CV(W)=0
LOGON
END
Wind speed and direction using Vector functions

Version 9.08 firmware for the DT80 range introduces vector maths that simplified the above calculations. This code demonstrates the use of vector maths and the new in line C type If Then Else statement.

This code is for wind speed and wind direction only.

BEGIN "WS&WD"
'=================================================================
'
'	Wind speed and direction calculation using Vector functions
'
'	For DT8x range of dataTaker data loggers
'
'	Notes:
'	Requires 9.08 firmware or above.
'	Version 9.08 firmware introduces vector mathematics which
'	greatly simplifies the calculation of wind speed and direction.
'
'	This code also make use of the new C type inline If Then Else statement
'	That was also added in V9.08 firmware
'
'	For assistance in using this code please contact
'	dataTaker technical support or your dataTaker distributor.
'================================================================= 

'=================================================================
'Change the spans to suit your sensor calibrations
'=================================================================
'Define the wind sensor calibrations (Polynomials)
S1=0,50,0,1000"m/s"                ' Wind speed      0-1000mV = 0-50 m/s
S2=0,360,0,1000"deg"               ' Wind direction  0-1000mV = 0-360 deg 

'Clear accumulators used to sum statistical samples
1..3CV(W)=0 

'=================================================================
'Schedule A scans wind set and sum intermediate data every 5 seconds
'
'	Note: All channels are working channels so no data is being logged.
'	If you want data to be logged for diagnostic purposes remove the
'	W channel option.
'=================================================================

RA"Sample"5S 
	'Change channel type to mach out put of Wind Speed sensor
	1V("Raw_WS~m/s",S1,W)									' Read instantaneous wind speed
	Calc("Inst_WS~m/s",W)=(&Raw_WS<0)?0:&Raw_WS				' If WS < 0 then WS = 0 else WS = WS
	
	'Change channel type to mach out put of Wind Direction sensor
	2V("Inst_WD~deg",S2,W)									' Read instantaneous wind direction

	' Vector components for wind speed and wind direction.
	1CV("sumX",W)=1CV+MAGDIR2X(&Inst_WS,D2R(&Inst_WD))		' Sum X component of vector
	2CV("sumY",W)=2CV+MAGDIR2Y(&Inst_WS,D2R(&Inst_WD))		' Sum Y component of vector
	3CV("Num_Samp",W)=3CV+1									' Count number of samples

'Schedule B calculates wind data, and log and return the data every 6 minutes
RB"Report"("b:",DATA:OV:62D)6M
	'Calculate Wind speed and wind direction from vector components.
	Calc("Ave_WS~m/s")=XY2MAG(&sumX,&sumY)/&Num_Samp			' Calculate average wind speed
	Calc("Ave_WD~deg")=(&Ave_WS>0)?R2D(XY2DIR(&sumX,&sumY)):-1	' Calculate average wind direction. If WS = 0 then WD = -1
	1..3CV(W)=0
LogOnB
END
Wind speed, direction and Yamartino method of standard deviation of wind speed

This example builds on the code above to include Standard deviation of wind direction by the Yamartino method.

BEGIN "WSWDSD"
'=================================================================
'
'	Wind speed and direction calculation using Vector functions
'	an Ymartino method to calculate the standard deviation of wind speed.
'
'	For DT8x range of dataTaker data loggers
'
'	Notes:
'	Requires 9.08 firmware or above.
'
'	For assistance in using this code please contact
'	dataTaker technical support or your dataTaker distributor.
'================================================================= 

'=================================================================
'Change the spans to suit your sensor calibrations
'=================================================================
'Define the wind sensor calibrations (Polynomials)
S1=0,50,0,1000"m/s"                ' Wind speed      0-1000mV = 0-50 m/s
S2=0,360,0,1000"deg"               ' Wind direction  0-1000mV = 0-360 deg 

'Clear accumulators used to sum statistical samples
1..3CV(W)=0 

'=================================================================
'Schedule A scans wind set and sum intermediate data every 5 seconds
'
'	Note: All channels are working channels so no data is being logged.
'	If you want data to be logged for diagnostic purposes remove the
'	W channel option.
'=================================================================

RA"Sample"5S 
	'Change channel type to mach out put of Wind Speed sensor
	1V("Raw_WS~m/s",S1,W)							' Read instantaneous wind speed
	Calc("Inst_WS~m/s",W)=(&Raw_WS<0)?0:&Raw_WS				' If WS < 0 then WS = 0 else WS = WS
	
	'Change channel type to mach out put of Wind Direction sensor
	2V("Inst_WD~deg",S2,W)							' Read instantaneous wind direction

	' Vector components for wind speed and wind direction.
	1CV("sumX",W)=1CV+MAGDIR2X(&Inst_WS,D2R(&Inst_WD))		' Sum X component of vector
	2CV("sumY",W)=2CV+MAGDIR2Y(&Inst_WS,D2R(&Inst_WD))		' Sum Y component of vector
	3CV("Num_Samp",W)=3CV+1						' Count number of samples

 	' Components for standard deviation of wind direction (Yamartino method)
	4CV("Sum_Cos_Theta",W)=4CV+Cos(D2R(&Inst_WD))    		' Sum of COS(wd)
	5CV("Sum_Sin_Theta",W)=5CV+Sin(D2R(&Inst_WD))     		' Sum of COS(wd)


'Schedule B calculates wind data, and log and return the data every 6 minutes
RB"Report"("b:",DATA:OV:62D)6M
	'Calculate Wind speed and wind direction from vector components.
	Calc("Ave_WS~m/s")=XY2MAG(&sumX,&sumY)/&Num_Samp			' Calculate average wind speed
	Calc("Ave_WD~deg")=(&Ave_WS>0)?R2D(XY2DIR(&sumX,&sumY)):-1	' Calculate average wind direction. If WS = 0 then WD = -1

	' Calculate standard deviation of Wind speed. (Yamartino method)
	Calc("E",W)=SqRt(1-((&Sum_Sin_Theta/&Num_Samp)^2+(&Sum_Cos_Theta/&Num_Samp)^2))	' Calculate E component
	Calc("SD_WD",W)=R2D(ASin(&E)*(1+0.1547*&E^3))				' Calculate standard deviation of wind direction.
	Calc("Std_Dev_Wnd_Dir")=(&Num_Samp<10)?999:&SD_WD		' If number of samples is less than Then 10 SD Wind = 999

	1..5CV(W)=0	'Clear counters
LogOnB
END

Calculating RH when measuring Wet Bulb and Dry Bulb

This calc could be used on ANY of the dataTaker loggers..

BEGIN
RA1S
 1TK(=1CV,"DryT")
 2TK(=2CV,"WetT")
 3CV("Dryabs",W)=1CV+273.16
 4CV("Wetabs",W)=2CV+273.16
 5CV(W)=-2892.3693/3CV-2.892736*LOG(3CV)/LOG(10)-4.9369728/1000*3CV+5.606905/((10^6)*(3CV^2))-4.645869/((10^9)*(3CV^3))+19.4260451+3.7874/((10^12)*(3CV^4))
 6CV(W)=-2892.3693/4CV-2.892736*LOG(4CV)/LOG(10)-4.9369728/1000*4CV+5.606905/((10^6)*(4CV^2))-4.645869/((10^9)*(4CV^3))+19.4260451+3.7874/((10^12)*(4CV^4))
 7CV("e",W)=10^6CV-0.66*(1CV-2CV)*(1+1.15/1000*2CV)
 8CV(W)=(100*7CV/(10^5CV))*(2CV>0)+(2CV<=0)
 8CV("RH")=(((1CV>=0)AND(1CV<99))*8CV)+((1CV<0)OR(1CV>=99))
END

Calculating rain fall rate with a tipping bucket rain gauge

To calculate the rain fall rate we need to know the time when the bucket tipped. The digital inputs can be used as counters and to trigger a schedule to execute.

This code uses digital input 1 to trigger the schedule and count the number of tips of the bucket. The data is date and time stamped with the /D/T switches.

BEGIN"RainRate"
Y1=0,0.1"mm" 'Rain gauge calibration (0.1 mm per tip)
/D  'Date stamp the data
/T  'Time stamp the data
RA1-E  'Trigger schedule A when the bucket tips
    1C(Y1) 'Read the counter
END

Calculating rain fall rate with a tipping bucket rain gauge and allowing sleep mode

The DT500 and DT80 both have a wake terminal. Then this terminal in pulled low the dataTaker will wake up from sleep mode. In this example the WK terminal is linked to 1 High Speed Counter (1HSC). When the High Speed Counter changes from 0 to 1 the schedule is triggered and the bucket volume is accumulated in 1 CV.


BEGIN
/D
/T
1CV=0
RA1HSC(1)
	1CV("Rain rate")=1CV+0.1
END

Weather Sensors

Gill Wind sensors

Gill R3-50 High speed wind sensor

This program reads the ASCII output of a Gill R3-50 High speed 3 dimensional wind ultrasonic wind sensor.

BEGIN"Gill"
PS=115200,N,8,1,NOFC    'Define serial sensor port comms parameters.
1SERIAL(RS422,"\\e",W)  'Clear Input buffer.

RA1SERIAL"^B"           'Trigger schedule on STX char
1SERIAL(RS422,"^B%2d[1CV],%2d[2CV],%f[3CV],%f[4CV],%f[5CV],%f[6CV],%f[7CV],%f[8CV]\\e",2)
   1CV("StaA")
   2CV("StaB")
   3CV("Wc1 ~m/s")
   4CV("Wc2 ~m/s")
   5CV("Wc3 ~m/s")
   6CV("C")
   7CV("T")
   8CV("A1 ~V")
LOGON
END
Gill Windmaster 3D wind sensor

Applies to DT8x

This program reads the ASCII output of a Gill Windmaster 3 dimentional wind ultrasonic wind sensor.

BEGIN"WINDMSTR"
'This program reads Mode 2 ASCII, Polar, Continuous data output from a Gill Windmaster anemometer 
'using RS422 comms at 19200,8,N,1, and logs output.
'Windmaster config string is M2,U1,O2,L1,P1,B4,H1,NQ,E1,T1,S1,C2,A1,I1,J1,V1,X1,G0,K50
'This is default mode except O2 is set for fixed format output for ease of parsing by DT80.
PS=RS422,19200,N,8,1,NOFC    'Define serial sensor port comms parameters.
1SERIAL(RS422,"\\e",W)  'Clear Input buffer.
P41=0 'no extra decimal places on seconds in time output
'/T/n/C/D/h/i P33=8 'Use this string for ASCII output with units from DT80
/n/c/u P22=44 P24=13 P33=0 'Use this string for comma delimited output from DT80
'Comma delimited format is DD/MM/YYYY,HH:MM:SS.S,A,DDD,M.MM,W.WW,UU,X
'Where A=Serial data state (0 is OK);DDD=Dirn;M.MM=Wind Magnitude;W.WW=W axis 
'velocity;UU=Units(decimal representation of ASCII code);X=Windmaster Status (0 is OK)
RA1SERIAL"^BQ" 'Trigger serial schedule on receipt of <STX>Q at start of Gill output string. 
               'Q is the default node address of the Windmaster (NQ in config string).
  1SERIAL(",%d[1CV],%f[2CV],%f[3CV],%c[4CV],%x[5CV],^C")
    1CV("Dirn:           ~deg",FF0)
    2CV("Wind Magnitude: ~",FF2) 'Units as per identifier in 4CV
    3CV("W axis Velocity:~",FF2) 'Units as per identifier in 4CV
    4CV("Units:          ",FF0) 'm/s=M(77);knots=N(78);mph=P(80);kph=K(75)
    5CV("Status Code:    ",FF0) 'Typically 0 for good data
LOGON
END
Gill Windsonic ultrasonic wind sensor

Applies to DT8x

This program reads the NMEA-0183 output of a Gill Windsonic ultrasonic wind sensor. It may also be used for other anemometers with a NMEA-0183 MWV sentence output.

BEGIN"NMEAWIND"
'This program reads NMEA-0183 MWV sentance data from a Gill Windsonic anemometer using RS422 comms at 
'4800,8,N,1, and logs wing speed and direction.
'Use windsonic config string as follows: M5,U1,O2,L1,P1,B2,F1,H1,NQ,E1,T1,S3,C2
/T/N/D/U P33=15 'Output formatting
PS=RS422,4800,N,8,1,NOFC    'Define serial sensor port comms parameters.
1SERIAL(RS422,"\\e",W)  'Clear Input buffer.
RA1SERIAL"$IIMWV"
  1SERIAL(",%d[1CV],R,%f[2CV],%c[3CV],%c[4CV]*")
    1CV("Dirn:~deg",FF0) 'Wind direction in degrees
    2CV("Spd:~",FF2) 'Wind speed (units are specified in 3CV)
    3CV("Units:",FF0) 'm/s=M(77);knots=N(78);mph=P(80);kph=K(75)       
LOGON
END

Vaisala sensors

Vaisala WTX510 and WXT520 Weather transmitter (ASCII)

Applies to DT8x and DT800

This code is to read a Vaisala WTX510 Weather transmitter configured for ASCII output.

BEGIN
1SSPWR=1
/T
PS=19200,N,8,1,NOFC
1SERIAL(RS232,"{\\e}")
RA10S
   1SERIAL(RS232,"\\e{0R1\\013\\010}\\m[,Dm=]%f[1CV],%*3S%f[2CV],%*3S%f[3CV],%*3S%f[4CV],%*3S%f[5CV],%*3S%f[6CV]",2,W)
   1SERIAL(RS232,"\\e{0R2\\013\\010}\\m[,Ta=]%f[7CV],%*3S%f[8CV],%*3S%f[9CV],%*3S%f[10CV]",2,W)
   1SERIAL(RS232,"\\e{0R3\\013\\010}\\m[,Rc=]%f[11CV],%*3S%f[12CV],%*3S%f[13CV],%*3S%f[15CV],%*3S%f[16CV],%*3S%f[17CV]",2,W)
   1CV("Wind Dir Min ~Deg")
   2CV("Wind Dir Ave ~Deg")
   3CV("Wind Dir Max ~Deg")
   4CV("Wind Speed Min ~m/s")
   5CV("Wind Speed Ave ~m/s")
   6CV("Wind Speed Max ~m/s")
   7CV("Air Temp ~DegC")
   8CV("Humidity ~%RH")
   9CV("Air Pressure ~hPa")
   11CV("Rain Amount ~mm")
   12CV("Rain Duration ~Sec")
   13CV("Rain Intensity ~mm/h")
   15CV("Hail Amount ~Hits/cm^2")
   16CV("Hail Duration ~Sec")
   17CV("Hail Intensity ~Hits/cm^2h")
END
Vaisala HMP45A

Applies to DT8x and DT800

This code reads the 0 to 1 VDC analog output of an HMP45A and scales the data to Temperature and Humidity

BEGIN

S1=-40,60,0,1000"DegC"    'Scale for Temperature : -40 DegC = 0 mV, 60 DegC = 1000 mV
S2=0,100,0,1000"%RH"      'Scale for humidity : 0 %RH = 0 mV, 100 %RH = 1000 mV

RA10S LOGONA
   1V(S1,"Temperature")   'Connect Temperature output between +/- Channel 1 and use span 1 (S1) to scale 
   1*V(S2,"Humidity")     'Connect Humidity output between */# channel 1 and use span 2 (S2) to scale.
END

Optical Scientific Inc - LOA 105 Optical Anemometer (Harsh Industrial Environment)

OSI LOA-105-xR DT8x/800 code currently untested Note: If you are to send this code to the logger with DeTransfer you will need to replace the \ characters with \\, as DeTransfer interprets the \ as the start of a DeTransfer command so to get DeTransfer to send a single \ you have to provide it with \\. This a wind speed and direction sensor by Optical Scientific industries. They are designed specifically for the Aluminum Plants. Using an optical technique it will operate in high EMF and dirty environments as found in Aluminum Smelters.

BEGIN"LOA 105"
PS=RS232,1200,N,8,1,NOFC   
1SERIAL("\\e")        
RA10S
    1SERIAL(RS232,"{A}",=99CV,W)
' Read Wind Speed  10CV
    1SERIAL(RS232,"W%5f",3,=10CV)
' Read Turbulance  11CV
    1SERIAL(RS232,"C%9f",=11CV)
' Read A detector level 12CV
    1SERIAL(RS232,"A%4f",=12CV)
' Read B detector level 13CV
    1SERIAL(RS232,"B%4f",=13CV)
' Read System Status 14CV
    1SERIAL(RS232,"B%4x\\e",=14CV)  
END
Views
Personal tools