Hey all, I'm unhappy to say that I'm adding yet another thread on issues with the VDIP1 module. I could get it to work with a certain bit of code, but now I can't even force that to work. Here's the link for that:
no messing around with handshaking, no looping, no nothing. But no file shows up on the flash drive. I've looked at every blog I could find (lots), but no bolt of inspiration has stricken yet. Perhaps one out of every twenty or thirty uploads I can get something to happen, but even without changing anything I can not reproduce it.
Might as well post the circuit. it goes arduino -> vdip1
gnd -> gnd
5V -> 5VO
D2 -> AD1
D3 -> ADO
and then VDIP1 has AD2 and AD3 tied together. I know this is bad, but I have gotten it to work in the past.
After the headache of my life and several eruptions, I have successfully gotten it to work a bit. After trying the instructions on this page (for the nth time I might add) it works! http://www.unlogic.co.uk/2009/03/usb-storage-and-arduino/
I then expanded the code a bit to actually write a file.
#include <NewSoftSerial.h>
NewSoftSerial mySerial(3, 4);
void setup()
{
Serial.begin(9600);
// set the data rate for the NewSoftSerial port
mySerial.begin(9600);
mySerial.print("IPA");
mySerial.print(13, BYTE);
Serial.println("Setupdone");
}
void loop()
{
int incoming = 0;
if (Serial.available()) {
incoming = Serial.read();
}
if (incoming =='1'){
mySerial.print("DIR");
mySerial.print(13, BYTE);
incoming = 0;
}
if (incoming =='2'){
mySerial.print("OPW LOG.TXT");
mySerial.print(13, BYTE);
incoming = 0;
}
if (incoming == '3'){
mySerial.print("WRF 6");
mySerial.print(13, BYTE);
mySerial.print("Hello");
mySerial.print(13, BYTE);
incoming =0;
}
if(incoming == '4')
{
mySerial.print("CLF LOG.TXT");
mySerial.print(13, BYTE);
incoming = 0;
}
if (mySerial.available()) {
Serial.print((char)mySerial.read());
}
}
and it works jim-dandy. I've been thinking though, I could never get it to log a non-string variable, like the unsigned long returned from millis(). So I decided to change the long into a string, and it works great! I dunno if this is necessary, though, because I've had such a spotty experience with the vdip1. Here's the current code:
#include <NewSoftSerial.h>
NewSoftSerial mySerial(3, 4);
void setup()
{
Serial.begin(9600);
// set the data rate for the NewSoftSerial port
mySerial.begin(9600);
mySerial.print("IPA");
mySerial.print(13, BYTE);
Serial.println("Setupdone");
}
void loop()
{
int incoming = 0;
if (Serial.available()) {
incoming = Serial.read();
}
if (incoming =='1'){ // lists the directories on the flash drive
mySerial.print("DIR");
mySerial.print(13, BYTE);
incoming = 0;
}
if (incoming =='2'){ // opens the file
mySerial.print("OPW LOG.TXT");
mySerial.print(13, BYTE);
incoming = 0;
}
if (incoming == '3'){ // writes "Hello" to the file
mySerial.print("WRF 6");
mySerial.print(13, BYTE);
mySerial.print("Hello");
mySerial.print(13, BYTE);
incoming =0;
}
if(incoming == '4') // closes the file
{
mySerial.print("CLF LOG.TXT");
mySerial.print(13, BYTE);
incoming = 0;
}
if(incoming == '5') // writes the current time to the file
{
String time = String(millis(), DEC);
mySerial.print("WRF ");
mySerial.print((time.length()+1)); //add one for a carriage return
mySerial.print(13, BYTE);
mySerial.print(time);
mySerial.print(13, BYTE);
Serial.println(time); // for checking to make sure it's consistent
}
if (mySerial.available()) {
char letter = (char)mySerial.read();
if(letter == '>') // when it prints "D:\>" it goes to the next line
Serial.println(letter);
else
Serial.print(letter);
}
}
I think I cheated.
I needed to log HOUR(0-23), DATE(1-31), MONTH(1-12), YEAR(0-99), TEMP1(0-99), TEMP2(0-99).
Not being very clever with STRINGS etc I decided to convert each number into TENS & UNITS using Tx = x/10 and Ux = x%10 so then I had an exact number of characters no matter what the values were.
I then counted up all the bits including the (,) and............GOT IT WRONG
So then I adjusted up and down until it worked.
Good luck.
Peter