Interfacing 27937 memory Stick Data Logger with Javelin
Istha Powron
Posts: 74
Next problem........the USB Memory Stick.
I'm trying to log data to teh memory stick from the Javelin and am going quitely insane.
First you have to get it to sync.
Here's my code to do this;
while (!DONE && index < 100)
{
index++;
USB_Write_Uart.sendByte('E');
USB_Write_Uart.sendByte('\r');
while (USB_Read_Uart.byteAvailable())
{
r = (char)USB_Read_Uart.receiveByte();
DONE = true;
System.out.print(r );
}
CPU.delay (200);
if (index > 99)
{
System.out.println(" \n\rSync failed !\n\r" );
DONE = true;
}
}
This works....I think....I get the response;
Ver 03.64VDAPF On-Line[noparse]:D[/noparse]evice Detected P2No UpgradeD:\>
To open a file, in pbasic you send;
' Open SEEDFILE.TXT for output (write)
PAUSE 500
SEROUT TX\CTS, Baud, [noparse][[/noparse]"OPW seedfile.txt", CR]
GOSUB Get_Serial_Bytes
In my case, i build a command;
// Open file command
USB_out_Buff.clear();
USB_out_Buff.append("OPW LogFile.txt");
USB_out_Buff.append('\r');
WriteUSB();
Then send it with this routine;
static void WriteUSB()
{
boolean COM = false;
int xdex = 0;
int b;
System.out.println("Writing the following to USB\r" );
System.out.println("\r" );
USB_in_Buff.clear(); //clear the input buffer
index = 0;
for (xdex = 0; xdex < USB_out_Buff.length(); xdex++)
{
b = (int) USB_out_Buff.charAt(xdex);
USB_Write_Uart.sendByte(b); //send output
System.out.print((char) b );
}
CPU.delay (2000); //wait
System.out.println("Waiting for USB \r" );
System.out.println("\r" );
while (!COM)
{
index ++;
while (USB_Read_Uart.byteAvailable())
{
System.out.println("+" );
c = (char)USB_Read_Uart.receiveByte();
USB_in_Buff.append(c);
CPU.delay (2000);
COM = true;
}
if (index > 99)
{
System.out.println("USB Write failed !\r" );
System.out.println("\r" );
COM = true;
}
} //end while
} //end Write USB
I get this response on screen;
Writing the following to USB
OPW LogFile.txtWaiting for USB
USB Write failed !
I get no repsonse from the USB.
The output "OPW LogFile.txtWaiting for USB" would suggest that the carriage return is not being sent for some reason.
I have tried;
// Open file command
USB_out_Buff.clear();
USB_out_Buff.append("OPW LogFile.txt");
USB_out_Buff.append((char) 13);
WriteUSB();
and
// Open file command
USB_out_Buff.clear();
USB_out_Buff.append("OPW LogFile.txt");
USB_out_Buff.append((char) 0x0d);
WriteUSB();
But I just can't get the USB to give me a response.
Any ideas?
Issy
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The robot is going to lose. Not by much. But when the final score is tallied, flesh and blood will beat the damn monster.
Adam Smith
Post Edited (Istha Powron) : 3/22/2009 10:14:32 PM GMT
I'm trying to log data to teh memory stick from the Javelin and am going quitely insane.
First you have to get it to sync.
Here's my code to do this;
while (!DONE && index < 100)
{
index++;
USB_Write_Uart.sendByte('E');
USB_Write_Uart.sendByte('\r');
while (USB_Read_Uart.byteAvailable())
{
r = (char)USB_Read_Uart.receiveByte();
DONE = true;
System.out.print(r );
}
CPU.delay (200);
if (index > 99)
{
System.out.println(" \n\rSync failed !\n\r" );
DONE = true;
}
}
This works....I think....I get the response;
Ver 03.64VDAPF On-Line[noparse]:D[/noparse]evice Detected P2No UpgradeD:\>
To open a file, in pbasic you send;
' Open SEEDFILE.TXT for output (write)
PAUSE 500
SEROUT TX\CTS, Baud, [noparse][[/noparse]"OPW seedfile.txt", CR]
GOSUB Get_Serial_Bytes
In my case, i build a command;
// Open file command
USB_out_Buff.clear();
USB_out_Buff.append("OPW LogFile.txt");
USB_out_Buff.append('\r');
WriteUSB();
Then send it with this routine;
static void WriteUSB()
{
boolean COM = false;
int xdex = 0;
int b;
System.out.println("Writing the following to USB\r" );
System.out.println("\r" );
USB_in_Buff.clear(); //clear the input buffer
index = 0;
for (xdex = 0; xdex < USB_out_Buff.length(); xdex++)
{
b = (int) USB_out_Buff.charAt(xdex);
USB_Write_Uart.sendByte(b); //send output
System.out.print((char) b );
}
CPU.delay (2000); //wait
System.out.println("Waiting for USB \r" );
System.out.println("\r" );
while (!COM)
{
index ++;
while (USB_Read_Uart.byteAvailable())
{
System.out.println("+" );
c = (char)USB_Read_Uart.receiveByte();
USB_in_Buff.append(c);
CPU.delay (2000);
COM = true;
}
if (index > 99)
{
System.out.println("USB Write failed !\r" );
System.out.println("\r" );
COM = true;
}
} //end while
} //end Write USB
I get this response on screen;
Writing the following to USB
OPW LogFile.txtWaiting for USB
USB Write failed !
I get no repsonse from the USB.
The output "OPW LogFile.txtWaiting for USB" would suggest that the carriage return is not being sent for some reason.
I have tried;
// Open file command
USB_out_Buff.clear();
USB_out_Buff.append("OPW LogFile.txt");
USB_out_Buff.append((char) 13);
WriteUSB();
and
// Open file command
USB_out_Buff.clear();
USB_out_Buff.append("OPW LogFile.txt");
USB_out_Buff.append((char) 0x0d);
WriteUSB();
But I just can't get the USB to give me a response.
Any ideas?
Issy
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The robot is going to lose. Not by much. But when the final score is tallied, flesh and blood will beat the damn monster.
Adam Smith
Post Edited (Istha Powron) : 3/22/2009 10:14:32 PM GMT
Comments
so I assume you are talking about interfacing
the Parallax Datalogger module.
Attached are my classes for the Parallax Datalogger.
The classes go into folder ...\lib\stamp\peripheral\datalogger
Note that these classes use SPI mode, so no VP's are required.
regards peter
Why is it that there is no mention of your libraries for the GPS on the GPS product page and no mention of your data logger libraries on the data logger product page. Due to their limited memory, the stamp modules can't be used to interface more than a couple of products. The great thing about teh Javelin is that it has sufficient memory to tackle real control issues. Surely, if you linked to the Javelin libraries, it woudl make teh Javelin more popular and give potential users more power to integrate the hardware.
The project I am working on at the moment will need;
GPS
Logger
Compass
Accelerometer
933MHz transmitter
Thank you again for pointing me in the right direction.
Just out of interest, do you have any idea why I am not getting a signal back from the USB?
I
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The robot is going to lose. Not by much. But when the final score is tallied, flesh and blood will beat the damn monster.
Adam Smith
Your test program imports: stamp.util.text.*;
I have looked on yahoo and in teh forumds but I can't find the class.
I
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The robot is going to lose. Not by much. But when the final score is tallied, flesh and blood will beat the damn monster.
Adam Smith
regards peter
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The robot is going to lose. Not by much. But when the final score is tallied, flesh and blood will beat the damn monster.
Adam Smith
Just beautifully written library.
Thanx.
I
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The robot is going to lose. Not by much. But when the final score is tallied, flesh and blood will beat the damn monster.
Adam Smith
It's almost working!
You might add a note to the comments at the top of your test program to remind users to change the jumper from UART to SPI. (That'll save an hour!)
In your code, you declare the following pins;
static final int SPI_CLK = CPU.pin13; //Clock out (connects to Vinculum SCLK pin)
static final int SPI_CS = CPU.pin11; //Chip Select out (connects to Vinculum CS pin)
static final int SPI_SDO = CPU.pin14; //Data out (connects to Vinculum SDI pin)
static final int SPI_SDI = CPU.pin10; //Data in (connects to Vinculum SDO pin)
You then do this;
//select datalogger
CPU.writePin(CPU.pin9,false);
CPU.writePin(CPU.pin8,false);
Unless I am wrong, thes pins should not be conneted to anything.
What do these lines do?
I
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The robot is going to lose. Not by much. But when the final score is tallied, flesh and blood will beat the damn monster.
Adam Smith
connected to an analogue multiplexer (CD4052)
so I could share multiple devices using the same pins.
They have no purpose for you.
Just delete them.
And could you edit the subject of this thread?
(upper right corner, pencil symbol)
regards peter
I have no idea. I am not a Parallax employee. Parallax could grab the classes from the Yahoo group
and make them available as downloads on the product pages. Most classes I wrote will work
out-of-the-box and most have more than sufficient documentation on how to use them.
But there are no application notes, except for the Format class.
regards peter
Please use the pencil icon at the top right of your message to add a descriptive subject for this thread. As for adding Peter's libraries to the website for each product, that shouldn't be a problem if they're packaged up with documentation. They need only to be submitted to someone such as myself and I can arrange to have them listed. Of course, this is up to Peter.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
Like I said, the only documentation are the comments and javadocs
in the java files (and that should be enough to use the class).
What kind of documentation do you need?
regards peter
If there are static links to the libraries you would like to see on our website you can send a list of them and with which product they go with and the link and I will see that they get put on our website. While I am quite fluent in the hardware, I am not very good with Java. Sadly we used to have three Java programmers but that is not the case now, so I would rely on your input for which files we should link to (or put up).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
My appologies! Given the immense support you give the Javelin forum, I assumed that you were a parallax employee.
I thank you again for the time you have spent assisting everyone and assisting Parallax and assisting me.
That said, I'm now asking for more of your time....
I still can't get the USB logger to work. When I run your test program, it appears to crash at different times.
I have tried about 10 USB drives and have formatted them a number of times. It is as though the USB Data Logger is just slow and we're trying to talk to it too fast !
Here is the output of several runs;
Datalogger Test Program for Javelin
Datalogger Test Program for Javelin
No disk present. Please insert disk.
No disk present. Please insert disk.
Datalogger Test Program for Javelin
No disk present. Please insert disk.
>
\>
disk freespace -1 bytes
Datalogger Test Program for Javelin
>
\>
disk freespace -1 bytes
disk freespace 1 kilobytes
disk freespace 0 megabytes
disk serial number 00000000
Directory testdir not found
rootdirectory is:
Command Failed
Datalogger Test Program for Javelin
No disk present. Please insert disk.
No disk present. Please insert disk.
>
\>
disk freespace -1 bytes
disk freespace 1 kilobytes
disk freespace 0 megabytes
disk serial number 00000000
Directory testdir not found
rootdirectory is:
creating testdir and testfile.txt ...
directory not created
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The robot is going to lose. Not by much. But when the final score is tallied, flesh and blood will beat the damn monster.
Adam Smith
I wrote the tesprogram using a 1GB stick formatted in FAT16
512 bytes sectors.
I don't know if FAT32 (sticks > 2GB) works with the datalogger.
regards peter
I have used a range of sticks from 256M to 1G and formatted them in FAT and FAT32. I tried to use the comandline to force FAT16, but it wouldn't let me do it.
I have written a really basic piece of code using you libraries which may be homing in on the problem. When I run;
while (!READ)
{
READ = logger.diskPresent();
CPU.delay (5000);
System.out.println("Checking for disk \r" );
}
System.out.println("Done \r" );
CPU.delay (5000); //Allow time for the system to settle
logger.receivePromptOrError(2000); //get unsollicited message from datalogger
READ = false;
while(!READ)
{
READ = logger.openFileForWrite("GPSLogs.txt",0,0);
CPU.delay (5000); //Allow time for the system to settle
System.out.println("trying to open file \r" );
}
System.out.println("Done \r" );
CPU.delay (5000); //Allow time for the system to settle
logger.receivePromptOrError(2000); //get unsollicited message from datalogger
READ = false;
while(!READ)
{
READ = logger.writeToFile("Hello",5,0);
CPU.delay (5000); //Allow time for the system to settle
System.out.println("trying to write to file \r" );
}
System.out.println("Done \r" );
CPU.delay (5000); //Allow time for the system to settle
logger.receivePromptOrError(2000); //get unsollicited message from datalogger
READ = false;
while(!READ)
{
READ = logger.closeFile("GPSLogs.txt");
CPU.delay (5000); //Allow time for the system to settle
System.out.println("trying to close file \r" );
}
System.out.println("Done \r" );
CPU.delay (5000); //Allow time for the system to settle
logger.receivePromptOrError(2000); //get unsollicited message from datalogger
I get the following response;
Starting
Checking for disk
Checking for disk
Checking for disk
Checking for disk
Done
trying to open file
Done
trying to write to file
Done
trying to close file
Done
The file is written to the disk, however there is not data in it.
I don't understand how I am getting a 'true' return for the file write, without it actually writing the data.
I
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The robot is going to lose. Not by much. But when the final score is tallied, flesh and blood will beat the damn monster.
Adam Smith
I have setup the datalogger module on the Javelin Demoboard.
Initially I got all weird responses due to the wirelinks I used
(those are the 6cm wirelinks that parallax supplied with the board).
I suspect these wirelinks pick up a lot of noise, so I replaced them
with·four 1k resistors (these also protect your javelin I/O pins).
See picture. Note that the I/O pins are different !!
Attached you·will find my test program to enter manual commands
so you can observe·the response of the datalogger.
Strangely enough, the datalogger reports $ bytes free after command
diskIdentify (see attached text file which is logged from the IDE message window).
I used the IDE beta as that does not show the echo that v2.0.3 shows,
and it allows logging of the message window.
If you setup your datalogger in the same way, we can work together·so it will
work for you as well in the end.
regards peter
·
Post Edited (Peter Verkaik) : 3/23/2009 11:32:49 AM GMT
Again, thank you for your help.
I have followed your instructions (photo attached)
The output from the new test program is as expected, other than the fourth last line;
Datalogger Manual Commands Test Program for Javelin
disk info:
Ver 03.64VDAPF On-Line:
Device Detected P2
No Upgrade
\>
USB VID = $0A48
USB PID = $3260
Vendor Id = HP
Product Id = Digital Drive
Revision Level = 1.00
I/F = SCSI
You can now enter manual commands
Bytes/Cluster = $000800{$0D}
Capacity = $0000077D2800 Bytes{$0D}
Free Space = $ Bytes{$0D}
{$0D}
\>{$0D}
ddiirr
{$0D}
TESTDIR DIR{$0D}
\>{$0D}
It appears that the DIR command is echoed where it is not in your output (ddiirr).
I have also tried to run your original test program, but the output shows that the same problems are happenning;
Datalogger Test Program for Javelin
No disk present. Please insert disk.
No disk present. Please insert disk.
>
\>
disk freespace -1 bytes
disk freespace -5 kilobytes
disk freespace 0 megabytes
disk serial number 00000000
Directory testdir not found
rootdirectory is:
Command Failed
creating testdir and testfile.txt ...
Using readFile: File testfile.txt:
Filesize is 0 bytes
Using readFromFile: File testfile.txt: ABCDE
Regards,
I
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The robot is going to lose. Not by much. But when the final score is tallied, flesh and blood will beat the damn monster.
Adam Smith
The echoeing of DIR is because you use the IDE v2.0.3
so anything typed in the message window is echoed.
The IDE beta (see sticky thread) does not have this
echoeing.
Something is messed up because the original program
doesn't work for me either in this setup. It definitely used
to work on the custom board I used when I wrote the
program (that one used the multiplexer that involved·pins·8 and 9
as said before). I will have to check that schematic and see
if I can get such a board so I can figure this out.
regards peter
··
I
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The robot is going to lose. Not by much. But when the final score is tallied, flesh and blood will beat the damn monster.
Adam Smith
I asked if anyone had it working in the Basic Stamp forum and got this reponse;
http://forums.parallax.com/forums/default.aspx?f=5&m=337864
This may help, though it is for teh UART not the SPI.
I
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The robot is going to lose. Not by much. But when the final score is tallied, flesh and blood will beat the damn monster.
Adam Smith
Attached is an updated version that works with the setup as decscribed in the above posts.
Here is the output of the test program:
Notice that after inserting the disk, that synchronization is off until reading freespace in kilobytes.
Best way to deal with this is doing: read firmware and freespace, then discard those readings.
After that synchroniztion should be ok. You can always use the Echo() command to synchronize.
regards peter
Post Edited (Peter Verkaik) : 3/25/2009 8:32:32 AM GMT
see attached classes. It is the same test program but uses Uarts instead
of SPI.
I have not tested this.
regards peter
I have been on th eroad and have just seen your latest post.
I will try today and get back to you.
I
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The robot is going to lose. Not by much. But when the final score is tallied, flesh and blood will beat the damn monster.
Adam Smith
It works.
That's only taken about three weeks and a few hundred hours.
Thank's Peter, you are a complete legend. I would not have been able to get this happenning without your help.
Istha
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The robot is going to lose. Not by much. But when the final score is tallied, flesh and blood will beat the damn monster.
Adam Smith
If you want, you could try the serial interface. If the logger outputs
the exact same data as in SPI mode, the serialmode classes should work
also, but note the different pin assignments.
If you get that working, you could try leaving out the handshake signals
and tying the logger's CTS pin to ground. The javelin has a 255 byte receive
buffer and so if you never read more then 240 bytes at a time, that should
work also. That saves you two I/O pins.
Now, if that works, you can try connecting the logger's rx pin to its tx pin
via a 1k resistor. Connect the logger's rx pin to a javelin I/O pin that
will be used for a bidirectional uart. If the logger discards any received
bytes while it is transmitting, this may well work, saving another I/O pin.
regards peter
I'm really struggling with this one.
I have set up the Datalogger on my Board as Peter suggested with four 1k resistors. Now I have tried to get it working both with own programs and with Peter's.
The USB-stick I am using is actually the one proposed on the parallax site (Transcend® USB Flash Drive 1GB). Here is what I get:
DataloggerUart_test: "No disk present. Please insert disk." - Datalogger stays in "Power On" mode (leds flash for two seconds constantly) - USB LED constant
DataloggerSPI_test: "No disk present. Please insert disk." - Datalogger shows Power On, then no led at all - USB LED constant
Now, one detail that might help is, if I start the SPI program with the Jumper in UART mode, the Datalogger actually seems to recognize the Stick (constant red led).
Any hints on where to start?
Thanks a lot in advance!
Post Edited (Eikin) : 5/10/2009 1:30:39 PM GMT
If the jumper is in Uart mode, then you must use the Uart test program.
Note that the pin assignments are different for SPI and Uart mode and that
I have not tested Uart mode.
regards peter
Say, what are the using restrictions of your libraries?
The VDAP firmware (I used v3.62) does require your usb stick
to have·512-byte sectors. Maybe not all usb sticks use that format.
(reformatting a stick may help in that case)
regards peter