VDIP1 USB Host Controller

March 27, 2010

I got my VDIP1 USB Host controller from Saelig today and was able to get it hooked up and reading a Flash drive in a couple hours. Because the Arduino only has one TX / RX serial pin if you connect it using them you cannot communicate with the computer over the built in USB UART on the Arduino. To get around this limitation there are a number of libraries that allow serial communication over non-serial pins.

I chose the NewSoftSerial library to give access to the VDIP1.  The first attempt was to use the AFSoftLibrary and it just did not work properly causing some strange looping of the Setup() method.  After switching to the NewSoftSerial library everything started working and I had no trouble doing a DIR and creating a new file on the flash drive.  I am posting an early version of the sketch just so i can get a good example and a picture / schematic out so expect updates later.  Keep reading for the schema, pic and sketch.

Update: I changed the sketch and schematic / pic to include the RTS / CTS flow control.

VDIP1 USB Host Controller Wiring

VDIP1 USB Host Controller Wiring

Click here to see the picture and sketch.

Picture of the wiring I used with the sketch.

Arduino USB Host Controller with Flash Disk

Arduino USB Host Controller with Flash Disk

I did a little cleaning of the wiring and put it on a proto-shield.

Protoshield new wiring

Protoshield new wiring

The sketch allows sending of any command via the Serial monitor for doing testing. Some common commands would be “~DIR~ ~CD DIRNAME~ ~CD ..~” See the VDIP1 command list for the full file operations.


// RX TX
#include

NewSoftSerial usb(2, 3);

int RTSPin = 5;
int CTSPin = 4;

void setup() {
pinMode(RTSPin, INPUT);
pinMode(CTSPin, OUTPUT);

usb.begin(9600);
//usb.begin(57600); // You can modify the default speed of the VDIP1 with firmware updates to be up to 57600 through newSoftSerial.
digitalWrite(CTSPin, LOW); // Set the CTS to low and keep it there.
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps

Serial.print("Starting");

usb.print("IPA"); // Set to ascii mode.
usb.print(13, BYTE);
}

char usbRx;
byte charIn;

void SendToUsb(char val) {
while (digitalRead(RTSPin) == HIGH) { }
usb.print(val);
digitalWrite(CTSPin, LOW);
}

void SendToUsbTermCmd() {
while (digitalRead(RTSPin) == HIGH) { }
usb.print(13, BYTE);
digitalWrite(CTSPin, LOW);

}

void loop() {
// Disable the sending on the USB device if you have filled more than 50% of your buffer (64 bytes by default)
if (usb.available() > 32) {
digitalWrite(CTSPin, HIGH);
} else {
digitalWrite(CTSPin, LOW);
}
if (usb.available() > 0) { // read the incoming byte
usbRx = usb.read();
if (usbRx == 0x0D) {
Serial.println();
} else {
Serial.print(usbRx);
}
}
if (Serial.available() > 0) { // read the incoming byte
if (Serial.read() == (byte)'~') {
charIn = 0;
while (charIn != (byte)'~') { // wait for header byte again
if (Serial.available() > 0) {
charIn = Serial.read();
Serial.print(charIn, HEX);
if (charIn == (byte)'~') {
Serial.println("breaking");
break;
}
SendToUsb(charIn);
}
}
SendToUsbTermCmd();
}
}
}

Advertisements

9 Responses to “VDIP1 USB Host Controller”

  1. Thanks a lot for this post. I have worked 3full days to setup communication, sync, and behavior for my VDIP1. This post helps complete my program.

  2. Lee said

    Hi,

    Can you please teach me on how to use this on a RFID reader with usb connection? I would like to interface it with Arduino.

    Thanks in advance.

    Regards,
    Lee

  3. rpgduino said

    You would need to know how your RFID reader communicates and likely set it in direct mode. There is likely a protocol they use when reading the RFIDs. Do you have the datasheet for it?

    • Lee said

      http://www.ananiahelectronics.com/RF9315R-u.htm

      The above website is all i can get. Not really a datasheet, but they never provide anymore information.

      I just wan to read the RSSI value from this device. Can the VDIP1 do that?

      • rpgduino said

        This appears to be a simple serial -> usb device. For this you would start the VDIP in data mode and it should just start feeding you data as it gets it in. Loop back the serial to your microcontroller and display the results of what it receives in the VDIP and you may get your results.

  4. Lee said

    Hi,

    I would like to ask the “VDIP1 command list” , where can I find the full list of it?

    Thanks in advance!

    Regards,
    Lee

  5. Lee said

    /***************************************************************************/
    #define DSR 5
    #define DTR 4

    void setup() {
    // initialize both serial ports:
    pinMode(DTR, OUTPUT);
    pinMode(DSR, INPUT);
    Serial.begin(9600);
    Serial1.begin(9600);
    }

    void loop() {
    digitalWrite(DSR, LOW);

    // read from port 1, send to port 0:
    if (Serial1.available()) {
    int inByte = Serial1.read();
    Serial.println(inByte, BYTE);
    }
    }
    /***************************************************************************/

    Above is my arduino code for reading the receiver, according to the data sheet, I just need to assert DSR pin(pin 12) to low to enter DATA mode.

    I’ve asserted DSR to LOW. But it returns me nothing.

    Is there anything else i should do to enter DATA mode? Btw, I’m using the same USB host model as you recommended.

    Thank you for the help these days!

    Regards,
    Lee

    • Lee said

      Is it because the driver of the usb converter restrict me from accessing data unless installed? (Like what happened to a computer, driver installed only the port is detected)

      If so, any solution to it?

      Regards,
      Lee

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: