Shop OBEX P1 Docs P2 Docs Learn Events
Mutiple sensor Logger to sd card HELPPPPPPPPPPPPPPP — Parallax Forums

Mutiple sensor Logger to sd card HELPPPPPPPPPPPPPPP

Igor_RastIgor_Rast Posts: 357
edited 2011-03-25 14:58 in Propeller 1
hi there , I am a fairly new to the propeller , got some electronic experiences but that aged away a little
Im working on a project to get multiple sensors logged to a excel format , so I can make a nice graph of it

now i have a problem

when I run the code like the one below :

PUB main |mount

cognew(getgeto,@stack)

mount := \sdfat.mount_explicit(DO, CLK, DI, CS)
if mount < 0
abort

sdfat.popen(string("test.csv"),"w")

repeat aa from 0 to 25

waarde1:=fp.floattostring(f.fmul(f.ffloat(waarde),co))

sdfat.pputs(waarde1)
sdfat.pputs(string(" ",13,10))

PUB getgeto

adc.start(24, 20, 21, 22, 23)
repeat
waarde :=adc.getdata(6)


I get a nice collum in ecxel , with 26 values of waarde1

this part is good

But i want to log multiple sensors, so

I wanna have something like
sdfat.pputs(waarde1,waarde2 ,waade 3 etc)
sdfat.pputs(string(" ",13,10))

but this does not work .
if I do sdfat.pputs(string("waarde1,waarde2",13,10))
than i wil make 2 collums like I want in the excel file , but than it would ste waarde1 in the collum not the valvue of waarde 1

the object i use for the sd card is :
fsrw 2.6 Copyright 2009 Tomas Rokicki and Jonathan Dummer
and I use a gangster gadget propeller usb platform

hope anyone can help me to get the multiple data logged into one excel file

