Where to start with "properly" reading logged data from SDcards? aka more help
WBA Consulting
Posts: 2,935
So I am finalizing my plungelogger that records temp to an SD card for this Saturday's Polar Bear Plunge and I would like to also make a "plotter" for the log file using a uOLED-128 display. I have figured out all the code to plot how I need on the display, but I am getting confused on how to use FSRW to read the values that have been put onto the SD card by the logging program.
I am currently working with my program from this thread. My data on the SD card is currently in this format as it logs temp and humidity from two SHT11 sensors:
Internal, 78.9, 42.4
External, 77.7, 42.2
Internal, 78.6, 42.6
External, 77.8, 42.1
Internal, 78.6, 43.4
Since I only need to log a single whole-number temp value for the plunge, I am thinking of changing my format to:
1, 78
2, 77
3, 74
4, 42 brrrr
etc
I would like to read the data back from the SD card and use the temperature as my offset for the Y of the pixel plotted on the uOLED to make a line chart. For example, the first internal temp reading is 78.9, so I want to plot the pixel at a Y position of 78 (and an X position equal to the logged number, IE: 1st value:x=1, 2nd value, x=2, etc so it plots to the right as a line chart).
I am currently reading through all of the FSRW files/demos to try to better understand how to use read commands. I need to understand how to control which bits of data from the data on the SD card is read and how to use that as my variable for the X value for my plotting. (I can make my uOLED plot values easily, it's getting the correct data from the SD that's got my scratching my head).
Anyone know of any simple examples of writing/reading a set of data values to/from an SD card and properly stepping through them? How do I manage where on the SD card I am pulling data (I see pointers and buffers in my future?)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andrew Williams
WBA Consulting
WBA-TH1M Sensirion SHT11 Module
Special Olympics Polar Bear Plunge, Mar 20, 2010
I am currently working with my program from this thread. My data on the SD card is currently in this format as it logs temp and humidity from two SHT11 sensors:
Internal, 78.9, 42.4
External, 77.7, 42.2
Internal, 78.6, 42.6
External, 77.8, 42.1
Internal, 78.6, 43.4
Since I only need to log a single whole-number temp value for the plunge, I am thinking of changing my format to:
1, 78
2, 77
3, 74
4, 42 brrrr
etc
I would like to read the data back from the SD card and use the temperature as my offset for the Y of the pixel plotted on the uOLED to make a line chart. For example, the first internal temp reading is 78.9, so I want to plot the pixel at a Y position of 78 (and an X position equal to the logged number, IE: 1st value:x=1, 2nd value, x=2, etc so it plots to the right as a line chart).
I am currently reading through all of the FSRW files/demos to try to better understand how to use read commands. I need to understand how to control which bits of data from the data on the SD card is read and how to use that as my variable for the X value for my plotting. (I can make my uOLED plot values easily, it's getting the correct data from the SD that's got my scratching my head).
Anyone know of any simple examples of writing/reading a set of data values to/from an SD card and properly stepping through them? How do I manage where on the SD card I am pulling data (I see pointers and buffers in my future?)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andrew Williams
WBA Consulting
WBA-TH1M Sensirion SHT11 Module
Special Olympics Polar Bear Plunge, Mar 20, 2010
Comments
By the way, I am also heavily involved in Special Olympics... but I think you guys are completely nuts for jumping into cold water in the middle of the winter. How about "brakeless Thursday?" I love the idea of getting everyone off the rode... so we can drive around without brakes and earn money for Special Olympics by not killing anyone[noparse]:)[/noparse]
It you would move over to video... I could shake this out for you in a couple of minutes.
Good work... thank you.
Rich
Startup
Mount SD
Open File
repeat x times (where x is the number of readings, probably 120)
__Read first value
__Plot pixel in position X, value
__next value
quit
Not sure what you mean by moving to video, unless you mean displaying the plot line using TV out instead of the uOLED. My plan is to set things up for TV out, then migrate to the uOLED. If I run out of time to get the uOLED code working, I will use my small composite display or as a last resort, just take my laptop and use excel.
Special Olympics is dear to me as my employer is directly involved with people with disabilities. I haven't been able to get anyone else here to join my plunge though, as they all think I am nuts as well.
My goal for next year is to add a heart rate monitor; that should be interesting to chart....
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andrew Williams
WBA Consulting
WBA-TH1M Sensirion SHT11 Module
Special Olympics Polar Bear Plunge, Mar 20, 2010
They won't join you because they are cowards... like me[noparse]:)[/noparse]
Rich
It depends on how you are writing to the sd.
If you wrote with pputc
to convert the ascii·value you read with r := sdfat.pgetc·· you just subtract 48...
so for instance
r := sdfat.pgetc
x:=r-48
if you wrote the value 2 to your file.... with pputc
x now has the value of 2.·
To get the number you actually stored you have to read in two characters and combine them into a final value.· so you would multiply 2 by 10... get the next digit and add it in.
If you use a pwrite to store the value then when you do sdfat.pgetc... your value pops out directly.
my code for writing looks like this:
·r:=sdfat.popen(string("camfile2.txt"),"a")
·sdfat.pwrite(@iod,512)
·sdfat.pclose
where 512 is the number of bytes to write from the iod array to the card
Not the clearest explanation... is it?
I think that will do it
Rich
·
after dinner:
The way the human brain works can be absolutely charming... so, I like to· leave it out there....
In this case I was between botchiball, the dentist and the forum...
Anyway, the above post is actually correct.· I have double checked it and it works out just the way I describe[noparse]:)[/noparse]
Post Edited (rjo_) : 3/18/2010 12:37:33 AM GMT
You'll need to put a layer on top to do that.
Note that this parsing will probably be *much* slower than anything else you do. But the parsing
is pretty easy to do.
I'd start by writing a pgets() routine that gets a "line" to parse into a fixed-sized buffer.
It can initially do this by calling pgetc() until it sees a newline or runs out of buffer space.
Then write some code to parse that line into your data. You can do this separately, using a
constant buffer, until it works, and then integrate it into the rest of the program.
-tom
It is easy to test... you just put some numbers into an array.... write them to the SDcard as described... then read them back in... add a number to each as you read them in and then display the result on the screen using tv.dec(your variable) to the screen. If you see what you want to see, you are done. If not... somewhere in the ether is a little confusion that we need help with.
The quick and dirty way is just to encode one kind of data by adding 100 to it. You have plenty of room in you byte to do this. Then when you read it back in... if the value is above one hundred... you subtract one hundred and log it in as that particular type of data[noparse]:)[/noparse]
You mentioned graphing... I like your idea about graphing the change from base line. You only have 200 or so vertical graph points to work with and the differences in your data should be fairly small. If you stick to graphing changes from baseline, you can stretch the changes over the entire vertical extent of the display for a more dramatic appearance , that will be easier to look at... but a little more difficult for people to interpret. But if you catch their eye, their brain won't be far behind.
By the way... we have some guys in our area... mostly cops, but a few insurance salesmen, etc. who are doing a "super" pluge, which involves them plunging into freezing water·evey hour for 24 hours.· If you would hook up an LED to their core body temperature measurement and make them wear it on their heads...· when the LEDs goes out... they need help[noparse]:)[/noparse]
I am thinking about going and taking a pole... "would you rather plunge into freezing water every hour for twenty four hours... or follow me around on "brakeless thursday?"· Why would I need a pole?· Something for them to grab onto... silly.
Post Edited (rjo_) : 3/18/2010 2:04:15 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andrew Williams
WBA Consulting
WBA-TH1M Sensirion SHT11 Module
Special Olympics Polar Bear Plunge, Mar 20, 2010