Shop OBEX P1 Docs P2 Docs Learn Events
MicroSD Log Data - Altimeter Project — Parallax Forums

MicroSD Log Data - Altimeter Project

aparis1983aparis1983 Posts: 22
edited 2014-01-21 16:30 in Robotics
I finished an altitude & temperature display project based on specifications that I found at http://hackaweek.com/hacks/?p=1021
Now, I'm trying to have the data logged in a MicroSD card. I've tried a few different things that I found on the tutorials but I still can't get any data into the card. Does anyone know of a simple code that I can add to what I already have in order to log data? Attached is the spin code that I'm using for my currently functional altitude & temperature project along with a diagram. My level of expertise? Complete novice. Please help!
diagram.jpg
spin code.jpg
600 x 900 - 108K
1024 x 683 - 64K

Comments

  • SRLMSRLM Posts: 5,045
    edited 2013-11-19 17:32
    Personally, I like FSRW for SD card access: http://fsrw.sourceforge.net/
  • LevLev Posts: 182
    edited 2013-11-19 17:56
    I also recommend FSRW. I have been using it for many high altitude balloon projects with the Parallax altimeter and many other sensors, and it has been very reliable. I can send you some code snippets tomorrow if you need them.
  • aparis1983aparis1983 Posts: 22
    edited 2013-11-19 18:10
    I'll take a look at FSRW. I would greatly appreciate any code you can throw my way. I'm using this project on a high altitude balloon as well.
  • aparis1983aparis1983 Posts: 22
    edited 2014-01-18 14:21
    Hi Lev,
    Would you mind sending me some code for SD data logging? I'm a little stuck as to how to do this.
    Greatly appreciate it.
  • LevLev Posts: 182
    edited 2014-01-18 15:01
    Hi aparis,

    oops. Thanks for reminding me. Senior moment - sorry. I'll dig that stuff out and send it to you tonight or tomorrow.

    Rich
  • GarethGareth Posts: 278
    edited 2014-01-18 17:39
    Here is the solution i used on my PropRover Data logging system... the circuit diagrams below appear correct when pasted as spin code : -
      {{┌───────────────────────────────────────────┐  10KΩ     ┌─────────┐
       │     PropRover Data Logging to SD Card     │ ┌──Rsv──┫ ┌───────┤
       │                                           │ ┣──CS ──┫ │   ┌───┻─┐  
       │ Demo Code   :- Gareth                     │ ┣──DI ──┫ │┌──┘ 2GB │  
       │ aka Youtube :- Chiprobot                  │ │    Vdd──┫ ││MicroSD │                                 
       │ www.parallax.com & www.letsmakerobots.com │ ┣──Clk──┫ │└──────┳─┘        
       └───────────────────────────────────────────┘ ├────Vss──┫ └───────┫   
                            This is my exact setup > ┣──DO───┫ SD Card │
                                                     └──Rsv──┫         │  
                                                               └─────────┘
    ''Sensirion SHT-11 demo for the propeller
    ''based on the original by Cam Thompson
    
       ┌───────────────────────────────────────────┐  10KΩ     ┌─────────┐
       │ PropRover Temparatur/Humidity/Dew-Point   │ ┌──SDA──┫ SHT-11  │
       │           Using the SHT-11 chip           │ ┣──SCL──┫  ┌───┐  │
       │ Demo code adjusted by user : Gareth       │ │       ──┫  │ ‣ │  │
       │ www.parallax.com & www.letsmakerobots.com │ │       ──┫  │   │  │                               
       │          aka Youtube :- Chiprobot         │ │    GND──┫  └───┘  │      
       └───────────────────────────────────────────┘ └────VCC──┫         │ 
                                                               └─────────┘  
                                                                          }}
    CON
      _clkmode = xtal1 + pll16x 
      _xinfreq = 5_000_000
    
      ' SD Card wiring (4 wire version + supplies) 
      D0  = 0   ' Pin 0  DataOut    ' I've set these pins to match the SD card holder connections
      CLK = 1   ' Pin 1  ClockOut   ' These are the correct pin numbers for my SD Card holder
      DI  = 2   ' Pin 2  DataIN     ' In addition, connect the first pin (VDD) to +3.3 Volts, and
      CS  = 3   ' Pin 3  ChipSelect ' connect the second pin (VSS) to ground.
                                    ' My card holder has 6 pins (the 4 data lines, and 2 power lines.)
    SHT_DATA      = 29        ' SHT-11 data pin
    SHT_CLOCK     = 28       ' SHT-11 clock pin
    
      CLS         = $0         ' clear screen
      CR          = $D         ' carriage return
      Deg         = $B0        ' degree symbol
    OBJ
      PST           : "Parallax Serial Terminal"   '  Serial moniotor
      sdfat         : "fsrw"                       '  SD card routines
      sht           : "Sensirion_full" 
      Math          : "Float32"                    '  Math routines
      fp            : "FloatString"                '  String manipluation
    PUB go    | mount, TestValue,count,tmp,rawTemp, rawHumidity, tempC, rh, dewC, TF_fp, RH_fp,LedCycle 
      PST.start(115200)     'Start serial monitor
      Math.start            'Start the floating point maths routines
      sht.start(SHT_DATA, SHT_CLOCK)   ' start sensirion object
       waitcnt(clkfreq*1+cnt)
      sht.config(33,sht#off,sht#yes,sht#hires)              'configure SHT-11
      
      DIRA[14]~ 'Set logic Pin 14 to input as Start logging button 0=off 1=pressed
      DIRA[15]~ 'Set logic Pin 15 to input as Stop  logging button 0=0ff 1=pressed
      DIRA[16..23]~~
      LedCycle :=%10000000
      
      PST.str(string("PropRover", 13))
      PST.str(string("Press Start button to begin Logging", 13)) 
      outa[16..23]:=  %10110110  ' Display "S" on 7seg 
      repeat  while INA[14] ==0   ' wait for Start button so card can be inserted etcetcetc
      outa[16..23]:=  %00000000  ' Display " " on 7seg 
    
      PST.str(string("Mounting Card", 13))
      mount := \sdfat.mount(0)   ' Prepare to mount the SD card
      if mount < 0
         PST.str(string("SD Card Error Please check!!!",13))
         outa[16..23]:=  %10011110  ' Display "E" on 7seg
         waitcnt(clkfreq*3+cnt)
         abort    'terminate program
     
      PST.str(string("SD Card Found", 13)) 
      sdfat.popen(string("DATA001.txt"), "w")  'Open SD Card file to "w" write or "a" append data.
      
      TestValue:= PI         ' Give test value an initial value PI = 3.141593 
      Math.FFloat(TestValue) ' convert it to a Floating point value for "Maths"
    
      PST.str(string("Logging Started",13))
        sdfat.pwrite(string("  °C  ,  °F  ,%Humid, DewC , DewF"),33)
        sdfat.pputc(13)   ' add a control charater to separate logged values   
      repeat 
          if INA[15] ==1   'If Stop button pressed stop logging exit
            PST.str(string("Logging Stopped",13))
            quit           ' exit repeat loop 
        rawTemp := Math.FFloat(sht.readTemperature) 
        'term.str(fp.FloatToFormat(rawTemp, 5, 0))
        'term.str(string(","))
        rawHumidity := Math.FFloat(sht.readHumidity)
        'term.str(fp.FloatToFormat(rawHumidity, 5, 0))
    
        'term.str(string(","))
        tempC := celsius(rawTemp)  
        PST.str(fp.FloatToFormat(tempC, 5, 2))
        PST.str(string("°C, "))
        PST.str(fp.FloatToFormat(fahrenheit(tempC), 5, 2))
        PST.str(string("°F, "))
         
        rh := humidity(tempC, rawHumidity)
        PST.str(fp.FloatToFormat(rh, 5, 2))
        PST.str(string("%, "))
         
        dewC := dewpoint(tempC, rh)
        PST.str(fp.FloatToFormat(dewC, 5, 2))
        PST.str(string(" DewP °C, "))
        PST.str(fp.FloatToFormat(fahrenheit(dewC), 5, 2))
        PST.str(string(" DewP °F"))
    
        TF_fp:=sht.getTemperatureF
        'term.dec(TF_fp)
        'term.str(string(", "))
        RH_fp:=sht.getHumidity
        'term.dec(RH_fp)
        'term.str(string(",   "))
        'status:=sht.readStatus
        'term.bin(status,8)
        'term.str(string(",  "))
    '   status:=sht.checkLowBat
    '   term.bin(status,8)
        PST.str(string(13))
       
          sht.config(33,sht#off,sht#yes,sht#hires)        '1 slow, hiRes measurement
       
       '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
       ' This is the all important write value as a string to the SD card part
       ' ie write data as 12 digits in length to 5 decimal places
       
        sdfat.pwrite(fp.FloatToFormat(TempC,6,2),6) ' write test value as string to SD card
        sdfat.pputc(44)
        sdfat.pwrite(fp.FloatToFormat(fahrenheit(tempC),6,2),6) ' write test value as string to SD card
        sdfat.pputc(44)
        sdfat.pwrite(fp.FloatToFormat(rh,6,2),6) ' write test value as string to SD card
        sdfat.pputc(44)
        sdfat.pwrite(fp.FloatToFormat(dewC,6,2),6) ' write test value as string to SD card
        sdfat.pputc(44)
        sdfat.pwrite(fp.FloatToFormat(fahrenheit(dewC),6,2),6) ' write test value as string to SD card
    
        sdfat.pputc(13)   ' add a control charater to separate logged values
       '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''    
          waitcnt(clkfreq/8 + cnt)  ' adjust delay time between samples clkfreq/2=0.5 second
          outa[16..23]:= LedCycle
          LedCycle := Ledcycle>>1  
           if LedCycle ==%00000010
             outa[16..23]:= LedCycle
              LedCycle:=%010000000
          
         PST.BIN(LedCycle,8)
         PST.newline      
       count++
              
      sdfat.pclose  ' close down SD card ie to clear any buffers and make it safe to remove.
      PST.str(string("It is safe to remove the card now")) 'logged data is safe on card now
    
    PUB celsius(t)
      ' from SHT1x/SHT7x datasheet using value for 3.5V supply
      ' celsius = -39.7 + (0.01 * t)
      return Math.FAdd(-39.7, Math.FMul(0.01, t))  
    
    PUB fahrenheit(t)
      ' fahrenheit = (celsius * 1.8) + 32
      return Math.FAdd(Math.FMul(t, 1.8), 32.0)
      
    PUB humidity(t, rh) | rhLinear
      ' rhLinear = -2.0468 + (0.0367 * rh) + (-1.5955E-6 * rh * rh)
      ' simplifies to: rhLinear = ((-1.5955E-6 * rh) + 0.0367) * rh -2.0468
      rhLinear := Math.FAdd(Math.FMul(Math.FAdd(0.0367, Math.FMul(-1.5955E-6, rh)), rh), -2.0468)
      ' rhTrue = (t - 25.0) * (0.01 + 0.00008 * rawRH) + rhLinear
      return Math.FAdd(Math.FMul(Math.FSub(t, 25.0), Math.FAdd(0.01, Math.FMul(0.00008, rh))), rhLinear)
    
    PUB dewpoint(t, rh) | h
      ' h = (log10(rh) - 2.0) / 0.4343 + (17.62 * t) / (243.12 + t)
      h := Math.FAdd(Math.FDiv(Math.FSub(Math.log10(rh), 2.0), 0.4343), Math.FDiv(Math.FMul(17.62, t), Math.FAdd(243.12, t)))
      ' dewpoint = 243.12 * h / (17.62 - h)
      return Math.FDiv(Math.FMul(243.12, h), Math.FSub(17.62, h))
    

    It is just a case of substituting your altitute variables instead of the temparature/dewpoint/humidity variable i used.....
    .... hope this steers you in the right direction ...G
  • LevLev Posts: 182
    edited 2014-01-19 08:37
    Hi aparis,

    Attached is a section of the code I have been using on high altitude balloon flights that deals with the altimeter and SD card. Let me know if this is enough to get you going.

    BalloonCodeExample.spin

    Rich
  • aparis1983aparis1983 Posts: 22
    edited 2014-01-21 16:30
    Thank you both!! I'm going to see if I can integrate this into my code over the weekend. I'll update with results.
Sign In or Register to comment.