'DATALOG program for September "Silicon Chip" Picaxe-08 article. Ver 1.03 6/09/03 'NB-check enhanced PICAXE-18A /DS18B20 version=> www.picaxe.orcon.net.nz/datads18.bas 'Use with attached 100k thermistor etc pin 1. Via Stan.SWAN => s.t.swan@massey.ac.nz 'When "08" powered up,any prior stored EEPROM values sent as pin 4 serial port data 'Display this gathered data via any terminal program -LCD,BananaCom,F8,StampPlot etc. 'If saved via a terminal program,the ".csv" data can of course be Excel graphed too 'NB-Gives you 30secs to turn unit OFF before fresh storage begins & thus wiping old ! '***** CARE - BE PROMPT ! REPROGRAMMING/RELOADING "08" TOTALLY WIPES DATA TOO ******. 'As set up logs temp in 0-30 C range every min for 1 hr.WAIT more accurate than SLEEP? 'Tweaking V divider network Rs may allow narrower temp range.Alter 47k to 100k maybe 'Picaxe 18A should run this OK too, but give high res readings & store 256 values.Yah! '------------------------------------------------------------------------------------- 'Picaxe data storage value range 0-255,although only to 160 via "08" readadc of course. 'EEPROM builds up from location 0,but program builds down from 128. Just 61 bytes used 'Basic EEPROM syntax is ex. EEPROM (13,7,19,69 ) where bytes 13,7,19,69 EEPROM stored 'at locations 0,1,2,3. Code use READ & WRITE to access this data at these spots maybe 'To retain program simplicity & maximise number of readings, data can not be viewed as 'gathered.In practise this should not be an issue, since data logger likely to be used 'stand alone/ outdoors etc, then retrieved to display values back at an indoor PC etc. 'N.B.SLEEP not 1:1,as unit=2.3 secs.Elapsed times ~x2 expected.By trial SLEEP 25=1 min 'Stored values are non volatile - thus no need battery backup connection once gathered 'PIC makers (Microchip) say data retained in EEPROM >40 years unless overwritten.Bravo 'Typical (baby Wish board!) hardware setup pix=> www.picaxe.orcon.net.nz/datalog8.jpg 'With sample Excel graph resulting (1 hour run)=> www.picaxe.orcon.net.nz/datalog8.gif ' ****** Download this program via => www.picaxe.orcon.net.nz/datalog8.bas <= ****** '------------------------------------------------------------------------------------- 'ASCII art schematic Typical temp. readings/readadc values ' - - - - - - -ve rail 0 Celsius 11 ' Piezo _____ Pin | | 4 21 ' Pin 0 ___ | 2 LED 47k 8 32 ' ------ | |_______| | 12 43 ' |Picaxe| |_______________| 16 53 ' | 08 | Pin 1 ADC | 20 64 ' ------ 100k 24 75 ' |______Pin 4 NTC 28 86 etc ' ||| serout | 3-5 V 'Usual 3 wire + + + + + + +ve supply NOTE - Temp values approximate 'prog.input & may need better calibration '--------------------------------------------------------------------------------------- 'READ/PLAYBACK ROUTINE serout 4,n2400,(12,"Datalog ") 'ASCII values 10=CR, 12=FF(=cls),13=LF, 44=comma for b0= 0 to 63 'stored data values readout to terminal or LCD read b0,b1 'polls & reads out stored eeprom values ( .csv) serout 4,n2400,(44,#b1) 'comma,then value @ pin 4. LED to show data too? next b0 'read next stored EEPROM value out wait 30 '30 secs "reading" delay -modify if too short etc '---------------------------------------------------------------------------------------- 'WRITE/DATA LOGGING ROUTINE for b0= 0 to 63 'begin 64 data readings at time set by SLEEP sound 0,(75,10) 'Beep to alert data logging commencing pulsout 2,500 'brief flash from pin 2 LED indicates datalogging readadc 1,b2 'b2 has 16 blocks 11 wide (range 0-160),so 21 etc write b0,b2 'sequentially write values to EEPROM locations sleep 25 '25x2.3secs ~1 min delay (+/- 1% )-alter to suit next b0 'Ex. Sleep 782 yields 64 x 1/2 hr =32 hrs data! 'Data gathering stops when 64 readings taken '---------------------------------------------------------------------------------------- Revision history: 1.02 24th July 2003 Original as published Sept SiChip 1.03 6th Sept 2003 Added extra material ( below) + pointer to 18A version UPDATES & EXTRA MATERIAL - you only need copy & paste the program above of course ! ---------------------------------------------------------------------------------------------- NOTE: This program has been enhanced for the October(?)/November "Silicon Chip" to use a PICAXE-18A with a DS18B20 digital temp. sensor to give 256 direct Celsius readings. Refer my => www.picaxe.orcon.net.nz/datads18.bas <= listing for pix & circuits etc (or the mag. itself ?) EXTRA: The following "data packing" technique has just been suggested by Jeff Hinwood --------------------------------------------------------------------------------------------- I altered Stan's data logging routine (Sept Silicon Chip) to take readings from two probes every 5 minutes and pack the data into 1 byte for recording. This gives 128 saved readings or 3 hours of data at 2 samles per 5 minutes. There's a leak in the 25 metres of plumbing to my garden fountain. When I run it, the pond slowly drains. To save digging up the garden and paths which now cover the pipes I decided to use Stan's datalogger to look for lower ground resistance. I put 2 pairs of metal probes at likely places connecting them by diodes to port 1 of picaxe with a pull-down resistor of half a meg. I powered the probes via 10k resistors from port 2 and 4. I had to rem out ( with ; ) some of the original code to squeeze in the packing function. symbol piezo = 0 symbol probe1 = 2 symbol probe2 = 4 ;serout 0,n2400,("DataLogger") ;no room for program name loop: for b0=0 to 63 read b0,b1 ;put 2 chars into b1 serout 0,n2400,(44,#b1) ;send comma & data byte to PC and piezo next b0 wait 30 ;about to record in 30 sec ;sound 0,(120,200) ;no room for warning but will hear serout for b0=0 to 63 ;sound piezo,(75,10) ;no room switch on probe1 pause 500 ;let probe stabilise for half a second readadc 1,b1 switch off probe1 b1=b1/10 max 15 ;get 4 bit character switch on probe2 pause 500 ;wait half a second readadc 1,b2 switch off probe2 b2=b2/10 max 15 *16 +b1 ;pack chars, probe2 is upper char write b0,b2 ;save in EEPROM sleep 130 ;wait 5 minutes, 130 * 2.3 secs next b0 To unpack data, I paste the input buffer of the comms routine into excel and parse the data into columns using the comma as a separator. The upper byte is given by int(cell/16) and the lower byte by mod(cell,16). Thanks Stan for a useful application. Jeff. --------------------------------------------------------------------------------------------