Comments

  • Mike GMike G Posts: 2,702
    edited 2011-01-27 05:34
    Igor_Rast; 10 13 is a Windows line terminator, return line feed. Column items are separated by a comma. If you are trying to write a string, then you need to send a pointer to the string. Pointers start with an "@" sign. A string is an array of values that is terminated with a zero. It looks like pputs() will handle a string.

    Main
     WriteColumn(@myStringPointer) 
     WriteColumn(string("My Text") )
    
    PUB WriteColumn(value)
     sdfat.pputs(value)
     sdfat.pputs(string(","))
    
    PUB WriteEndOfRecord(value)
     sdfat.pputs(value)
     sdfat.pputs(string(" ",13,10))
    
  • MagIO2MagIO2 Posts: 2,243
    edited 2011-01-27 07:08
    As we don't have dynamic memory management, you have to do this in a sequence - which means convert value and write, convert next value and write ....
    In opposite convert value1, convert value2 ... convert last value and the write all won't work.

    The fp.floattostring is using one buffer for it's conversion and returns the address of this buffer. If you call it twice, the first conversion result will be overwritten.

    So, what you have to do:
    waarde1 := fp.floattostring( .. value 1 .. )
    sdfat.pputs( waarde1 )
    sdfat.pputs( string( "," ) )
    waarde1 := fp.floattostring( ... value 2 .. )
    sdfat.pputs( waarde1 )
    sdfat.pputs( string(",") )

    just to give you the first quick and easy programming for better understanding.

    Next step is use functions as described by Mike G:
    WriteColumn( fp.floattostring( ... value1 ... ) )
    WriteColumn( fp.floattostring( ... value2 ... ) )
    ...
    WriteEndOfRecord( fp.floattostring( ... value last ... ) )
  • Igor_RastIgor_Rast Posts: 357
    edited 2011-01-29 10:14
    Thank you Very much Guy's
    Ive just gave it a tweak and it works , makes my day
    Need some more experience to see those thing
    finally I can log the temp


    Thankss
  • Igor_RastIgor_Rast Posts: 357
    edited 2011-03-25 06:58
    ive tyried to get it working , but now with the sensors it will not create 5 difrent rows in excel but groups of 5 in the same row,
    please help me to get it right


    }}

    CON
    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000

    MAX_DEVICES = 5
    Do = 0
    CLK = 1
    DI = 2
    CS = 3




    OBJ
    debug : "tv_text"
    ow : "SpinOneWire"
    f : "FloatMath"
    fp : "FloatString"
    sdfat :"fsrw"

    VAR
    long addrs[2 * MAX_DEVICES]
    word waarde1
    PUB start | i, numDevices, addr,mount

    debug.start(12)
    ow.start(10)
    mount := \sdfat.mount_explicit(DO, CLK, DI, CS)
    if mount < 0
    abort

    sdfat.popen(string("444444.csv"),"w")

    repeat 10
    numDevices := ow.search(ow#REQUIRE_CRC, MAX_DEVICES, @addrs)

    debug.str(string($01, "-- Gringo's Datalogger --", 13, 13, "Devices:"))

    repeat i from 0 to MAX_DEVICES-1
    debug.out(13)

    addr := @addrs + (i << 3)
    readTemperature(addr)
    sdfat.pputs(waarde1)
    waitcnt(clkfreq +cnt )
    sdfat.pputs(string(" "))
    sdfat.pputs(string(" , "))
    sdfat.pputs(string(" "))

    sdfat.pputs(string(" ",13,10))

    sdfat.pclose
    sdfat.unmount

    pub readTemperature(addr) | temp, degC, degF
    '' Read the temperature from a DS18B20 sensor, and display it.
    '' Blocks while the conversion is taking place.
    ow.reset
    ow.writeByte(ow#MATCH_ROM)
    ow.writeAddress(addr)

    ow.writeByte(ow#CONVERT_T)

    ' Wait for the conversion
    repeat
    waitcnt(clkfreq/100 + cnt)

    if ow.readBits(1)
    ' Have a reading! Read it from the scratchpad.

    ow.reset
    ow.writeByte(ow#MATCH_ROM)
    ow.writeAddress(addr)

    ow.writeByte(ow#READ_SCRATCHPAD)
    temp := ow.readBits(16)

    ' Convert from fixed point to floating point
    degC := f.FDiv(f.FFloat(temp), 16.0)

    ' Convert celsius to fahrenheit
    degF := f.FAdd(f.FMul(degC, 1.8), 32.0)

    fp.SetPrecision(4)
    debug.str(fp.FloatToString(degC))
    debug.str(string("°C "))

    waarde1:=fp.floattostring(degC)





    return




    hope someone can help
  • Igor_RastIgor_Rast Posts: 357
    edited 2011-03-25 07:00
    for some reason the , wil not jump to the next row.
    that's the main problem
  • Mike GMike G Posts: 2,702
    edited 2011-03-25 09:02
    A record (row) ends with 13, 10. Columns are separated by a comma. Open the file in a text (hex) editor and verify the file format.

    In Excel create an example of what you expect. Then export to CSV. Open the exported file in a text editor and compare the export with the file created by the Prop. Update your code logic to match the file format.
  • Igor_RastIgor_Rast Posts: 357
    edited 2011-03-25 10:16
    I know that the comma seperates them for collums, but I can't get it good. it rights the comma in the same collum then adds the next data so all in the same collum,
    Can you help me with the code so it get in 5 diferent collums,
    probably the comma needs to be somewhere else, but I tryed everything, getting crazy abou it ;
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-03-25 13:07
    Your problem may just be in how you are opening the file in Excel.
    Excel uses tabs as deliminators by default.
    I usually use the .txt ending with my files that way Excel "imports" the file. You just need to make sure the check box next to "comma" is checked when in import it.
    If you use open office, you can right click the file, select "open with" choose "OpenOffice.org Calc". OpenOffice uses commas by default.

    You could also try using tab as your deliminator instead of a comma.
    Change
    sdfat.pputs(string(" , "))
    to
    sdfat.pputs(string(" ", 9," "))

    Duane
  • Igor_RastIgor_Rast Posts: 357
    edited 2011-03-25 14:58
    thanks again, if made a text file and imported it, worked like a charm .
    im verry gratefull spend 3 nigts placing the comma everywhere without chekking the excel
    thanks.
Sign In or Register to comment.