Feb 13, 2019

Using hobbytronics USB Flash Drive breakout board with Arduino

To log data from a test system running a microcontroller, I found a flash drive reader (only) from Hobbytronics.  https://www.hobbytronics.co.uk/usb-host-flash-drive  I used the smaller "mini" version.

To get the device to write to a file from demo code (first example at btm of pg) seemed to work ok.
To send a command and read back responses, some hours of testing and several modifications were needed for my configuration to work.

Things to check first:

  • Is the baud rate to the USB Drive Host board set to default of 9600 to start?
  • Is the Tx of the board connected to the Rx of the MCU and vice versa?
  • Are command strings terminated with a Serial1.write(13) or '\r' ?

The example uses softwareSerial library. I used a hardware port, preferred if available. (Serial1 on Teensyduino 3.x)

If no response comes from your command, you'll need additional delay. I had to add time after the command, and a time between each character sent. In the example code, a while(!Serial.available()) is used to wait until the first character starts.

While troubleshooting, I connected directly to the board from a TTL-to-USB interface to TeraTerm terminal program. Once the first 3 items above were correct, Commands (such as DATE, CD, DIR) worked just fine.

By adding:

  •    delay(100) after each sent command
  •    adding a delay(1) before each character read in the while loop, 

...

sprintf(mystring,"$TIME \r");
mySerial.write(mystring);
delay(100);   // ***
getFromFlash();

...

}


void getFromFlash() {
    char c;
    // Hang out here
    while(!mySerial.available());        // Wait for data to be returned

    // loop waiting for a character for each line separately
    // Read and display contents of line returned
    while (mySerial.available() > 0) {
        c = mySerial.read();
        delay(1);   // ***
        Serial.write(c);
    }
    if (c != '\r' && c != '\n') {
        // Serial.write(13);
        Serial.write(10);
    }
}

Other notes


asdf

No comments: