; =========================================================================
; File....... MiniWeather
; Purpose.... PICAXE 08M based weather station to measure the temp, humidity and light level and then
; store data for later transfer to a PC via the Prog Editor Datalink function for viewing in Excel
; After a recording mission, once the data has been transferred to the PC,
; MUST turn power Off and back On for a new "mission"
;
; Author..... Westaust55
; Written.... 2-05-2009
;
; =======================================================================
;The formula for RH% is: RH(%) = (Offset-Soh) * Sens /(2^12) 2^12 = 4096
;
;
#PICAXE 08M
;
; IO DEFINITIONS
;
SYMBOL temp = 4 ; using a DS18B20 temperature sensor (available from MicroZed)
SYMBOL humid = 3 ; using a HOPERF HH10D Humidity Sensor (available from MicroZed)
SYMBOL ldres = 2 ; Using a Jaycar supplied LDR Cat No RD3485
; Dark resistance: 0.5M ohm min.
; Light resistance: 2.8K ohm min 8.4K ohm max.
SYMBOL ULoad = pin1 ; switch - low to record and when memory full a high to initiate transfer to PC
SYMBOL spare = 0 ; pin 0 = output only - used for SERTDX suggest do not use elsewhere
;
; VARIABLE DEFINITIONS
;
SYMBOL light = b0 ; holds the current light level as measured by the LDR
SYMBOL degC = b1 ; holds the current temperature as measured by the temp sensor
SYMBOL axefactr = b2 ; a scaled factor to prevent overflow in the maths to calculate humidity
SYMBOL addr = b3
SYMBOL Soh = w2 ; w2 = b5:b4 = the frequency from the humidity sensor
SYMBOL diff = w3 ; w3 = b7:b6 = intermediate value used in humidity calculations
SYMBOL RH = w4 ; w4 = b9:b8 = the relative humidity value
SYMBOL timr = b10
;
;
; CONSTANTS
;
SYMBOL COM = 44 ; ASCII value for a comma
SYMBOL RET = 13 ; ASCII value for a carriage return
SYMBOL LFEED = 10 ; ASCII value for a line feed
;
SYMBOL Offset = 7762 ; HH10D module 1 calibration constant
SYMBOL Sens = 340 ; HH10D module 1 calibration constant
;
SYMBOL mins = 1 ; Minutes between each reading
SYMBOL basetime = 58800 ; Basic increment of time set for 1 minute min period
; NOTE: using 58,800 not 60,000 to account for time reading in data each interval
SYMBOL space = 50 ; max space for data storage typ = space bytes -2 bytes
; PICAXE-08M EEPROM memory available = 0 to (255 - number of used bytes)
; Actual is 56 bytes 54 / 3 = 18 complete (3-byte) slots for data
;
; =========================================================================
; MAIN PROGRAM
; =========================================================================
;
Init:
; First check if there is data in memory still to download
READ addr, light ; read the first memory location. If zero, then clear for new mission
IF light > 0 THEN Download ; if not clear then get ready to download to PC
;
; here waiting for the switch to be changed to low to intiate data recording
DO
LOOP UNTIL Uload = 0 ; wait for switch to be moved to the Record/Logging position
; here to start recording weather data at the defined intervals
Record:
;
; Step 1 = Fetch the current weather data
READADC ldres, light ; read the relative light level value
READTEMP temp, degC ; read the temperature in Degrees C.
COUNT humid, 1000, Soh ; read the frequency (ie cycles in 1 second)
diff = Offset - Soh
axefactr = diff / 19 + 1 ; a factor to prevent number roll over error (ie >65535)
RH = 10 * diff / axefactr * Sens ; intermediate result (multiply by 10 is to enable 0,1 resolution later if required)
axefactr = 4096 / axefactr ; a factor to prevent number roll over error
RH = RH / axefactr / 10 ; final value for RH% - divided by 10 (for now) as not transmitting fractional
;
; Step 2 = Store the current weather data values for 1 record
WRITE addr, light ; save the light level value
INC addr
WRITE addr, degC ; save the temperature value
INC addr
WRITE addr, RH ; save the humidity value
INC addr
IF addr > space THEN Download ; branch from data collection when the allocated memory is full
; Step 3 = Wait for time interval to next reading
FOR timr = 1 to mins ; loop for the specified number of basic time periods
PAUSE basetime ; pause for the basic period of time
NEXT timr
GOTO Record ; continue to take weather readings
;
;
; Here when memory is full and ready to download to the PC
Download:
;
; Step 1 = Turn on LED, set up pointers, then wait for signal to transfer
HIGH 0 ; turn on the LED to indicate when recording phase is finished
Addr = 0 ; reset address pointer for data
Timr = 0 ; reset timer as record counter
DO
LOOP UNTIL Uload = 1 ; wait for command (switch) to transfer the data
LOW 0 ; Turn off LED
;
;Step 2 = Transmit the titles
SERTXD("Record", COM, "Light", COM, "Temp.", COM, "Humidity", RET, LFEED)
;
NuLine:
; Step 2 = retrieve the saved data for 1 record
IF addr > space THEN Finished ; branch from data transfer when all data has been sent
READ addr, light ; fetch the light level value
INC addr
READ addr, degC ; fetch the temperature value
INC addr
READ addr, RH ; fetch the humifity value
INC addr
INC timr ; advance the time interval counter
; Step 3 = Transmit the weather data for 1 record
SERTXD (#timr, COM, #light, COM, #degC, COM, #RH, COM, RET, LFEED)
PAUSE 50 ; allow a short pause for the data to be handled at the PC
GOTO Nuline
Finished:
; delete the next line to gain 3 exta bytes for data storage but will get a time-out in Datalink
; instead of the proper completion message - but still works okay.
;
SERTXD (0) ; send a null to indicate to Datalink transfer is complete
WRITE 0,0 ; clear first memory location to indicate download was done
;
;
; =========================================================================
; THE END
; =========================================================================