Writing to SD Card
frankwillis
Posts: 6
I have been using FSRW26 to try to write to an SD card, but I am unable for some reason to assign a variable and write it to the SD card. I know I must be missing something stupid. I am Gadget Gangster's tutorial to write a predetermined quotation to the card just like he does, but I cannot figure out how to write the value of a variable to the card.
As an engineer (non electronics related), with 30 years experience, I find it absolutely incredible that a simple method to apply an object to write data to an SD card is so illusive. Parallax has done a pretty good job with the basic stamp, but for the entry level people, too much time is being wasted on the Propeller. This should be simple and direct, and I am sure the final coding is, but why make it so darn complex to get a grasp of this? I know I am not alone.
Can anyone point me to a simple code that writes a variable to the SD card? I know how to use objects.
As an engineer (non electronics related), with 30 years experience, I find it absolutely incredible that a simple method to apply an object to write data to an SD card is so illusive. Parallax has done a pretty good job with the basic stamp, but for the entry level people, too much time is being wasted on the Propeller. This should be simple and direct, and I am sure the final coding is, but why make it so darn complex to get a grasp of this? I know I am not alone.
Can anyone point me to a simple code that writes a variable to the SD card? I know how to use objects.
Comments
Fank,
One thing you need to decide is how you want your variables stored.
Do want them stored as computer native numbers or do you want them stored as ASCII characters.
If you want to be able to read the file from Excel for some other text reader, you probably want to store the number in ASCII characters.
In my PropBOE-Bot project, the servo pulse length are written to the SD card as ASCII characters.
Here's the section of code to store the variables.
I convert the variables wheelSpeed[_PortWheel] and wheelSpeed[_StarboardWheel] to ASCII characters and store them in the buffer "sdBuffer" and then write the buffer as string to the card.
The SD card objects may have a method that does this conversion for you. I wanted to minimize the number of writes to the card so I built up a buffer to write all at once (now I wonder why I didn't add the "13" and "10" end of line characters to the buffer first).
Here's the method "LongToDecStr"
I'm using Kye's SD card object but the principles apply to FSRW26 as well.
If you don't want the data stored as ASCII data then you'd use a different method to write the values.
I am unable to track where some of your variables are coming from.
To declare a variable so that it is a string, I can't use long?
Then to write the variable to the sD takes all of this? I don't follow some of the code you have listed. It must be part of your larger program.
For example, say I want to write the values of A and B to a card in ASCII format.
What would the declaration be?
What part of the could could run on its own to write to an SD card. I am using new Propeller BOE that just came out.
It doesn't have a method to automatically write a variable as ASCII characters so you'd need to use a method such as "LongToDecStr" to write a variable as ASCII characters.
The SD object does have a writeLong method. So if your variable name is "variableX" and you wanted to write to a SD card you could use this code.
There are write methods for other variables sizes as well.
The PropBOE-BOT code I mentioned earlier is posted in the (currently) last post of the thread I linked to in my earlier post.
Thanks. Where is Kyles object? I don't see it in the propeller object in obex.
Andy
It's way to hard to find things in the OBEX IMO.
But I did find it.
http://obex.parallax.com/objects/619/
Kye's object is very sensitive to card errors. I've had to reformat cards before they would work. "Quick" formats don't fix the problems (if there are any) either.
Andy, it seems that your suggestion best fits where I am now. I was apparently having problems with the FSRW and the string issue thing. I will try it today. I bet it resolves my issue.
THANKS!