Bluetooth enabled flash drives

Here is a simple project showing how a pen drive/hard drive can be designed so that file/data transfers can be made without the help of a computer.!

 

watch the video on Youtube

     

  • Congrats.. Could you please share your code here?

  • burky said:

    Congrats.. Could you please share your code here?

    Am not really a good programmer... and so the code is somewhat bulky...

    /* Bluetooth Enabled flash drives

    Note: There is a bug in the SDMMC library. Hence it enters into an infinite loop whenever we try to return anything in its func (Maybe i am wrong due to poor programming skills). since i can't overcome that problem, i have written a bulky program.
    */

    #include<rxduino.h>
    #include <SDMMC.h>
    #include<liquidCrystal.h>
    #include<iodefine_gcc63n.h>

    LiquidCrystal lcd(22,23,24,25,26,27,28);
    SDMMC SD;

    void disp();
    void ser();

    char *a[12];
    char *b[12];
    volatile int i,k;
    signed int forward,count;

    int main()
    {

    Serial.begin(38400); // Initialize virtual COM port
    pinMode(10, OUTPUT);
    pinMode(43, INPUT);
    pinMode(42, INPUT);
    pinMode(41, INPUT);
    pinMode(40, INPUT);
    pinMode(39, INPUT);
    pinMode(38, INPUT);
    pinMode(9, OUTPUT);
    pinMode(8, OUTPUT);
    digitalWrite(8, 0);
    digitalWrite(9, 0);

    delay(500);
    Serial1.begin(38400,SCI_SCI6B); // initialize Serial communication with HC-05 bluetooth module
    SD.begin(10);
    lcd.begin(16,2);
    lcd.clear();
    int len=3;
    while((len<10)&&(len>0))
    {
    lcd.clear();
    lcd.print("-----Hello------");
    lcd.setCursor(0,1);
    lcd.print("Wait for");
    lcd.setCursor(10,1);
    lcd.print(len);
    delay(1000);
    len--;
    }
    delay(200);
    lcd.clear();
    lcd.print(" Turn ON ");
    lcd.setCursor(2,1);
    lcd.print("Bluetooth.?");

    while(1)
    {
    if(digitalRead(43)==0)
    {
    delay(200); // debouncing delay
    if(digitalRead(43)==0)
    {
    digitalWrite(8, 1);
    delay(100);
    digitalWrite(9, 1);
    delay(100);
    lcd.clear();
    delay(100);
    lcd.clear();
    lcd.print(" Connect to ");
    lcd.setCursor(0,1);
    lcd.print(" Device..?");
    while(1)
    {
    if(digitalRead(43)==0)
    {
    delay(200);
    if(digitalRead(43)==0)
    {
    delay(100);
    lcd.clear();
    delay(1000);
    Serial1.write("AT+NAME=HC-05\n");
    ser();
    Serial1.write("AT+NAME?\n");
    ser();
    delay(100);
    Serial1.write("AT+ROLE=0\n");
    delay(100);
    Serial1.write("AT+UART=115200,0,0\n");

    delay(100);
    Serial1.write("AT+CMODE=0\n");

    delay(100);
    Serial1.write("AT+INIT\n");
    ser();
    delay(100);
    Serial1.write("AT+CLASS=0\n");
    ser();
    delay(100);
    Serial1.write("AT+BIND=00af,af,a42988\n");
    ser();
    delay(100);
    Serial1.write("AT+PAIR=00af,af,a42988,20\n"); // pair with the given address
    ser();
    Serial1.write("AT+FSAD=00af,af,a42988\n");
    ser();
    Serial1.write("AT+LINK=00af,af,a42988\n");
    ser();
    break;
    }
    }
    if(digitalRead(42)==0)
    {
    delay(200);
    if(digitalRead(42)==0)
    {
    delay(1000);
    lcd.clear();
    delay(10);
    Serial1.write("AT+ORGL\n"); // reset the specifications
    delay(100);
    Serial1.write("AT+NAME=HC-05\n");
    ser();
    Serial1.write("AT+NAME?\n");
    ser();
    lcd.clear();
    delay(100);
    digitalWrite(8, 0);
    digitalWrite(9, 0);
    delay(1000);
    digitalWrite(9, 1);
    delay(100);
    break;
    }
    }
    }



    delay(100);
    lcd.clear();
    delay(1000);
    lcd.clear();
    lcd.print("Paired...!");

    delay(2000);
    lcd.clear();

    File root = SD.open("/"); // SD Files detection part

    i=0;
    k=0;
    volatile int entries=0;
    root.seek(0);

    while(true)
    {
    dir:
    File entry = root.openNextFile();
    if(!entry)
    {
    root.rewindDirectory();
    break;
    }

    a[i]=strdup(entry.name());
    Serial.print(a[i]);
    b[k]=strdup(a[i]);
    i++;
    k++;

    if(entry.isDirectory())
    {
    goto dir;
    }
    else
    {
    Serial.print("\t\t");
    Serial.println(entry.size(), DEC);
    entries++;
    }
    }

    Serial.print("\n\n");
    Serial.print(entries);
    Serial.println( " entries found." );
    lcd.clear();
    lcd.print(entries);
    lcd.setCursor(3,0);
    lcd.print("files found");

    lcd.setCursor(0,1);
    lcd.print("Press OK(scroll)");
    forward=-1;
    count=0;
    Serial.print("\n\n");
    Serial.println("done!");


    while(1) //loop for scroll and send/cancel switches
    {
    if(digitalRead(43)==0)
    {
    delay(200);
    if(digitalRead(43)==0)
    {
    machi:
    lcd.clear();
    lcd.print("Press up & down ");
    lcd.setCursor(0,1);
    lcd.print(" for files ");
    while(1)
    {
    if(digitalRead(41)==0) // scroll down switch loop
    {
    delay(200);
    if(digitalRead(41)==0)
    {
    count+=1;
    forward+=1;
    if(forward>=entries)
    {
    lcd.clear();
    lcd.print("------END------");
    forward=entries;
    count=entries+1;
    }
    else
    {
    disp();
    lcd.setCursor(0,0);
    lcd.print(count);
    lcd.setCursor(2,0);
    lcd.print(".");
    lcd.setCursor(3,0);
    lcd.print(a[forward]);
    }

    }
    }

    if(digitalRead(40)==0) // scroll up switch
    {
    delay(200);
    if(digitalRead(40)==0)
    {
    count-=1;
    forward-=1;
    if(forward<0)
    {
    lcd.clear();
    lcd.print("-----Home-----");
    forward=-1;
    count=0;
    }
    else
    {
    disp();
    lcd.setCursor(0,0);
    lcd.print(count);
    lcd.setCursor(2,0);
    lcd.print(".");
    lcd.setCursor(3,0);
    lcd.print(a[forward]);
    }
    }
    }
    if(digitalRead(39)==0) // send switch
    {
    delay(200);
    if(digitalRead(39)==0)
    {
    lcd.clear();
    delay(1000);
    lcd.clear();
    File Myfile = SD.open(b[forward]);
    lcd.clear();
    lcd.print("Sending.........");
    lcd.setCursor(0,1);
    lcd.print(b[forward]);
    while(Myfile.available()) // file reading and sending loop
    {
    Serial1.write(Myfile.read());
    delay(5);
    if(digitalRead(38)==0) // cancel switch loop
    {
    delay(200);
    if(digitalRead(38)==0)
    {
    lcd.clear();
    lcd.print("Cancelling....");
    delay(2000);
    goto machi;
    }
    }
    }
    while(!Myfile.available())
    {
    lcd.clear();
    lcd.print("File Sent....");
    delay(2000);
    goto machi;
    }
    }
    }
    }
    }
    }
    }
    }
    }

    if(digitalRead(42)==0) // Bluetooth OFF
    {
    delay(200);
    if(digitalRead(42)==0)
    {
    delay(000);

    File root = SD.open("/"); // SD Files detection part

    i=0;
    k=0;
    volatile int entries=0;
    root.seek(0);

    while(true)
    {
    repeat:
    File entry = root.openNextFile();
    if(!entry)
    {
    root.rewindDirectory();
    break;
    }

    a[i]=strdup(entry.name());
    Serial.print(a[i]);
    b[k]=strdup(a[i]);
    i++;
    k++;

    if(entry.isDirectory())
    {
    goto repeat;
    }
    else
    {
    Serial.print("\t\t");
    Serial.println(entry.size(), DEC);
    entries++;
    }
    }

    Serial.print("\n\n");
    Serial.print(entries);
    Serial.println( " entries found." );
    lcd.clear();
    lcd.print(entries);
    lcd.setCursor(3,0);
    lcd.print("files found");

    lcd.setCursor(0,1);
    lcd.print("Press OK (scroll)");
    forward=-1;
    count=0;
    Serial.print("\n\n");
    Serial.println("done!");

    while(1)
    {
    if(digitalRead(43)==0)
    {
    delay(200);
    if(digitalRead(43)==0)
    {
    mach:
    lcd.clear();
    lcd.print("Press up & down ");
    lcd.setCursor(0,1);
    lcd.print(" for files ");
    while(1)
    {
    if(digitalRead(41)==0)
    {
    delay(200);
    if(digitalRead(41)==0)
    {
    count+=1;
    forward+=1;
    if(forward>=entries)
    {
    lcd.clear();
    lcd.print("------END------");
    forward=entries;
    count=entries+1;
    }
    else
    {
    disp();
    lcd.setCursor(0,0);
    lcd.print(count);
    lcd.setCursor(2,0);
    lcd.print(".");
    lcd.setCursor(3,0);
    lcd.print(a[forward]);
    }
    }
    }
    if(digitalRead(40)==0)
    {
    delay(200);
    if(digitalRead(40)==0)
    {
    count-=1;
    forward-=1;
    if(forward<0)
    {
    lcd.clear();
    lcd.print("-----Home-----");
    forward=-1;
    count=0;
    }
    else
    {
    disp();
    lcd.setCursor(0,0);
    lcd.print(count);
    lcd.setCursor(2,0);
    lcd.print(".");
    lcd.setCursor(3,0);
    lcd.print(a[forward]);
    }
    }
    }
    if(digitalRead(39)==0)
    {
    delay(200);
    if(digitalRead(39)==0)
    {
    lcd.clear();
    lcd.print("Can't Send File!");
    lcd.setCursor(0,1);
    lcd.print("Bluetooth 'OFF' ");
    delay(3000);
    goto mach;
    }
    }
    }
    }
    }
    }
    }
    }
    }
    }


    void disp()
    {
    lcd.clear();
    lcd.setCursor(0,1);
    lcd.print("Send");
    lcd.setCursor(10,1);
    lcd.print("Cancel");
    }

    void ser()
    {
    while(1)
    {
    if(Serial1.available())
    {
    lcd.write(Serial1.read());
    }
    else if(digitalRead(43)==0)
    {
    delay(200);
    if(digitalRead(43)==0)
    {
    lcd.clear();
    break;
    }
    }
    }
    }