Transfer jpg in SD card to iPhone through Bluetooth

Hi everyone!

First of all,I have implemented a project which store camera snapshot image into SD card. The project is show as below:

the parts list:
1 x Arduino UNO
1 x 2M_TTL_Camera
1 x SD Card Breakout Board
1 x SD card
Several jumper wires

then I wanna add a Bluetooth module(4.0 of course) and implement an app in iPhone(yes I am learning swift and know there are some Bluetooth frameworks in iOS development.) which can get the jpg in the SD cards.

So the question is:

1.Could the idea work?
2.Are there some similar projects which I can learn from?
3.Any problems I may meet and any suggestion?

I wil log my processing in this subject, thanks!

Up for this one! Only in my case, I'll be sending txt files instead of jpg ;o

1.Could the idea work?

If you are adept at Arduino coding AND are adept at iPhone programming (and are sure that there is a market for the app and are will to kiss Apple's ass enough (I mean pay for the right to upload apps to your own phone), then, yes the idea could work.

2.Are there some similar projects which I can learn from?

Obviously.

3.Any problems I may meet and any suggestion?

Yes. No.

diaosiki:
I wil log my processing in this subject, thanks!

I've used Bluetooth with an Android before but I haven't every used Bluetooth with an iPhone. I'm very curious about the hardware you'll be using.

I look forward to updates.

Are you aware of the many inexpensive WiFi cameras? You can purchase a camera which will take a photo and send it over WiFi. These cameras don't cost much more than $20.

DuaneDegn:
I’ve used Bluetooth with an Android before but I haven’t every used Bluetooth with an iPhone. I’m very curious about the hardware you’ll be using.

I look forward to updates.

Are you aware of the many inexpensive WiFi cameras? You can purchase a camera which will take a photo and send it over WiFi. These cameras don’t cost much more than $20.

The hardware are:
1 x Arduino UNO R3
1 x 2M_TTL_Camera(LS-Y201-2MP is LinkSprite’s new generation high resolution serial port camera module. )
1 x SD Card Breakout Board(also from LinkSprite)
1 x SD card

I know some useful solutions of using WiFi cameras, however, in my prototype I prefer to use bluetooth because I
thought my product may often used in a none-WiFi situation. It should transfer the jpg to iPhone through BT, then the phone transfer jpg to server through 3G/4G.

diaosiki:
my product may often used in a none-WiFi situation. It should transfer the jpg to iPhone through BT, then the phone transfer jpg to server through 3G/4G.

The inexpensive cameras act as their own WiFi hotspot. Hotspot might not be the correct term. The phone has a built in WiFi device which doesn't require an additional router. The camera can communicate directly with the phone.

DuaneDegn:
The inexpensive cameras act as their own WiFi hotspot. Hotspot might not be the correct term. The phone has a built in WiFi device which doesn't require an additional router. The camera can communicate directly with the phone.

Got it, it seems pretty good, I will check that.

It is called ad-hoc. No need for a gateway/router.

Hi guys, I am coming back to report the progress.

The good news is I learned how to use SD card module, I bought all the parts and connect together like the picture showed.

The bad news is though code seems ok, the camera give the HEX number on the serial window without stop. This is not what the lecture said. I am very confused now.

If anybody can help?the code is below

//*******************************************************
//              www.linksprite.com 
// Note:
// 1. SD must be formated to FAT16
// 2. As the buffer of softserial has 64 bytes,
//    so the code read 32 bytes each time
// 3. Please add the libaray to the lib path
// 
// * SD card attached to SPI bus as follows:
// * MOSI - pin 11
// * MISO - pin 12
// * CLK - pin 13
// * CS - pin 4
//*******************************************************
#include <SoftwareSerial.h>
#include <SPI.h>
#include <SD.h>

SoftwareSerial mySerial(5,6);          // Set Arduino pin 4 and 5 as softserial

byte ZERO = 0x00;
byte incomingbyte;
long int j=0,k=0,count=0,i=0x0000;
uint8_t MH,ML;
boolean EndFlag=0;
File  myFile;

void SendResetCmd()
{
 mySerial.write(0x56);
 mySerial.write(ZERO);
 mySerial.write(0x26);
 mySerial.write(ZERO);
}

/*************************************/
/* Set ImageSize :
/* <1> 0x22 : 160*120
/* <2> 0x11 : 320*240
/* <3> 0x00 : 640*480
/* <4> 0x1D : 800*600
/* <5> 0x1C : 1024*768
/* <6> 0x1B : 1280*960
/* <7> 0x21 : 1600*1200
/************************************/
void SetImageSizeCmd(byte Size)
{
 mySerial.write(0x56);
 mySerial.write(ZERO);
 mySerial.write(0x54);
 mySerial.write(0x01);
 mySerial.write(Size);
}

/*************************************/
/* Set BaudRate :
/* <1> 0xAE  :   9600
/* <2> 0x2A  :   38400
/* <3> 0x1C  :   57600
/* <4> 0x0D  :   115200
/* <5> 0xAE  :   128000
/* <6> 0x56  :   256000
/*************************************/
void SetBaudRateCmd(byte baudrate)
{
 mySerial.write(0x56);
 mySerial.write(ZERO);
 mySerial.write(0x24);
 mySerial.write(0x03);
 mySerial.write(0x01);
 mySerial.write(baudrate);
}

void SendTakePhotoCmd()
{
mySerial.write(0x56);
mySerial.write(ZERO);
mySerial.write(0x36);
mySerial.write(0x01);
mySerial.write(ZERO);
}

void SendReadDataCmd()
{
MH=i/0x100;
ML=i%0x100;
mySerial.write(0x56);
mySerial.write(ZERO);
mySerial.write(0x32);
mySerial.write(0x0c);
mySerial.write(ZERO);
mySerial.write(0x0a);
mySerial.write(ZERO);
mySerial.write(ZERO);
mySerial.write(MH);
mySerial.write(ML);
mySerial.write(ZERO);
mySerial.write(ZERO);
mySerial.write(ZERO);
mySerial.write(0x20);
mySerial.write(ZERO);
mySerial.write(0x0a);
i+=0x20;
}

void StopTakePhotoCmd()
{
mySerial.write(0x56);
mySerial.write(ZERO);
mySerial.write(0x36);
mySerial.write(0x01);
mySerial.write(0x03);
}

void setup()
{

Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

Serial.print("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
Serial.println("please waiting ....");  
}

void loop()
{
 byte a[32];
 int ii;       
 mySerial.begin(115200);
 delay(200);
 SendResetCmd();//Wait 2-3 second to send take picture command
 delay(2000);
 SetBaudRateCmd(0x2A);
 delay(100);
 mySerial.begin(38400);
 delay(100);
 SetImageSizeCmd(0x21);
 delay(100);
 SendTakePhotoCmd();
 delay(3000);
 while(mySerial.available()>0)
 {
    incomingbyte=mySerial.read();
 }
 myFile = SD.open("pic.jpg", FILE_WRITE); //<strong><span style="color: #ff0000;">The file name should not be too long</span></strong>
 while(!EndFlag)
 {
   j=0;
   k=0;
   count=0;
   SendReadDataCmd();
   delay(5);
   while(mySerial.available()>0)
   {
     incomingbyte=mySerial.read();
     k++;
     delayMicroseconds(100); 
     if((k>5)&&(j<32)&&(!EndFlag))
     {
       a[j]=incomingbyte;
       if((a[j-1]==0xFF)&&(a[j]==0xD9))     //tell if the picture is finished
       EndFlag=1;
       j++;
      count++; 
     }
    }

   for(j=0;j<count;j++)
   {
     if(a[j]<0x10)  Serial.print("0");
     Serial.print(a[j],HEX);           // observe the image through serial port
     Serial.print(" ");
   }
   for(ii=0; ii<count; ii++)
     myFile.write(a[ii]);
   Serial.println();
 }
 myFile.close();
 Serial.print("Finished writing data to file");
 while(1);
}

diaosiki:
The bad news is though code seems ok, the camera give the HEX number on the serial window without stop.

I'd think this is what you'd want? Can't you connect a Bluetooth module to the Arduino and have the data sent to the smartphone?

diaosiki:
This is not what the lecture said. I am very confused now.

What lecture?

The main loop seems off to me. Made some annotations. You may have missed some {} around the IF statement task?

j=0;    // set j to 0;
   k=0;    // set k to 0;
   count=0; // set count to 0;
   SendReadDataCmd();   //ask for data to be sent.
   delay(5);      // Why does this exist? No point.
   while(mySerial.available()>0)    // While there is some data...which there may not be...because 5ms was not long enough.
   {
     incomingbyte=mySerial.read();   // read the incoming byte
     k++;                            //increment k
     delayMicroseconds(100);         // another delay...for some reason?
     if((k>5)&&(j<32)&&(!EndFlag))   // if there have been more than 5 bytes read and less than 32 and it is not the "end of the program"
     {
       a[j]=incomingbyte;            // put the 6th byte in an array
       if((a[j-1]==0xFF)&&(a[j]==0xD9))     //tell if the picture is finished...this returns nothing and is not an actual if loop...you are MISSING {}?
       EndFlag=1;                    //set this to TRUE once there has been from byte 6 to the end byte recieved.
       j++;                          // increment j each time?
      count++;                       //increment counter
     }
    }

   for(j=0;j<count;j++)                // dumpo the contents of array a till count is reached.
   {
     if(a[j]<0x10)  Serial.print("0");  //if the value of the byte (byte number 6 onwards from the original) is less than 16...print a 0 to the COM port viewer.
     Serial.print(a[j],HEX);           // print the HEX value held in array address j...
     Serial.print(" ");                // put a space in
   }

Johnny010:
The main loop seems off to me. Made some annotations. You may have missed some {} around the IF statement task?

j=0;    // set j to 0;

k=0;    // set k to 0;
  count=0; // set count to 0;
  SendReadDataCmd();  //ask for data to be sent.
  delay(5);      // Why does this exist? No point.
  while(mySerial.available()>0)    // While there is some data…which there may not be…because 5ms was not long enough.
  {
    incomingbyte=mySerial.read();  // read the incoming byte
    k++;                            //increment k
    delayMicroseconds(100);        // another delay…for some reason?
    if((k>5)&&(j<32)&&(!EndFlag))  // if there have been more than 5 bytes read and less than 32 and it is not the “end of the program”
    {
      a[j]=incomingbyte;            // put the 6th byte in an array
      if((a[j-1]==0xFF)&&(a[j]==0xD9))    //tell if the picture is finished…this returns nothing and is not an actual if loop…you are MISSING {}?
      EndFlag=1;                    //set this to TRUE once there has been from byte 6 to the end byte recieved.
      j++;                          // increment j each time?
      count++;                      //increment counter
    }
    }

for(j=0;j<count;j++)                // dumpo the contents of array a till count is reached.
  {
    if(a[j]<0x10)  Serial.print(“0”);  //if the value of the byte (byte number 6 onwards from the original) is less than 16…print a 0 to the COM port viewer.
    Serial.print(a[j],HEX);          // print the HEX value held in array address j…
    Serial.print(" ");                // put a space in
  }

thanks, I will check that and come back with results later.