Programing PICAXE 18X datalooger

Armagon

Member
I?m a beginning in Micontroler chips, I download a Editor program from WEB , It?s great It has wizard to help us to develop programs, I made a program (using wizards data logger option) but I have 2 questions:

1)the picaxe read a light sensor measure (sensor 0) and show measures from 0 to 250, but if we suppose that 0 is 0% and 250 is 100% (presence of light), how I have to modify the program to show in percent % not in range 0-250

2) How can I show in the LCD the number of reading is already taken, this means if we will take 100 readings, the LCD show, 1,2,3?..100 , how I have to modify the program to do that

________
buy iolite vaporizer
 
Last edited:

Michael 2727

Senior Member
Hi Armagon, welcome to the forum.

Here is a very basic 0 to 255 - 0 to 99 converter.
It's not perfect - <A href='http://www.porepunkahps.vic.edu.au/home/jef01/files/display/' Target=_Blank>External Web Link</a>
But you will get the idea.

To count the cycles in your code just include
something like, b1=b1+1 on a line then count
up the total of b1 when you need it.
Use w? for large numbers.
And if you have the new Beta5 Editor you can
now use the &quot; inc &quot; command, it does the
same thing.

Good luck.

PS: It's too early for urgent here -
Coffee hasn't kicked in yet.

Edited by - Michael 2727 on 20/10/2006 23:57:32
 

SD2100

New Member
Try this, for LDR value 0 to 250 it will show 0 to 100%, also shows number of readings taken, it reads the LDR once per second.

Percentage = ldr * 100 / totalvalue
<code><pre><font size=2 face='Courier'>
#picaxe 18x
symbol Percentage = b0
symbol ldr = b1
symbol Readings = b2
symbol TotalValue = 250

