2010年4月7日 星期三

自製數位相框 DIY photo frame with BL-TFT240320PLUS

Build photo frame with AVR and BL-TFT240320PLUS

Build it self photo frame. Display on QVGA 240x320 pixel using AVR small 8 bit microcontroller.

Objective
  • DIY photo frame
  • Using AVR microcontroller.
  • Display on QVGA TFT 3.2” 240x320 pixel 16 bit color
  • Using BMP file format with out convert.
  • File store on SD card.
  • Keep small program size.
  • Fast display as fast as possible.
 Hardware
  • Atmega8,16,32 8 bit microcontroller from www.atmel.com
  • SD card
  • QVGA BL-TFT240320PLUS from circuitidea.com. It come with include SD card slot. 8/16 bit interface.
    
Understanding BMP file format
BMP file contain 4 group of data structure.
  1. BMP File Header Stores general information about the BMP file.
  2. Bitmap Information Stores detailed information about the bitmap image.
  3. Color Palette Stores the colors use for indexed color bitmaps. This is for 1,4,8 bits per pixel.
  4. Bitmap Data Stores the actual image, pixel by pixel. 
In this project we are interesting in part 1, 2 and 4. The color palette take more ram to keep color index table.
The yellow mark is interesting point for project.
BMP File Header
00h
2 bytes
the “BM” characters identify the BMP file.
02h
4 bytes
size of the BMP file in bytes
06h
2 bytes
reserved; actual value depends on the application that creates the image
08h
2 bytes
reserved; actual value depends on the application that creates the image
0Ah
4 bytes
the bmp data offset starting address
 Bitmap Information
0Eh
4 bytes
size of this header ( 40 bytes ).
12h
4 bytes
bitmap width in pixels (signed integer).
16h
4 bytes
bitmap height in pixels (signed integer).
1Ah
2 bytes
number of color planes being used. This must be set to 1.
1Ch
2 bytes
number of bits per pixel. values are 1, 4, 8, 16, 24 and 32.
1Eh
4 bytes
compression method being used.
22h
4 bytes
image size. This is the size of the raw bitmap data.
26h
4 bytes
horizontal resolution of the image. (Pixel per meter, signed integer)
2Ah
4 bytes
vertical resolution of the image. (Pixel per meter, signed integer)
2Eh
4 bytes
number of colors in the color palette, or 0 to default to 2n.
32h
4 bytes
number of important colors used.

To understand raw data format. . You can found example, The Example of a 2x2 Pixel Bitmap with 24 bits/pixel encoding ) athttp://en.wikipedia.org/wiki/Windows_bitmap#Example_of_a_2x2_Pixel.2C_24-Bit_Bitmap.
Schematic
AVR Atmega16,32
AVR atmega8 (ARDUINO hardware)
Software
            Concept is very easy. Read BMP files from SD card and display to LCD.
LCD driver
            BL-TFT240320PLUS TFT LCD board (4) using SSD1289. The code from www.circuitidea.com
SD card driver
            AVR microcontroller has a small ram. Our scope is reading and display BMP file with out convert. It’s take more ram and give more speed to display. I found many SD card libraries for AVR on internet. Petit FatFs(3) is good for this solution. It’s take a small code. 
Petit Fatfs Features:
  • Read only file system.
  • Very small RAM consumption (46 bytes work area + certain stack).
  • Very small code size (2.5K-3.5K bytes).
  • FAT12, FAT16 and FAT32.
  • Single volume and Single file. 
Display BMP
1. Start scan SD card to find bmp file.
2. Open file and check condition to fit in solution. 
Check image to fit screen

Address 0x12h contains the width of the bitmap in pixels.
Address 0x16h contains the height of the bitmap in pixels.
Display 24 bit per pixel
Address 0x1Ch contains number of bit per pixel.
No image processing function.
Address 0x1Eh contains the compression.
MUST be 0.
       3. Scan data and put to LCD 
Set area to display.
Adjust center image if need.
Image size must be equal or less than screen area.
Start of picture data
Address 0x0Ah keeps the point to bitmap data.
Scan and display from bottom to top
Image data store from the bottom line of the image
Scan each line of image.
Image data store in each lines.
Address 0x12h contains the width of the bitmap in pixels.
Convert color to RGB
Color is present in BGR
Skip padding data form some image
There are padding data to keep the line of data in multiples of four image width.
Compiler
            SD buffer set to 512 byte. Using AVR atmega32 program size is 8166 (24.9%). Data size 23 byte ( internal buffer use 512 byte ).
Atmega16 program size is 8166 (49.8%).  Atmega8 (using 8 bit mode) program size is 7220 (88.1%).

Source code
Release 01
            Atmega16,32 schematic and hex include in Photoframe.zip
            Atmega8 ( using only arduino hardware ) schematic and hex include in Photoframe Arduino
Release 02
           Atmega8 ( using only arduino hardware ) schematic and hex include in Photoframe Arduino R02
Arduino
          Arduino atmega168 ( Source code in Arduino library, LCD and demo. Must use with SD card library) ( board Version 1)  www.circuitidea.com/dev-board/BL-TFT240320PLUS.html
          Code and library for Arduino ( board Version 1 and 2 ) www.circuitidea.com/dev-board/BL-TFT240320PLUS-V2.html

Sample picture
 
  
Reference
(2) BMP file format : en.wikipedia.org/wiki/Windows_bitmap
(3) Petit FAT File System Module : elm-chan.org/fsw/ff/00index_p.html

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。