Pages: [1]   Go Down
Author Topic: How to transfer an image using the WiFi Shield and UNO to a PC  (Read 6219 times)
0 Members and 1 Guest are viewing this topic.
Newark, NJ
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I am working on a project where I need to transfer images taken by an Adafruit TTL camera, store it on a SD Card (optional) and send it to a PC (local server on PC, a JAVA socket or something similar). I researched about it but do not seem to find a conclusive solution to the problem.

I understand that an Arduino does not handles and processes images but I am sure there must be a way to transfer images. It could be done by converting the image to HEX, or break them into bytes and reconstruct them on the PC. I am not worried about the reconstruction part, but I need to transfer the images!

Please help if you already have this figured out or if you are working on something similar.

Thank you very much!

Logged

Newark, NJ
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If any one is willing to answer, is this achievable through SoftSerial library. I tried the code but nothing seems to appear except gibrish characters. If anyone has tried transferring images, please guide me.

Thank you
Logged

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

There's quite a bit of "more information required" to this question, and lots of ways to approach the problem.  One way might be to have your camera write the image to the SD card (as outlined in the Adafruit tutorial for the camera) and then periodically serve up the image as a web page where you can view/save the image on your PC.

By breaking down the problem into chunks you should be able to beat this.

Cheers ! Geoff
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Newark, NJ
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for answering strykeroz. For the project, I am not looking to upload any data on a webpage. I was trying to create a TCP Server which fetches information being sent over a port. The server works fine as long as I am transferring strings of code using the wifi shield.

After having tried that, I learned about Processing, and thought I could use it to capture the images stored on the SD card and generate them on PC. But that does not seem to be working as well.

I was able to get the following code to generate HEX version of an image (I am using an uno and hence thought of using the SoftSerial) but it generates nothing useful. And after I am able to generate the HEX of the image, I also need to write them to the server.

#include <SoftwareSerial.h>
#include <SD.h>

byte incomingbyte;
SoftwareSerial mySerial(4,5);                     //Configure pin 4 and 5 as soft serial port
int a=0x0000,j=0,k=0,count=0,i=0,p=0;                    //Read Starting address       
uint8_t MH = 0x00,ML = 0x00;
boolean EndFlag=0,HeaderFlag=0;
int chipSelect = 4;
File logfile;
                               
void SendResetCmd();
void SetBaudRateCmd();
void SetImageSizeCmd();
void SendTakePhotoCmd();
void SendReadDataCmd();
void StopTakePhotoCmd();

void setup()
{
  Serial.begin(115200);
  mySerial.begin(115200);
  a-=0x20;
  pinMode(10, OUTPUT);
 
  //see if the card is present and can be initialized
  if (!SD.begin(chipSelect)) {
    Serial.print("Card failed, or not present");
    return;
  }
  Serial.println("card initialized.");

 // create a new file
  char filename[] = "Test1.jpg";
  for (uint8_t i = 0; i < 100; i++) {
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (! SD.exists(filename)) {
      // only open a new file if it doesn't exist
      logfile = SD.open(filename, FILE_WRITE);
      break;  // leave the loop!
    }
  }
  Serial.print("Logging to: ");
  Serial.println(filename);
}
 

void loop()
{
     Serial.println("about to take picture...");
     
     byte a[32];
     p=0;
     SendResetCmd();
     delay(4000);                               //After reset, wait 2-3 second to send take picture command
     
     SendTakePhotoCmd();

     while(mySerial.available()>0)
      {
        incomingbyte=mySerial.read();
      }   
       
      while(!EndFlag)
      { 
         j=0;
         k=0;
         count=0;
         SendReadDataCmd();
         delay(20);
          while(mySerial.available()>0)
          {
               incomingbyte=mySerial.read();
               k++;
               if((k>5)&&(j<32)&&(!EndFlag))
               {
               a[j]=incomingbyte;
               if((a[j-1]==0xFF)&&(a[j]==0xD9))      //Check if the picture is over
               EndFlag=1;                           
               j++;
          count++;
               }
          }
         
          for(j=0;j<count;j++)
          {   if(a[j]<0x10)
              Serial.print("0");
              Serial.print(a[j], HEX);
              Serial.print(" ");
          }           //Send jpeg picture over the serial port
         
          if(((a[j-32]==0xFF)&&(a[j-31]==0xD8))||(p))
            {
            logfile.print((char*)a);
            Serial.println();
            p=1;
           
            }
      }
     logfile.close();
     Serial.print("Finished writing data to file"); 
     while(1);   
}

