+ Post New Thread
Results 1 to 4 of 4
  1. #1
    Full Member level 6
    Points: 2,296, Level: 11

    Join Date
    Mar 2012
    Posts
    322
    Helped
    6 / 6
    Points
    2,296
    Level
    11

    How to send jpeg image to avr?

    Hello,
    I need to send jpeg from PC to AVR as follows:
    JPEG (from PC) => RS232 =>--------------=> USART(atmega128) => SD card.
    I have never done it before and hope anyone who has experience give me some advice about it.
    Can you tell me how to send from PC to USART?
    Which kind of image format I should to save in SD card?
    .....
    What should I take into consideration?
    Thanks for help.

    •   Alt3rd October 2012, 17:53

      advertising

        
       

  2. #2
    Advanced Member level 5
    Points: 19,842, Level: 34
    barry's Avatar
    Join Date
    Mar 2005
    Location
    California, USA
    Posts
    3,826
    Helped
    825 / 825
    Points
    19,842
    Level
    34

    Re: How to send jpeg immage to avr?

    I assume you are sending a file rather than sending JPEG data as it's being created. If so, then just send the file as you would any other file-the communication stream doesn't care what the data represents (JPEG or otherwise).

    The letter carrier doesn't need to know what's in the envelope in order to deliver your mail.



    •   Alt3rd October 2012, 18:45

      advertising

        
       

  3. #3
    Member level 2
    Points: 577, Level: 5

    Join Date
    Oct 2011
    Location
    Serbia
    Posts
    52
    Helped
    11 / 11
    Points
    577
    Level
    5

    Re: How to send jpeg immage to avr?

    I want to ask you about some details, for which I believe it will help people to help you easier:

    1. how you plan to communicate between PC and ATmega128? Will you write some software (standalone application) in Delphi or Microsoft development software, etc. In all of that solution, way to communicate between PC and ATmega128 is same through COM port (RS232 standard), but syntax depends from development software. I have a some experience with Delphi (Pascal) in communication between PC and ATmega through COM port, and could tell you that is not to complex, if you have to ask somebody for start. Also, I made one standalone application in development platfom LabView, and it was very simple to do that. LabView is development platform of National Instruments.

    2. will you use real and physical COM port, or do you have COM port on your PC? I ask you this, because COM port is legacy for few years. But, in that case, virtual COM port is solution, and that is independent task. In that solution I have experience with virtual COM port with FTDI232 chip. Also, I think that is very easy and simple solution, only problem with that is FTDI chip is in SMD package, so it is easy to burn the chip when you try to solder it on board.

    3. I do not have experience with SD card in communication with ATmega, but I think you do not need worry about image format, because you will save data on SD card in all format, without any diferences between files.

    4. Are your project something like flash drive, just like a storage, or you want to use and GLCD for showing the pictures which you memory on SD card?

    I hope that my questions are clear for you, and your answers could help people to help you easier.

    - - - Updated - - -

    Here is one example of C code for ATmega128 and EasyAVR5A development board which manufacture Mikroelektronika. Here you can see how in MikroC PRO for AVR syntax looks like (be carefull, you must know write syntax for compiler which you use and adjust your code to your board and pins on microcontroller):

    Code:
    /*
     * Project name:
         Cf_Fat16_Test (Demonstration on usage of Cf_Fat16 library)
     * Copyright:
         (c) MikroElektronika, 2008
     * Revision History:
         20080930:
           - initial release;     
     * Description:
         This project consists of several blocks that demonstrat various aspects of
         usage of the Cf_Fat16 library. These are:
         - Creation of new file and writing down to it;
         - Opening existing file and re-writing it (writing from start-of-file);
         - Opening existing file and appending data to it (writing from end-of-file);
         - Opening a file and reading data from it (sending it to USART terminal);
         - Creating and modifying several files at once;
     * Test configuration:
         MCU:             ATmega128
         Dev.Board:       BigAVR2
         Oscillator:      External, 08.0000 MHz
         Ext. Modules:    mE Compact Flash card on PORTB(Control) and PORTD(Data)
         SW:              mikroC PRO for AVR
     * NOTES:
         - Please make sure that CF card is properly formatted (to FAT16 or just FAT)
           before testing it on this example!
         - This example expects CF card to be inserted before reset, otherwise,
           the FAT_TXT message is displayed!!!
     */
     
    #include "built_in.h"
    
    // set compact flash pinout 
    char Cf_Data_Port at PORTD;
    char Cf_Data_Port_Direction at DDRD;
    
    sbit CF_RDY at PINB.B7;
    sbit CF_WE  at PORTB.B6;
    sbit CF_OE  at PORTB.B5;
    sbit CF_CD1 at PINB.B4;
    sbit CF_CE1 at PORTB.B3;
    sbit CF_A2  at PORTB.B2;
    sbit CF_A1  at PORTB.B1;
    sbit CF_A0  at PORTB.B0;
    
    sbit CF_RDY_direction at DDRB.B7;
    sbit CF_WE_direction  at DDRB.B6;
    sbit CF_OE_direction  at DDRB.B5;
    sbit CF_CD1_direction at DDRB.B4;
    sbit CF_CE1_direction at DDRB.B3;
    sbit CF_A2_direction  at DDRB.B2;
    sbit CF_A1_direction  at DDRB.B1;
    sbit CF_A0_direction  at DDRB.B0;
    // end of cf pinout
    
    char
     fat_txt[20] = "FAT16 not found",
     file_contents[50] = "XX CF FAT16 library by Anton Rieckert\n";
    
    char
     filename[14] = "MIKRO00xTXT";          // File names
    unsigned short
     tmp, caracter, loop, loop2;
    unsigned long
     i, size;
    
    char Buffer[512];
    
    //-------------- Writes string to USART
    void I_Write_Str(char *ostr) {
      unsigned short i;
    
      i = 0;
      while (ostr[i]) {
        UART1_Write(ostr[i++]);
      }
      UART1_Write(0x0A);
    }
    
    
    //-------------- Creates new file and writes some data to it
        void M_Create_New_File() {
      filename[7] = 'A';
      Cf_Fat_Assign(&filename, 0x80);      // Will not find file and then create file
      Cf_Fat_Rewrite();                    // To clear file and start with new data
      for(loop = 1; loop <= 99; loop++) {  //  We want 5 files on the MMC card
        file_contents[0] = loop / 10 + 48;
        file_contents[1] = loop % 10 + 48;
        Cf_Fat_Write(file_contents, 38); // write data to the assigned file
        UART1_Write('.');
      }
    }
    
    //-------------- Creates many new files and writes data to them
    void M_Create_Multiple_Files() {
      for(loop2 = 'B'; loop2 <= 'Z'; loop2++) {
        UART1_Write(loop2);
        filename[7] = loop2;              // set filename
        Cf_Fat_Assign(&filename, 0xA0);   // find existing file or create a new one
        Cf_Fat_Rewrite();                 // To clear file and start with new data
        for(loop = 1; loop <= 44; loop++) {
          file_contents[0] = loop / 10 + 48;
          file_contents[1] = loop % 10 + 48;
          Cf_Fat_Write(file_contents, 38); // write data to the assigned file
        }
      }
    }
    
    //-------------- Opens an existing file and rewrites it
    void M_Open_File_Rewrite() {
    
      filename[7] = 'C';
      Cf_Fat_Assign(&filename, 0);
      Cf_Fat_Rewrite();
      for(loop = 1; loop <= 55; loop++) {
        file_contents[0] = loop / 10 + 64;
        file_contents[1] = loop % 10 + 64;
        Cf_Fat_Write(file_contents, 38); // write data to the assigned file
      }
    }
    
    //-------------- Opens an existing file and appends data to it
    //               (and alters the date/time stamp)
    void M_Open_File_Append() {
    
      filename[7] = 'B';
      Cf_Fat_Assign(&filename, 0);
      Cf_Fat_Set_File_Date(2005,6,21,10,35,0);
      Cf_Fat_Append();                                    // Prepare file for append
      Cf_Fat_Write(" for mikroElektronika 2005\n", 27);   // Write data to assigned file
    }
    
    //-------------- Opens an existing file, reads data from it and puts it to USART
    void M_Open_File_Read() {
    
      filename[7] = 'B';
      Cf_Fat_Assign(&filename, 0);
      Cf_Fat_Reset(&size);            // To read file, procedure returns size of file
      for (i = 1; i <= size; i++) {
        Cf_Fat_Read(&caracter);
        UART1_Write(caracter);         // Write data to USART
      }
    }
    
    //-------------- Deletes a file. If file doesn't exist, it will first be created
    //               and then deleted.
    void M_Delete_File() {
      filename[7] = 'F';
      Cf_Fat_Assign(filename, 0);
      Cf_Fat_Delete();
    }
    
    //-------------- Tests whether file exists, and if so sends its creation date
    //               and file size via USART
    void M_Test_File_Exist() {
      unsigned long fsize;
      unsigned int year;
      unsigned short month, day, hour, minute;
      unsigned char outstr[12];
    
      filename[7] = 'B';       //uncomment this line to search for file that DOES exists
    //  filename[7] = 'F';       //uncomment this line to search for file that DOES NOT exist
      if (Cf_Fat_Assign(filename, 0)) {
        //--- file has been found - get its date
        Cf_Fat_Get_File_Date(&year, &month, &day, &hour, &minute);
        WordToStr(year, outstr);
        I_Write_Str(outstr);
        ByteToStr(month, outstr);
        I_Write_Str(outstr);
        WordToStr(day, outstr);
        I_Write_Str(outstr);
        WordToStr(hour, outstr);
        I_Write_Str(outstr);
        WordToStr(minute, outstr);
        I_Write_Str(outstr);
        //--- get file size
        fsize = Cf_Fat_Get_File_Size();
        LongToStr((signed long)fsize, outstr);
        I_Write_Str(outstr);
      }
      else {
        //--- file was not found - signal it
        UART1_Write(0x55);
        Delay_ms(1000);
        UART1_Write(0x55);
      }
    }
    
    //-------------- Tries to create a swap file, whose size will be at least 100
    //               sectors (see Help for details)
    void M_Create_Swap_File() {
      unsigned int i;
    
      for(i=0; i<512; i++)
        Buffer[i] = i;
    
      size = Cf_Fat_Get_Swap_File(5000, "mikroE.txt", 0x20);   // see help on this function for details
    
      if (size) {
        LongToStr((signed long)size, fat_txt);
        I_Write_Str(fat_txt);
    
        for(i=0; i<5000; i++) {
          Cf_Write_Sector(size++, Buffer);
          UART1_Write('.');
        }
      }
    }
    
    
    //-------------- Main. Uncomment the function(s) to test the desired operation(s)
    void main() {
        // we will use PORTC to signal test end
        DDRC  = 0xFF;
        PORTC = 0;
        //--- set up USART for the file read
        UART1_Init(19200);                         
        Delay_ms(100);
        // use fat16 quick format instead of init routine if a formatting is needed
        if(!Cf_Fat_Init()) {    // Init the FAT library
          //--- Test start
          UART1_Write('s');
          M_Create_New_File();
          M_Create_Multiple_Files();
          M_Open_File_Rewrite();
          M_Open_File_Append();
          M_Open_File_Read();
          M_Delete_File();
          M_Test_File_Exist();
          M_Create_Swap_File();
          //--- Test termination
          UART1_Write('e');
        }
        else {
         I_Write_Str(fat_txt);
        }
        //--- Test termination
        PORTC = 0x0F;    
    }



    •   Alt3rd October 2012, 19:08

      advertising

        
       

  4. #4
    Administrator
    Points: 69,041, Level: 64
    Achievements:
    Created Album pictures Created Blog entry 7 years registered
    bigdogguru's Avatar
    Join Date
    Mar 2010
    Location
    Southwest, USA
    Posts
    9,832
    Helped
    2351 / 2351
    Points
    69,041
    Level
    64
    Blog Entries
    4

    Re: How to send jpeg immage to avr?

    The following is an informative four part tutorial concerning the interfacing of an SD card to an AVR and implementation of a FAT filesystem:

    Simple FAT and SD Tutorial Part 1

    BigDog
    The Edge... there is no honest way to explain it, because the only people who really know where it is are the ones who have gone over.
    -- Hunter S. Thompson



--[[ ]]--