Readings=0
serout 7,n2400,(254,1)
pause 30
do
readadc 1, ldr
percentage = ldr * 100 / TotalValue
inc Readings
serout 7,n2400,(254,128,&quot;Reading #&quot;,#Readings)
pause 30
serout 7,n2400,(254,192,&quot;Light = &quot;,#Percentage,&quot;% &quot;)
pause 1000
loop </font></pre></code>

havn't tried this on an lcd so might need some adjustments ???, it works in the simulator with the LCD display thingy.


Edited by - Phil75 on 21/10/2006 08:29:51
 

Armagon

Member
Then, the modification of program is as follow?:


'AXE110 PICAXE-18X - New Datalogger Mission Program
'Automatically generated by Wizard

'LED will flash green as readings are taken.

'Data can be retrieved after mission (LED red) by Datalink tool (F9).
'Use Datalink options: Baud rate - 4800, Sensors - 4, Send G - Enabled

' *******************
' ***** Options *****
' *******************

'Title - Prototipo
'Date - 23/10/2006
'Time - 09:36:10 a.m.

'Options Selected
'Sensors:
'Sensor 0 - Light
'Sensor 1 - Sensor 1
'Sensor 2 - Sensor 2
'Sensor 7 - Temperature

'Memory:
'No of readings = 20
'8 x 24LC256

'Outputs:
'Bi-colour LED
'SPE002 Piezo sounder
'AXE033 Serial LCD

'Logging Period:
'DS1307 RTC
'Hours: 0 Mins: 0 Secs: 1

' ********************
' ***** Symbols *****
' ********************

'Symbol definitions
symbol data0 = b0
symbol data1 = b1
symbol data2 = b2
symbol data7 = b3
symbol top_address = w2 '(b4 + b5)
symbol address = w3 '(b6 + b7)
symbol temp_word = w4 '(b8 + b9)
symbol temp_byte = b10
symbol hours = b11
symbol mins = b12
symbol secs = b13
symbol day = b0
symbol month = b1
symbol COM = 44 'comma
symbol RET = 13 'carriage return
symbol LFEED = 10 'line feed
symbol percentage = b0
symbol ldr = b1
symbol readings = b2
symbol totalvalue = 250
Symbol reading = 0

'Preload sensor names and title into data memory
EEPROM 0,(0,0)
EEPROM 16,(&quot;Light&quot;)
EEPROM 32,(&quot;Sensor 1&quot;)
EEPROM 48,(&quot;Sensor 2&quot;)
EEPROM 64,(&quot;Temperature&quot;)
EEPROM 80,(&quot;Prototipo&quot;)


' ***************************
' ***** Initialisation *****
' ***************************

init:
serout 6,N2400,(254,1) 'clear LCD
pause 30

high 5 ' write protect eeprom
'reload the last address from data memory
read 0,b6
read 1,b7


' *********************************
' ***** Main loop - read data *****
' *********************************

'Now read each sensor
main:
high 3 ' flash LED

readadc 0,data0
readadc 1,data1
readadc 2,data2
readtemp 7,data7

pause 100

low 3 ' end of flash LED

sound 0,(50,50) ' make a piezo beep

' *********************************
' ***** Display values on LCD *****
' *********************************

serout 6,N2400,(254,128,&quot;In0=&quot;,#data0,&quot; &quot;)
serout 6,N2400,(254,136,&quot;In2=&quot;,#data2,&quot; &quot;)
serout 6,N2400,(254,192,&quot;In1=&quot;,#data1,&quot; &quot;)
serout 6,N2400,(254,200,&quot;In7=&quot;,#data7,&quot; &quot;)
readadc 1, ldr
percentage = ldr * 100 / totalvalue
serout 7,n2400,(254,144,&quot;Reading #&quot;,#readings)
serout 7,n2400,(254,208,&quot;Light = &quot;,#percentage,&quot;% &quot;)
pause 30

' *****************************
' ***** Now Save the Data *****
' *****************************

'Now save the data
save_data:
low 5 ' write enable eeprom

'4x 24LC256. Input0 in IC0,4, input1 in IC1,5
'4x 24LC256. Input2 in IC2,6, input7 in IC3,7

if address &gt; 32767 then memory_full
if address &gt; 16383 then save_data_high
i2cslave %10100000, i2cslow, i2cword
writei2c address,(data0)
pause 10
readi2c address,(temp_byte)
if temp_byte &lt;&gt; data0 then ee_error

i2cslave %10100010, i2cslow, i2cword
writei2c address,(data1)
pause 10
readi2c address,(temp_byte)
if temp_byte &lt;&gt; data1 then ee_error

i2cslave %10100100, i2cslow, i2cword
writei2c address,(data2)
pause 10
readi2c address,(temp_byte)
if temp_byte &lt;&gt; data2 then ee_error

i2cslave %10100110, i2cslow, i2cword
writei2c address,(data7)
pause 10
readi2c address,(temp_byte)
if temp_byte &lt;&gt; data7 then ee_error

goto inc_address:

save_data_high:
temp_word = address - 16384
i2cslave %10101000, i2cslow, i2cword
writei2c temp_word,(data0)
pause 10
readi2c temp_word,(temp_byte)
if temp_byte &lt;&gt; data0 then ee_error

i2cslave %10101010, i2cslow, i2cword
writei2c temp_word,(data1)
pause 10
readi2c temp_word,(temp_byte)
if temp_byte &lt;&gt; data1 then ee_error

i2cslave %10101100, i2cslow, i2cword
writei2c temp_word,(data2)
pause 10
readi2c temp_word,(temp_byte)
if temp_byte &lt;&gt; data2 then ee_error

i2cslave %10101110, i2cslow, i2cword
writei2c temp_word,(data7)
pause 10
readi2c temp_word,(temp_byte)
if temp_byte &lt;&gt; data7 then ee_error

'increment address and save in data memory
inc_address:
high 5 ' write protect eeprom

let address = address + 1
write 0,b6
write 1,b7
if address &gt; 1000 then memory_full


' ***********************
' ***** Time Delays *****
' ***********************

'Now do time delay
'Read time now
read_rtc_now:
i2cslave %11010000, i2cslow, i2cbyte
readi2c 0,(secs,mins,hours)

'Convert to decimal then add offset
gosub bcd_decimal

let data0 = secs
let data1 = mins
let data2 = hours

Add_Secs:
let data0 = data0 + 1
if data0 &lt; 60 then Add_Mins
'Secs is now greater than 60 so add 1 to minute instead
let data0 = data0 - 60
let data1 = data1 + 1

Add_Mins:
let data1 = data1 + 0
if data1 &lt; 60 then Add_Hours
'Mins is now greater than 60 so add 1 to hour instead
let data1 = data1 - 60
let data2 = data2 + 1

Add_Hours:
let data2 = data2 + 0
if data2 &lt; 24 then read_rtc
'Hours is now greater than 24 so correct
let data2 = data2 - 24

'Read rtc to test alarm'
read_rtc:
i2cslave %11010000, i2cslow, i2cbyte
readi2c 0,(secs,mins,hours)

gosub bcd_decimal

if secs &lt;&gt; data0 then read_rtc
if mins &lt;&gt; data1 then read_rtc
if hours &lt;&gt; data2 then read_rtc

'now do next reading
goto main


' *************************
' ***** Error Routine *****
' *************************

'Memory error - flash LED red/green'
ee_error:
high 2
low 3
pause 500
low 2
high 3
pause 500
goto ee_error

' ***********************
' ***** Memory Full *****
' ***********************

'Memory is full - LED red'
memory_full:
high 2

' ****************************
' ***** Datalink Routine *****
' ****************************

'Datalink routine to transmit data
read_init:
high 5 ' write protect eeprom
let address = 0

'Get top address from data memory (w2=b4+b5)

read 0,b4
read 1,b5

'Wait for G character sent from software
serin 6, N4800, (&quot;G&quot;) 'Wait for GO signal

'Transmit the titles
serout 7,N4800,(&quot;Address&quot;,COM,&quot;Light&quot;,COM,&quot;Sensor 1&quot;,COM,&quot;Sensor 2&quot;,COM,&quot;Temperature&quot;,COM,&quot;Prototipo&quot;,RET,LFEED)

'Now read the data
read_data:
'4x 24LC256. Input0 in IC0,4, input1 in IC1,5
'4x 24LC256. Input2 in IC2,6, input7 in IC3,7

if address &gt; 32767 then all_done
if address &gt; 16383 then read_data_high
i2cslave %10100000, i2cslow, i2cword
readi2c address,(data0)

i2cslave %10100010, i2cslow, i2cword
readi2c address,(data1)

i2cslave %10100100, i2cslow, i2cword
readi2c address,(data2)

i2cslave %10100110, i2cslow, i2cword
readi2c address,(data7)

goto tx_data:

read_data_high:
temp_word = address - 16384
i2cslave %10101000, i2cslow, i2cword
readi2c temp_word,(data0)

i2cslave %10101010, i2cslow, i2cword
readi2c temp_word,(data1)

i2cslave %10101100, i2cslow, i2cword
readi2c temp_word,(data2)

i2cslave %10101110, i2cslow, i2cword
readi2c temp_word,(data7)

'transmit data
tx_data:
serout 7,N4800,(#address,COM,#data0,COM,#data1,COM,#data2,COM,#data7,RET,LFEED)

let address = address + 1
if address = top_address then all_done
goto read_data

'finished so send NULL
all_done:
serout 7,N4800,(0)
goto read_init


' **********************************
' ***** Convert BCD to decimal *****
' **********************************

'Convert BCD to decimal
bcd_decimal:
let temp_byte = secs &amp; %11110000 / 16 * 10
let secs = secs &amp; %00001111 + temp_byte
let temp_byte = mins &amp; %11110000 / 16 * 10
let mins = mins &amp; %00001111 + temp_byte
let temp_byte = hours &amp; %11110000 / 16 * 10
let hours = hours &amp; %00001111 + temp_byte
return
 
Top