//-----------------
//Camera functions

//Send Reset command
void SendResetCmd()
{
      mySerial.write(0x56);
      mySerial.write((byte)0x0);
      mySerial.write(0x26);
      mySerial.write((byte)0x0);
}

void SetImageSizeCmd()
{
      mySerial.write(0x56);
      mySerial.write((byte)0x0);
      mySerial.write(0x31);
      mySerial.write(0x05);
      mySerial.write(0x04);
      mySerial.write(0x01);
      mySerial.write((byte)0x0);
      mySerial.write(0x19);
      mySerial.write(0x22);
}

void SetBaudRateCmd()
{
      mySerial.write(0x56);
      mySerial.write((byte)0x0);
      mySerial.write(0x24);
      mySerial.write(0x03);
      mySerial.write(0x01);
      mySerial.write(0xAE);
      mySerial.write(0xC8);

}


//Send take picture command
void SendTakePhotoCmd()
{
      mySerial.write(0x56);
      mySerial.write((byte)0x0);
      mySerial.write(0x36);
      mySerial.write(0x01);
      mySerial.write((byte)0x0); 
}

//Read data
void SendReadDataCmd()
{
      MH=a/0x100;
      ML=a%0x100;
      mySerial.write(0x56);
      mySerial.write((byte)0x0);
      mySerial.write(0x32);
      mySerial.write(0x0c);
      mySerial.write((byte)0x0);
      mySerial.write(0x0a);
      mySerial.write((byte)0x0);
      mySerial.write((byte)0x0);
      mySerial.write(MH);
      mySerial.write(ML);   
      mySerial.write((byte)0x0);
      mySerial.write((byte)0x0);
      mySerial.write((byte)0x0);
      mySerial.write(0x20);
      mySerial.write((byte)0x0); 
      mySerial.write(0x0a);
      a+=0x20;                            //address increases 32£¬set according to buffer size
}

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


Logged

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I was trying to create a TCP Server which fetches information being sent over a port. The server works fine as long as I am transferring strings of code using the wifi shield.
So you have a reliable transport for data from your Uno to your PC, it's only you've not managed to reconstruct the image from your HEX representation successfully?  Sounds to me like you're close to getting this solved.  If you can verify the data received is the same as what you're sending then surely your final hurdle is rebuilding the image file at the PC end?

BTW on these forums, be sure to enclose any code in [code ] tags so it's more readable.

Cheers ! Geoff
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Newark, NJ
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

Thanks for the tip. I am fairly new to this forum and next time I'll include it within the code tag.

Well, the problem is a little more than what it appeared like. The basic problem is: I am trying to use Arduino Uno with a WiFi shield to transfer an image stored on the SD card (which is on the WiFi Shield) OR directly from a TTL camera to a PC.

Firstly I tried to do this by simply using the SD and WiFi libraries and trying to read a file stored on the SD Card and output it on the serial. But I learned than images are rather more complex files and hence I thought about other ways of accomplishing this.

Next, I was trying to create an array (following someone's code on Mega) to store the bits of the image as hex (my last code), but I keep getting gibberish characters. I would like to know if this approach is in the right direction or not.

If not, could you suggest another alternative to achieving this using the same hardware ?

I have a Uno, a Mega, a TTL Camera, a WiFi shield, a SD Card Slot on the WiFi shield.

I really appreciate your help. Thank you,

Raj
Logged

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Raj

Perhaps if you set up an FTP share on your PC you could use this code on the playground, modified to drive your Wifi module rather than wired ethernet?
Playground FTP.

Cheers ! Geoff
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Newark, NJ
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you very much. I was working in a similar direction and trying to set up a FTP server. I'll update as soon as it works.

Thanks again!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm new to arduino.
I'm working on a project where i need to send some characters over wifi (using arduino wifi shield). I'm able to generate the characters and transmit it, but not able to read them on my pc.
Can you help me regarding this?
thanx
Logged

Pages: [1]   Go Up
Jump to: