How big a file do you need? I have got mine to read from a 5MB file on a memory stick with the Parallax USB and send them back to the PC via bluetooth. Actually the file was the gutenberg King James Bible - which was a the biggest text file I could find and in fact I have to stop it after a couple of chapters. If you don't have or plan to have a memory stick I would reckon you will need to put your text into EEPROM - which won't allow you much.
Just in case my approoach is the one for you here is some of my code. It is just an extract, so I have not shown the variable declarations.
' Open textfile.TXT for input (read)
PAUSE 200
SEROUT TX\CTS, Baud, [noparse][[/noparse]"OPR textfile.txt", CR]
DEBUG "Opening text file", CR
GOSUB Get_Serial_Bytes
temp=0
readagain:
FOR x = 1 TO 10
PAUSE 220
SEROUT TX\CTS, Baud, [noparse][[/noparse]"RDF ", $00, $00, $00, $0f, CR]
' Four Hex digits describe amount to read - the final 0f is 15 in hex
SERIN RX\RTS, Baud, 500, No_Data2, [noparse][[/noparse]STR buffer\15]
FOR z = 1 TO 15 'The text I was reading was littered with Line Feeds
IF buffer(z)=10 THEN buffer(z)=7 'If I recall this is Ctrl-G the bell, and non-printing
NEXT
DEBUG STR buffer\15 ' Display data read from file
SEROUT 1,84,[noparse][[/noparse]STR buffer\15] 'out to the Bluetooth
SERIN RX\RTS, Baud, 500, No_Data2, [noparse][[/noparse]STR buffer\5] 'The prompt from the drive
NEXT
temp=temp+1
'DEBUG " [noparse][[/noparse]",DEC temp,"] "
IF temp < 40 THEN readagain
'Close textfile.txt
PAUSE 120
SEROUT TX\CTS, Baud, [noparse][[/noparse]"CLF textfile.txt", CR]
GOSUB Get_Serial_Bytes
The text file i need to open is pixel data from a web cam. I have a few questions on how to make it work. First how do i read the values as inputs to create an action? say my text file looks like this [noparse][[/noparse]123,234,345,234,321,564,243,156,90,567,43] and each number represents a pixel value for a quadrant of a video feed. Once i open the file how do i create an IF ..THEN for an individual value from the list? Also, the file will be continually rewriting itself (about thirty times a second) so how do i loop the program to continually reopen the file?
The Stamp is really not fast enough for this kind of thing. The BS2 executes maybe 4,000 instructions per second where each statement is translated into several instructions. At 30 frames a second, this is about 120 instructions per frame, nowhere near enough by several orders of magnitude. You really need some kind of fast pre-processor. The CMUcam and AVRcam are good examples of such a processor (do a websearch for those names).
By the way, do you really mean a text file? How are you getting the data from the camera to the Stamp? Do you have a PC accessing the webcam, then feeding the raw stream to the Stamp? If so, it would be much better to have the PC do the initial image processing. Even if you're having the PC store the raw data on something like a memory stick, it's still better to have the PC do some initial image processing and pass on more limited data to the Stamp.
Post Edited (Mike Green) : 3/26/2008 3:14:08 AM GMT
Yes the PC is analyzing the video and extracting pixel information and saving it to a text file. It will rewrite this text file about thirty times per second. Then we will either have the stamp hooked up to the PC by USB or bluetooth so it can access the text file. What I need to know is how to write the code for opening a text file and reading individual values in order to move my servos.
It's simply not possible for the BS2 to "open" a text file on the PC's hard disk. The BS2 only has a serial port link to the PC, and has NO access to the PC's file system.
Having said that, you CAN write a PC-based program to recieve 'directions' over the serial port from the BS2, and the PC-based program can open the file and send the bytes to the BS2 over the serial link. From your posts it sounds like you already KNOW how to write code on the PC to open a text file and read individual values, so it sounds like you need to know how to write a program on the BS2 that will accept bytes over the serial link, and use those bytes to command servo positions.
That can be as simple as:
ServoPos1 VAR WORD
ServoPos2 VAR WORD
ServoPin1 PIN 1
ServoPin2 PIN 2
MAIN:
SERIN 16, 16864, 20, Timeout, [noparse][[/noparse]DEC ServoPos1, DEC ServoPos2]
Timeout:
IF ServoPos1 = 0 THEN
ServoPos1 = 750
ENDIF
IF ServoPos2 = 0 THEN
ServoPos2 = 750
ENDIF
PULSOUT ServoPin1, ServoPos1
PULSOUT ServoPin2, ServoPos2
GOTO MAIN
Comments
Just in case my approoach is the one for you here is some of my code. It is just an extract, so I have not shown the variable declarations.
By the way, do you really mean a text file? How are you getting the data from the camera to the Stamp? Do you have a PC accessing the webcam, then feeding the raw stream to the Stamp? If so, it would be much better to have the PC do the initial image processing. Even if you're having the PC store the raw data on something like a memory stick, it's still better to have the PC do some initial image processing and pass on more limited data to the Stamp.
Post Edited (Mike Green) : 3/26/2008 3:14:08 AM GMT
Having said that, you CAN write a PC-based program to recieve 'directions' over the serial port from the BS2, and the PC-based program can open the file and send the bytes to the BS2 over the serial link. From your posts it sounds like you already KNOW how to write code on the PC to open a text file and read individual values, so it sounds like you need to know how to write a program on the BS2 that will accept bytes over the serial link, and use those bytes to command servo positions.
That can be as simple as:
ServoPos1 VAR WORD
ServoPos2 VAR WORD
ServoPin1 PIN 1
ServoPin2 PIN 2
MAIN:
SERIN 16, 16864, 20, Timeout, [noparse][[/noparse]DEC ServoPos1, DEC ServoPos2]
Timeout:
IF ServoPos1 = 0 THEN
ServoPos1 = 750
ENDIF
IF ServoPos2 = 0 THEN
ServoPos2 = 750
ENDIF
PULSOUT ServoPin1, ServoPos1
PULSOUT ServoPin2, ServoPos2
GOTO MAIN