I posted a thread late last year on the uDrive from 4dsystems. That allowed a picaxe to read and write data from a micro SD card, but it wasn't easy to get the data off the card. 4dsystesm have updated their software (with a simple upgrade to an existing udrive) so it can now read FAT files. This now means files can be transferred to and from a PC easily. You could use a $5 USB to sd card adaptor. Or put the card in a camera and read the files over.
I wrote some code in vb.net as a demonstration http://www.instructables.com/id/Simple-mass-storage-for-your-microcontroller-proje/
Surprisingly, the picaxe code ended up far simpler than the vb.net code! I think credit is due to RevEd for the simple Serin and Serout code structure.
This code demonstrates writing a file, reading a file and erasing a file. With a few additions (shown in the vb.net code) you can read and write huge files, and can append data to existing files.
I believe this may open up some amazing possibilities for the picaxe. Reading animatronics files, large text files and putting them on a display, even ? wav files. For writing, datalogging would be the obvious application (there was a thread recently where someone wanted to store a million data points. Well, this could store a billion!).
I wrote some code in vb.net as a demonstration http://www.instructables.com/id/Simple-mass-storage-for-your-microcontroller-proje/
Surprisingly, the picaxe code ended up far simpler than the vb.net code! I think credit is due to RevEd for the simple Serin and Serout code structure.
This code demonstrates writing a file, reading a file and erasing a file. With a few additions (shown in the vb.net code) you can read and write huge files, and can append data to existing files.
I believe this may open up some amazing possibilities for the picaxe. Reading animatronics files, large text files and putting them on a display, even ? wav files. For writing, datalogging would be the obvious application (there was a thread recently where someone wanted to store a million data points. Well, this could store a billion!).
Code:
' udrive (4dsystems) file demonstration for micro SD card with FAT16 files for easy transfer to and from a PC
' code below uses 152 bytes (less if you want 'write' but not 'read' etc)
' pin 4 to the reset pin of the udrive (leg 1)
' ground to the ground of the udrive (leg 2)
' pin 2 to receive data on the udrive (leg 3)
' pin 3 to transmit data on the udrive (leg 4)
' 5V to 5V on the udrive (leg 5)
main:low 4 ' 4 is reset pin
high 2 ' 2 transmits to the udrive (receive on pin 3) high is resting, low is data (T mode)
pause 100 ' startup delay for reset
high 4 ' 4 is reset pin - enable =high
pause 1000 ' short pause after resetting should be at least 500ms
serout 2,T2400,("U") ' initialise
serin 3,T2400,b0 ' should be a 06 - if no reply then hangs
' if b0<>6 then goto main ' if a reply but not a 06 then reset - probably not needed
'gosub erasefile
gosub writefile
gosub readfile
end
readfile: ' read file 10char.txt which has 10 characters
serout 2,T2400,("@a",0,"10char.txt",0) ' packet size 0 ie send the entire file at once. Bigger files are possible in pieces
serin 3,T2400,b0,b1,b2,b3 ' size of data file (we know it is 10 for this file)
serout 2,T2400,(6) ' acknowledge got the file size
serin 3,T2400,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10 ' get 10 bytes, plus the last byte b10 should be 06
' perhaps add error checking here if b10 does not equal 6
' debug
return
writefile: ' create a file with ABCDEFGHIJ in it. 10 bytes long
' this is a very simple demonstration. More advanced code can write files of indefinite length
' and can append data to the end of an existing file. See the udrive documentation for more details.
serout 2,T2400,("@t",0,"10char.txt",0,0,0,0,10)
' @t is write, 0 is packetsize, filename (ends in zero), 4 filesize bytes
serin 3,T2400,b10 ' should be a 6 to acknowledge
serout 2,T2400,("ABCDEFGHIJ") ' send the data
serin 3,T2400,b10 ' should be a 6
' debug
return
erasefile: ' erase a filename from the drive
serout 2,T2400,("@e","10char.txt",0)
serin 3,T2400,b10 ' should be a 6 to acknowledge
' debug
return
dirfile: ' this may be difficult on a small picaxe as the udrive dumps out all the file listing in one go
Attachments
-
274.5 KB Views: 167
Last edited: