Micro SD Data Logging
aparis1983
Posts: 22
My project is an altitude sensor displaying altitude above sea level in feet and temperature in Farenheit on an LCD display while storing the data into a micro SD card. It currently displays altitude and temperature on the LCD, but I cannot get it to log more than 1 line of the data into the excel file in the card. The project is for a high altitude balloon that will go upwards of 100,000 feet and come down after a little over 2 hours.
Components: Propeller BOE, Parallax MS5607 altitude sensor, and Parallax 2x16 serial LCD. Schematics provided below.
I've used snippets of code that were suggested when I asked about this project in the past. Currently I only get one line of data into the file. My results display altitude in cell A1 and temperature in B1, then the next altitude and temp reading in C1 and D1; so on all along row 1. However, it always stops at AO1 (about 21 pairs of readings), and never goes to row 2.
Ideally, I would like altitude readings to be recorded down column A and temperature readings down column B. Additionally, one reading per second would be more than sufficient as the balloon flight will likely exceed 2 hours (7,200 readings). The code I'm currently using is:
I would appreciate any help with the data logging portion.
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
sd_DO = 22
sd_CLK = 23
sd_DI = 24
sd_CS = 25
TX_PIN = 2
BAUD = 19_200
START_ALT = 20
OBJ
sdfat : "fsrw"
pst : "Parallax Serial Terminal"
LCD : "FullDuplexSerial.spin"
alt : "29124_altimeter"
fp : "FloatString"
PUB start | a , t , mount
LCD.start(TX_PIN, TX_PIN, 00, 19_200) ' Start Parallax FullDuplexSerial.
waitcnt(clkfreq / 100 + cnt) ' Pause for FullDuplexSerial.spin to initialize
mount := \sdfat.mount_explicit (sd_DO, sd_CLK, sd_DI, sd_CS)
LCD.tx(17)
if mount < 0
lcd.str( string( 13, "Failed to mount", 13 ) )
abort
lcd.str(string( 13, "SD card found & mounted", 13) )
alt.start(alt#QUICKSTART, alt#BACKGROUND) ' Start altimeter for QuickStart with background processing.
alt.set_resolution(alt#HIGHEST) ' Set to highest resolution.
alt.set_altitude(alt.m_from_ft(START_ALT * 100)) ' Set the starting altitude, based on average local pressure.
sdfat.popen( string("Data.csv"),"w")
repeat
a := alt.altitude(alt.average_press) ' Get the current altitude in cm
lcd.str(string("Alt:")) ' Print header.
lcd.str(alt.formatn(a, alt#TO_FEET,8)) ' Print altitude in feet.
sdfat.pputs(alt.formatn(a, alt#TO_FEET,8))
t := alt.current_temp ' Get the current temperature.
lcd.str(string("Temp:")) ' Print header.
lcd.str(alt.formatn(t, alt#TO_DEGF,8)) ' Print temperature in Farenheit.
sdfat.pputs(alt.formatn(t, alt#TO_DEGF,8))
LCD.tx(13)
sdfat.pclose
sdfat.unmount
Components: Propeller BOE, Parallax MS5607 altitude sensor, and Parallax 2x16 serial LCD. Schematics provided below.
I've used snippets of code that were suggested when I asked about this project in the past. Currently I only get one line of data into the file. My results display altitude in cell A1 and temperature in B1, then the next altitude and temp reading in C1 and D1; so on all along row 1. However, it always stops at AO1 (about 21 pairs of readings), and never goes to row 2.
Ideally, I would like altitude readings to be recorded down column A and temperature readings down column B. Additionally, one reading per second would be more than sufficient as the balloon flight will likely exceed 2 hours (7,200 readings). The code I'm currently using is:
I would appreciate any help with the data logging portion.
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
sd_DO = 22
sd_CLK = 23
sd_DI = 24
sd_CS = 25
TX_PIN = 2
BAUD = 19_200
START_ALT = 20
OBJ
sdfat : "fsrw"
pst : "Parallax Serial Terminal"
LCD : "FullDuplexSerial.spin"
alt : "29124_altimeter"
fp : "FloatString"
PUB start | a , t , mount
LCD.start(TX_PIN, TX_PIN, 00, 19_200) ' Start Parallax FullDuplexSerial.
waitcnt(clkfreq / 100 + cnt) ' Pause for FullDuplexSerial.spin to initialize
mount := \sdfat.mount_explicit (sd_DO, sd_CLK, sd_DI, sd_CS)
LCD.tx(17)
if mount < 0
lcd.str( string( 13, "Failed to mount", 13 ) )
abort
lcd.str(string( 13, "SD card found & mounted", 13) )
alt.start(alt#QUICKSTART, alt#BACKGROUND) ' Start altimeter for QuickStart with background processing.
alt.set_resolution(alt#HIGHEST) ' Set to highest resolution.
alt.set_altitude(alt.m_from_ft(START_ALT * 100)) ' Set the starting altitude, based on average local pressure.
sdfat.popen( string("Data.csv"),"w")
repeat
a := alt.altitude(alt.average_press) ' Get the current altitude in cm
lcd.str(string("Alt:")) ' Print header.
lcd.str(alt.formatn(a, alt#TO_FEET,8)) ' Print altitude in feet.
sdfat.pputs(alt.formatn(a, alt#TO_FEET,8))
t := alt.current_temp ' Get the current temperature.
lcd.str(string("Temp:")) ' Print header.
lcd.str(alt.formatn(t, alt#TO_DEGF,8)) ' Print temperature in Farenheit.
sdfat.pputs(alt.formatn(t, alt#TO_DEGF,8))
LCD.tx(13)
sdfat.pclose
sdfat.unmount
Comments
In any case, you'll probably want to add some commas ( sdfat.pputc(',') ) and newlines ( sdfat.pputc('\n') ) to make your code output CSV.
One difference I notice is that in my code I always open the file with 'a'; not sure if that makes a difference here. Anyway, I hope this helps you out.
I notice that you do not have a pause in the repeat loop (or, maybe you didn't send all of the code below the repeat). You might try slowing the loop down a bit. That would give some extra time for the card to mount/unmount. In mine, I wrote to the SD card every 10 seconds.
Now the only thing I'm worried about is the several corrections needed for lower operational temperatures. I've read about this in the forum but not sure where to begin to include these corrections. At any rate, I have no time to work on it as the balloon is launching on Saturday. Hoping for the best.
Thanks!
That is great news! Let us know how the flight goes.