You are on page 1of 67

Lessius Mechelen Campus De Nayer Jan Pieter de Nayerlaan 5 2860 Sint-Katelijne-Waver

TouchDuino
Een poject met n van de bekendste microcontroller platformen in combinatie met een touchscreen, microSD kaart en joystick. Begeleidende leerkracht: Johan Van Bauwel

Door Matthias Van Gestel & Dries Darquennes Project tot het behalen van het eerste jaar professionele bachelor Electronica ICT

Inhoudsopgave
1 Beschrijving:......................................................................................................................................2 1.1 Photoviewer...............................................................................................................................2 1.2 Snake..........................................................................................................................................3 1.3 Pictionary...................................................................................................................................4 2 Problemen en oplossingen.................................................................................................................5 3 Beschrijving van de componenten en gebruikte technologie............................................................6 3.1 Arduino & Seeeduino.................................................................................................................6 3.2Seeeduino....................................................................................................................................6 Seeeduino v3.0............................................................................................................................7 Seeeduino Stalker V2.2...............................................................................................................8 Waarom.......................................................................................................................................8 3.3 MicroSD.....................................................................................................................................9 3.4 UARTSBEE...............................................................................................................................9 Waarom.......................................................................................................................................9 3.5 Grove - Thumb Joystick :.......................................................................................................10 Werking:....................................................................................................................................10 3.6 FAT16.......................................................................................................................................11 3.7 TFT 2.8 Touch Shield:...........................................................................................................12 Resistief touch screen:...............................................................................................................12 Touch detection:........................................................................................................................12 Programmeren : ........................................................................................................................13 Specificaties:.............................................................................................................................15 Aansturing met IC :...................................................................................................................15 3.8 BMP bestandsindeling.............................................................................................................16 Structuur....................................................................................................................................16 4 Kostprijs:.........................................................................................................................................17 5 Flowcharts.......................................................................................................................................18 5.1 Photoviewer.............................................................................................................................18 5.2 Pictionary.................................................................................................................................21 5.3 Snake........................................................................................................................................22 6 Handleidingen..................................................................................................................................33 6.1 Photoviewer.............................................................................................................................33 6.2 Pictionary.................................................................................................................................34 6.3 Snake........................................................................................................................................35 7 Logboeken.......................................................................................................................................36 7.1 Matthias Van Gestel.................................................................................................................36 7.2 Dries Darquennes.....................................................................................................................38 8 Bijlagen............................................................................................................................................39

Verslag: TouchDuino

1/39

Beschrijving:

Het doel van het project was om kennis te maken met het arduino platform en om een touchscreen aan te sturen, zodat we er enkele toffe dingen mee konden doen. Daarom hebben we het project opgedeeld in 3 aparte programma's, namelijk:

1.1 Photoviewer
Het doel van dit deel van het project is dat men foto's kon opladen naar het microSD kaart, zodat men ze op het touchscreen zou kunnen bezien. Door gebruik te maken van het touchscreen kan men zich zo doorheen de foto bibliotheek vegen.

Verslag: TouchDuino

2/39

1.2 Snake
Bij dit deel van het project is het de bedoeling dat men snake kan spelen met behulp van het touchscreen waarbij men zich doorheen de hindernissen moeten begeven om het aas te kunnen vangen. Deze hindernissen zijn instelbaar via de computer en zo zeer gemakkelijk aan te passen aan je eigen smaak of tactisch inzicht.

Verslag: TouchDuino

3/39

1.3 Pictionary
Het nut van dit programma is om het spel pictionary te kunnen spelen. Hierbij krijg je een willekeurig woord toegewezen en moet je dat woord dan tekenen zodat andere mensen dit woord kunnen raden. De eerste die het woord geraden heeft mag dan de volgende ronde tekenen. Met behulp van het microSD zou je dan je tekening kunnen opslagen zodat je het later zou kunnen bekijken.

Verslag: TouchDuino

4/39

Problemen en oplossingen
We kunnen spreken van een aantal uiteenlopende problemen bij het gebruik van het Touch screen en zijn library. Namelijk bij de drawString bijvoorbeeld, als een cordinaat buiten het scherm zou vallen zal de code dit niet kunnen registreren. Er is een mogelijkheid dat het scherm zal tilt slaan. Dit kon opgelost worden door middel van software aanpassingen en verstandig programmeerwerk. Een bijkomend nadeel waren de randen van het Touch screen, bij het wissen van het Touch screen (eingenlijk gewoon overschrijven met zwart) is het mogelijk dat er pixels achterblijven. Dit kan simpel opgelost worden door de waardes van het scherm te vergroten zodat deze buiten het interval van het scherm vallen. Het volgende probleem heeft te maken met de Touch detectie, bij het inlezen van een punt werkt deze niet optimaal. Bijvoorbeeld de aanraking op het scherm bij punt n is enkel juist bij de eerste detectie, bij de volgende incorrect of zelfs geen detectie. Dit zorgde voor grote hinder bij de bewegingszin bij onder andere het spel snake. Ten tweede is de detectie rond de randen haast onmogelijk omwille van het scherm dat op sommige plaatsen niet goed doordrukt. Door het gebruiken van een joystick zorgde we ervoor dat er geen belemmering meer was bij de bewegingszin van het spel snake. Vervolgens waren er ook problemen met de wire library, namelijk dat men maar n byte kon requesten. De library gaf wel aan dat die hoeveelheid groter zou kunnen zijn, maar werkte nagenoeg niet. De oplossing hiervoor was softwarematig het meerdere keren oproepen van de 1 byte request. Bij het debuggen in arduino ondervonden we ook problemen, namelijk bij serieel overzetten kon de serial monitor niet meer gebruikt worden omdat anders de poort reeds in gebruik was. Dit kan vereenvoudigt worden door middel van een led toe te voegen om na te kijken of communicatie al dan niet mogelijk was. Eveneens treden er problemen op bij het Photoviewer programma dat na een aantal foto's te veranderen ervoor zorgt dat de Slave helemaal niet meer doet wat van hem verwacht wordt. Zo geraakt hij niet meer in zijn request interrupt en blijft hij de laatst verstuurde byte herversturen waardoor het scherm een eentonig kleur kreeg. Na lang zoeken hebben we geen oplossing gevonden en hebben we het gewoon opgegeven. Ten laatste hadden we niet genoeg I/O pinnen voor het tft-touch shield en sd-shield, daarom hebben we een tweede processor aangekocht met meerdere I/O pinnen en de aanwezigheid van een SD-slot. Maar hierdoor was wel de tft-shield niet compatibel meer dus hebben we gebruik gemaakt van IC . We hebben beide processors gebruikt, de ene voor het tft-shield en de andere als het sd-shield.

Verslag: TouchDuino

5/39

Beschrijving van de componenten en gebruikte technologie

3.1 Arduino & Seeeduino


Arduino is een opensource computerplatform gebouwd rond de Atmel ATmega microcontroller en het opensource ontwikkelplatform Processing. Arduino is een krachtig microcontroller platform bedoeld voor het ontwerpen van slimme en creatieve objecten die kunnen interacteren met hun omgeving. De Arduino kan zowel analoge als digitale input en output genereren, en is deels gestandaardiseerd zodat het makkelijk is om de controller uit te breiden met zogenaamde shields die bepaalde uitbreidmogelijkheden in 1 PCB bieden zoals onder andere ons TFT Touch Shield.

3.2 Seeeduino
Het was de bedoeling dat we met behulp van een SD-shield, een TFT Touch Shield en een Seeeduino V3.0 controller heel ons project konden maken, maar uiteindelijk bleek dat we niet genoeg I/O hadden om alles aan te sturen. Dus hebben we geopteerd voor een 2de controller zodat we de taken konden verdelen over deze controllers. Er zijn een handvol verschillende Arduino uitvoeringen, elk met hun eigen nadelen en voordelen. Zo zijn er die je zelf kunt assembleren (DIY) of er zijn er die je voorgemaakt kunt bestellen. De Arduino's die wij gebruiken zijn vooraf geassembleerd en zijn gebaseerd op de Atmel ATmega328p.

Seeeduino Stalker v2 UARTSBEE

Seeduino V3.0

Verslag: TouchDuino

6/39

Seeeduino v3.0
Gebaseerd op de Duemilanove controller en 100% compatibel met de bestaande software. Functionaliteiten: Microcontroller Type Clock Speed Type Operation Voltage Input Voltage Input/Output aanbevolen limieten Digital PWM output Analog input DC current per pin Voltage Memory Flash SRAM EEPROM Misc ATmega328p 20 MHz 8-bit AVR 5V 7 12 V 6 20 V 14 6 6 40 mA 5V 32 KB (2 KB used by bootloader) 2 KB 1 KB

Internal 20k pull-up resistor

Integrated Two Wire Interface ( IC ) Integrated UART (max 115200 bps) Integrated USB overcurrent Fuse ( > 500 mA) Internal programmer, ICSP header for external programmer

Verslag: TouchDuino

7/39

Seeeduino Stalker V2.2


Gebaseerd op de Seeeduino V3.0 en 100% compatibel met de bestaande software, shields en IDE's. Enkel dat de I/O op 3.3V logic werkt. Functionaliteiten: Microcontroller Type Clock Speed Type Operation Voltage Input Voltage Input/Output aanbevolen limieten Digital PWM output Analog input DC current per pin Voltage Memory Flash SRAM EEPROM Misc ATmega328p 20 MHz 8-bit AVR 5V 7 12 V 6 20 V 14 6 6 40 mA 3.3 V 32 KB (2 KB used by bootloader) 2 KB 1 KB

Internal 20k pull-up resistor

Integrated Two Wire Interface ( IC ) with onboard IC level shifter IC (voltage translation between 3.3V and 5V) Integrated UART (max 115200 bps) Integrated USB overcurrent Fuse ( > 500 mA) No internal programmer, ICSP header for external programmer or Onboard RTC with CR2032 Cell Socket microSD card socket Bee series socket

Waarom
Wij hebben voor deze controllers gekozen omdat: 1. ze gemakkelijk te bestellen waren met de bijhorende shields 2. er zeer uitgebreide wiki websites en voorbeelden bijzaten 3. uitgebreide libraries 4. ze in C programmeerbaar zijn Maar ook omdat we er in de toekomst nog toffe projecten mee konden maken en omdat we nogal nieuwsgierig waren naar het Arduino platform in zijn totaliteit. Verslag: TouchDuino 8/39

3.3 MicroSD
Ook maken we gebruik van een microSD kaart voor het bijhouden van dynamische data. De gebruikte IC is helemaal afhankelijk van het microSD kaartje zelf maar de communicatie is volledig gestandaardiseerd. Er zijn 2 verschillende opties van communicatie mogelijk namelijk 4-bit parallel modus en SPI modus, Arduino maakt gebruik van de laatste modus aangezien er dan maar 3 I/O pinnen in beslag genomen worden door het kaartje zelf (CMD,MISO en MOSI). Wel is het een tragere manier van communiceren maar op een Atmega328p van 20Mhz heeft dit geen grote invloed. Ook hiervoor maken wij gebruik van standaard Arduino libraries.

3.4 UARTSBEE
Dit component is een USB naar Serial converter die gebruikt kan worden voor het programmeren en de communicatie met MCU's. Maar dankzij zijn XBEE socket kan het perfect gebruikt worden om je PC te verbinden met verschillende draadloze applicaties om dan zo je PC te gebruiken om te kunnen communiceren met je microcontroller. Eveneens kan het een schakeling van stroom voorzien (3,3V of 5V) en kan het applicaties vervangen waarbij je een parallelle poort moet gebruiken. Functionaliteiten: Microprocessor: FT232RL FTDI kabel compatibel (een standaard voor het omzetten van TTL serile communicatie naar USB-signalen) USB 2.0 compatibele Serial interface (mini-B usb) 3.3V & 5V compatibele I/O 3.3V & 5V dual power output (max 500mA) RESET knop voor BEE modules Bit-Bang mode ready (bv als SPI) LED's voor UART en BEE operaties

Waarom
Wij gebruiken dit component om onze Seeeduino Stalker te programmeren, omdat deze microcontroller geoptimaliseerd is voor een minimaal stroomverbruik hebben de ontwikkelaars ervoor gekozen om een externe programmer te gebruiken, waarvoor de UARTSBEE perfect te gebruiken is.

Verslag: TouchDuino

9/39

3.5 Grove - Thumb Joystick :


Omdat onze touchscreen detectie niet goed genoeg werkte hebben wij deze joystick aangeschaft voornamelijk voor het spel snake om zo de richting van de slang te bepalen. Eigenschappen : Drukknop X en Y cordinaat

Werking:
Als de drukknop wordt ingedrukt dan zal de maximum weerstandswaarde (1023) doorgestuurd worden, de x en de y cordinaat worden bepaald door 2 potentiometers, de waardes die worden doorgestuurd kunnen oplopen van 200 tot ongeveer 800. Standaard, wanneer de joystick dus in rust staat, wordt een waarde van ongeveer 450 doorgestuurd. Vervolgens wordt er softwarematig bepaald welke waarde aan welke richting gekoppeld wordt. De 2 waardes worden ingelezen bij onze slave, deze zal dan de richting bepalen en daarna doorsturen naar onze master via IC wanneer deze dit opvraagt.

Verslag: TouchDuino

10/39

3.6 FAT16
FAT16 (16-bits File Allocation Table) is een bestandssysteem dat werkt met een tabel die op een vaste plek op de schijf is opgeslagen. Deze tabel houdt bij welke stukken van de schijf door welke bestanden gebruikt worden. Zoals je hierboven kunt vaststellen kan deze tabel maar 216 (65 536) posities groot zijn. Oorspronkelijk kwam elke positie overeen met een sector (512 bytes) maar hiermee zou een FAT16 partitie maar maximum 32 MB groot kunnen zijn. Daarom hebben ze later besloten dat een positie overeen komt met een cluster (32 KB) die bestaat uit meerdere sectoren. Hiermee kan een moderne FAT16 partitie 2GB groot zijn. In FAT16 hebben alle directory's dezelfde vorm. Een directory is eigenlijk een lijst van bestanden met het start-clusternummer van dat bestand. Deze bestanden worden opgeslagen als een directoryentry, wat niet meer is dan wat informatie in het FAT omtrent het bestand. Positie Lengte (bytes) 0 8 11 12 14 16 18 20 22 24 26 8 3 1 2 2 2 2 2 2 2 2 Beschrijving FAT VFAT Bestandsnaam Extensie Attribuut-byte Start-clusternummer (OSR2) Niet gebruikt Niet gebruikt creatietijd creatiedatum 2de versie van win95 Bepaald of het om een bestand gaat of om een subdirectory

Niet gebruikt Datum laatst gelezen Gereserveerd Tijd laast beschreven Datum laast beschreven Start-clusternummer van bestand

28 4 Bestandsgrootte in bytes Zoals je hierboven kunt zien staat er VFAT, VFAT was een uitbreiding op FAT16 om met langere bestandsnamen te kunnen werken. (dit was enkel mogelijk vanaf Windows 95).

Verslag: TouchDuino

11/39

3.7 TFT 2.8 Touch Shield:


Voor ons project hebben wij gebruik gemaakt van een 2.8'' TFT Touch Shield. Eigenschappen: Meerdere kleuren 4 wire resistief Arduino/Seeeduino, Arduino Mega, en Seeeduino Mega compatible.

Resistief touch screen:


Het resistief touch scherm is gemaakt door het samendrukken van 2 lagen, Indium Tin Oxide bedekt glas en Poly Ethylene Terephthalate. Tussen deze 2 lagen komen er dan microdot spacers deze zorgen ervoor dat men niet per ongeluk input kan registreren als er geen is. Deze spacers worden met een grote zorg op het glas geplaatst hierdoor kunnen ze bepalen waar een aanraking is, hoe groot ze is en voornamelijk hoe hard ze wordt ingedrukt, zo kan men dan een onderscheid maken tussen bijvoorbeeld vinger en pen aanraking. Eveneens komt er nog een luchtlaag tussen de lagen en wordt die laag dan helemaal dicht gemaakt zodat er geen stof en vuil tussen kan komen.

Touch detection:
Het lezen van een X of Y cordinaat gebeurd in 2 stappen. Eerst maakt men Y+ hoog en hangt men Y- aan ground en meet men de spanning aan X+. Vervolgens gebruikt men de volgende formule om het Y cordinaat te berekenen : Uy + Y= Height screen Udrive Daarna gebruikt men voor het lezen van het X cordinaat een gelijkaardig aanpak.

Verslag: TouchDuino

12/39

Programmeren :
Voor dit touchscreen te kunnen programmeren bestaat er een TFT-library. Deze omvatten standaard functies voor de aansturing : setXY(unsigned int poX, unsigned int poY) Sets the cursor position to (poX,poY). This function is internally used by other graphics APIs. setPixel(unsigned int poX, unsigned int poY,unsigned int color) Sets the (poX,poY) pixel to color color. This function is internally used by other graphics APIs. drawLine(unsigned int x0,unsigned int y0,unsigned int x1,unsigned int y1,unsigned int color) Draws a line from pixel (x0,y0) to pixel (x1,y1) with color color. drawVerticalLine(unsigned int poX, unsigned int poY,unsigned int length,unsigned int color) Draws a Horizontal Line of length length with color color starting from pixel (poX,poY). drawHorizontalLine(unsigned int poX, unsigned int poY,unsigned int length,unsigned int color) Draws a Vertical Line of length length with color color starting from pixel (poX,poY). drawRectangle(unsigned int poX, unsigned int poY, unsigned int length,unsigned int width,unsigned int color) Draws a rectangle starting from (poX,poY) of length length, width width and color color. fillRectangle(unsigned int poX, unsigned int poY, unsigned int length, unsigned int width, unsigned int color) Draws a filled rectangle starting from pixel (poX,poY) of length length, width width and color color. drawCircle(int poX, int poY, int r,unsigned int color) Draws a circle at (poX,poY) of radius radius and color color. 13/39

Verslag: TouchDuino

fillCircle(int poX, int poY, int r,unsigned int color) Draws a filled circle at (poX,poY) of radius radius and color color. drawChar(unsigned char ascii,unsigned int poX, unsigned int poY,unsigned int size, unsigned int fgcolor) Draws a character starting from (poX,poY) using inbuilt font of size size and with color fgcolor. This function is used by drawString() function. drawString(char *string,unsigned int poX, unsigned int poY,unsigned int size,unsigned int fgcolor) Draws a string of text starting from (poX,poY) using inbuilt font of size size and with color fgcolor.

Verslag: TouchDuino

14/39

Specificaties:
Item Min Typical Max Unit Voltage 4.5 5 5.5 VDC Current / / 250 mA LCD Panel Size 2.8 inch View angle 60~120 Deg Resolution 320x240 / LCD color 65k / Backlight Type LED / LCD driver IC ST7781R / Interface Type 102 g Interface Type Parallel port ( 8bit Data + 4bit Control ) / Touch Screen 4-Wire resistive touch screen / Active area 43.2*57.3 mm ESD contact discharge 4 KV ESD air discharge 8 KV Dimension 72.5x54.7x18 mm Weight 242 g

Aansturing met IC :
ST7781R is de LCD driver IC die de Arduino moet aansturen om zo het scherm te kunnen gebruiken. Aan de hand van het RAM geheugen dat verbonden is met het IC kan er beeld worden weergegeven op het scherm. Daarom moet men via SPI een index in dat RAM register aanduiden en de gevulde waardes laten overschrijven met de kleur die wij willen weergeven op het scherm, door vervolgens een puls op de Vsync te zetten wordt het scherm dan vernieuwd.

Verslag: TouchDuino

15/39

3.8 BMP bestandsindeling


Het BMP bestandsformaat, beter bekend als bitmap image file of Device Independent Bitmap (DIB) bestandsformaat, is een raster graphics image file format gebruikt om digitale afbeeldingen op te slaan, onafhankelijk van het weergave apparaat (zoals bijvoorbeeld graphic card). In dit formaat is het mogelijk om 2D digitale afbeeldingen van een variabele hoogte en breedte in zowel zwart-wit als kleur,met verschillende kleur dieptes, op te slagen met behulp van optionele compressie, alpha channels en kleurprofielen.

Structuur

BMP header
Positie Lengte (bytes) 0 2 6 10 14 18 22 26 28 30 34 38 42 46 50 2 4 4 4 4 4 4 2 2 4 4 4 4 4 4 Type Unsigned short type Unsigned long size Unsigned long Reserved Unsigned long bitmap_offset Unsigned long header_size Signed long Signed long width height 54 bytes BITMAPINFOHEADER Versie 5 BITMAPFILEHEADER Naam

Unsigned short planes Unsigned short bits_per_pixel Unsigned long compression Unsigned long bitmap_size Signed long Signed long horizontal_resolution vertical_resolution

Unsigned long num_colors Unsigned long num_important_colors

Wat dit allemaal betekend gaan we niet uitleggen. Wel ga ik vertellen dat ons programma Photoviewer verwacht dat we met een BITMAPINFOHEADERv5 werken, waarbij de afbeelding begint vanaf byte 54. Waarbij de kleurdiepte 24 bit is en waarbij geen compressie gebruikt wordt. Ook verwacht het programma dat we met een 320x240pixels afbeelding werkt. Maar zelfs als bovenstaande vereisten niet worden voldaan zal het programma toch nog de afbeelding proberen te lezen. We hebben ook geopteerd om niet de gehele header te lezen, dit omdat we zo snel mogelijk onze interrupts willen beindigen. Na deze header volgen de kleurwaardes van de pixels (in X gespiegeld) waarvan de lengte van een pixel wordt bepaald door bits_per_pixel. Deze lezen we dan ook (niet gecomprimeerd) in en zetten we op ons scherm. Het bijgevoegde python GTK+2 programma zal met behulp van imagemagick een werkende afbeelding produceren die door het programma gelezen kan worden.

Verslag: TouchDuino

16/39

Kostprijs:
$6.99 $49.50 $22.50 $6.90 $39.00 $124.00 Omgerekend is dit zo'n 97,67.

Grove Thumb Joystick 2.8 TFT Touch Shield Seeeduino V3.0 (ATmega328p) SanDisk microSD
TM

Card 2GB

Seeeduino Stalker v2 Totaal

Dit had veel goedkoper geweest kunnen zijn aangezien we enkel de ATmega328p moesten aankopen (2x weliswaar), om daarna op een professionele PCB te zetten en zo ons eigen microSD socket hadden kunnen kopen om er dan zo op te zetten. En dit voor een veel goedkopere kostprijs, maar omdat deze bordjes ideaal waren om mee te ontwikkelen (denk maar aan de interne zekeringen en ledjes) hebben we voor deze oplossing geopteerd.

Verslag: TouchDuino

17/39

Flowcharts

5.1 Photoviewer

Verslag: TouchDuino

18/39

Verslag: TouchDuino

19/39

Verslag: TouchDuino

20/39

5.2 Pictionary

Verslag: TouchDuino

21/39

5.3 Snake

Verslag: TouchDuino

22/39

Verslag: TouchDuino

23/39

Verslag: TouchDuino

24/39

Verslag: TouchDuino

25/39

Verslag: TouchDuino

26/39

Verslag: TouchDuino

27/39

Verslag: TouchDuino

28/39

Verslag: TouchDuino

29/39

Verslag: TouchDuino

30/39

Verslag: TouchDuino

31/39

Verslag: TouchDuino

32/39

Handleidingen

6.1 Photoviewer
Dit programma werkt zeer eenvoudig, je start eerst de Seeeduino stalker V2 (slave) op en daarna de Seeeduino (master), mits er 24-bit BMP foto's staan op het microSD kaartje in het /pictures/ directory, zal er geleidelijk aan een foto op het scherm worden getoond. Zo niet dan kan je aan de hand van het ledje op de Seeeduino stalker zien wat er fout loopt: led knippert aan en uit voor ongeveer een halve seconde er staan geen foto's op het SD-kaart led staat voornamelijk aan het SD kaart kan niet genitialiseerd worden, dit kan zijn omdat er geen SD kaartje aanwezig is of omdat er een onbekende fout zich voordoet, dan unplug je beter voor beiden de power source en volg je bovenstaande instructies.

Ook bijgeleverd is een python programma bestaande uit een GTK+ 2 interface die met behulp van imagemagick foto's omzet naar het juiste formaat en dimensies zodat je ze makkelijk kunt opslaan op het microSD kaartje dat in de microcontroller gaat. Het programma wijst zichzelf uit en is dus makkelijk te gebruiken.

Verslag: TouchDuino

33/39

6.2 Pictionary
Als je de controller aanzet, wordt je begroet door het volgende scherm:

Dit scherm vertelt welk woord er gaat moeten getekend worden. Als je het scherm aandrukt kom je vervolgens op het tekenscherm:

1. Als je deze oppervlakte aanraak teken je de vorm die je in vakje 6 terugvindt 2. Dit is een kleine oppervlakte waarmee je snel de gom kunt pakken, deze oppervlakte is zo klein mogelijk gehouden zodat je zoveel mogelijk tekenoppervlakte hebt, pas hier dus mee op! 3. Deze blauwe pijlen veranderen je vorm (je vormgrootte wordt altijd gereset naar de standaard grootte), je ziet altijd je te gebruiken vorm in vakje 6 dat een preview geeft van wat je gaat tekenen. 4. Deze gele/oranje pijlen gebruik je om je vormgrootte te vergroten of te verkleinen, wederom wordt vakje 6 als preview gebruikt 5. Deze 3 bolletjes worden gebruikt om zo snel de 3 basis kleuren te gebruiken, waarbij daaronder de + en - gebruikt kunnen worden om tussen ongeveer 350 kleuren te kiezen afhankelijk van de kleur die je reeds aan het gebruiken bent 6. Als je deze oppervlakte aanraakt geef je aan dat je tekening klaar is en dat je het volgend te tekenen object wilt zien. Hiermee kom je eigenlijk terug op je welkomstbeeld.

Verslag: TouchDuino

34/39

6.3 Snake
Het werkt met beide microcontrollers (slave en master ) en een joystick die is bevestig aan de slave. Bij het opstarten van het programma krijgt u een menu te zien met daarop de volgende keuzes : - Start - Walls on/off - Highscores - Load map Start: U begint nu het spel snake te spelen, met behulp van de joystick besturing moet u zoveel mogelijk bait te pakken zien te krijgen. Walls on/off: Bij het selecteren van dit veld veranderd u de stand van de randen van het spel, u kan zo instellen dat de randen niet aanstaan en zo er zich kan door begeven, bij walls on staan de randen aan en is het spel afgelopen moest u 1 van de 4 raakt. Highscores: Hiermee kan u de vijf hoogste scores bekijken die zijn opgeslagen op het SD kaart, deze scores komen op u scherm en 5 seconde later word u terug naar het hoofdmenu gebracht. Load map: Bij deze laatste keuze kan u een map laden van het SD kaart en deze dan laden als de map die u gaat spelen. Om een map op het SD kaart te plaatsen dient u gebruik te maken van het C# programma. Hierbij moet de computer serieel verbonden zijn met de slave.

Verslag: TouchDuino

35/39

Logboeken

7.1 Matthias Van Gestel


Datum 28/02/2012 05/03/2012 05/03/2012 08/03/2012 08/03/2012 09/03/2012 10/03/2012 11/03/2012 12/03/2012 14/03/2012 15/03/2012 Programma N.V.T. N.V.T. Photoviewer N.V.T. N.V.T. Photoviewer Wat Bestellen van componenten: Seeduino, SD card shield, MicroSD 2GB, 2.8 TFT Touch Shield Aankomst bestelling Poging om het SD-shield en het TFT-Touch Screen aan te sturen Overleg met mr. Van Bauwel in verband met tekort aan I/O om SD-shield en TFT-Touch Screen aan te sturen met 1 controller Bestellen van componenten: Seeeduino Stalker v2, UartSBee V4, Grove - Thumb Joystick Analyse van het .BMP formaat

Photoviewer

Implementatie in C zonder canvas

Photoviewer Photoviewer

BMP decoder in C Python script voor het serieel doorsturen van de kleurenwaardes met behulp van de BMP decoder in C met daarbij een ontvanger in Arduino om op het scherm te tekenen Datasheet analyse omdat de 24 bit kleuren niet deftig ondersteund waren (scherm werkt hoogstens in 16 bit kleuren) + BMP decoder in C updaten met een 24bit to 16bit decoder Ophalen bestelling aan DHL depot Poging om TFT - TouchScreen op de Seeeduino Stalker aan te sluiten Overleg met mr. Van Bauwel omdat de Seeeduino Stalker niet met TFT Touch Screen omkan BMP decoder in C porten naar Seeeduino Stalker

16/03/2012

Photoviewer

19/03/2012 19/03/2012 21/03/2012 21/03/2012 23/03/2012 23/03/2012

N.V.T. N.V.T. N.V.T. Photoviewer

Photoviewer

IC concept bedenken om het tekort aan I/O op te vangen met behulp van 2 controllers en een communicatiebus

Verslag: TouchDuino

36/39

28/03/2012 29/03/2012 30/03/2012 02/04/2012 03/04/2012 04/04/2012 05/04/2012 08/04/2012 07/04/2012 10/04/2012 13/04/2012 17/04/2012 18/04/2012 18/04/2012 21/04/2012 24/04/2012

Photoviewer

IC concept inplementeren met behulp van beide controllers waarbij de BMP decoder (Stalker) als Slave gebruikt wordt en de aansturing van het TFT-TouchScreen (Seeeduino) als Master gebruikt wordt mr. Van Bauwel consulteren in verband met IC bug: 1 byte beperking in Arduino libraries Rondheen IC 1 byte bug werken (door telkens maar met 1 byte te werken) Pull-Up weerstands schakeling solderen (wat niet echt nodig was) Python GTK+ 3 converter programma maken dat met behulp van ImageMagick afbeeldingen kan converteren naar 320x240 BMPs (met 24 bit kleuren) Joystick solderen (gebrek aan GROVE kabel) Python GTK+ 3 converter programma porten naar GTK+2 en windows compatibel maken Analyse in verband met mr. Van Bauwel consulteren in verband met gebrek aan geheugen voor een hele bitmap te onthouden Bijna heel pictionary afgemaakt, inclusief alle Tools (= vormen), kleur waardes & interface Overleg met Dries Darquennes in verband met het optimaliseren van pictionary + implementatie van deze optimalisaties Poging tot het oplossen van bugs in verband met photoviewer als je zon 3 a 4 fotos verder gaat. Maken van verslagen

Photoviewer Photoviewer

N.V.T. Photoviewer

N.V.T. Photoviewer

Pictionary Pictionary Pictionary

Pictionary

01/05/2012 10/05/2012 17/05/2012 21/05/2012 21/05/2012 21/05/2012

Photoviewer

N.V.T.

Photoviewer Pictionary

Bugs fixen: buffer bug bij het veranderen van fotos Kleurenselectie optimaliseren en debugging van deze selectie (van 24 bit naar 16 bit datatype (uint --> ushortint) Gom toevoegen

Verslag: TouchDuino

37/39

7.2 Dries Darquennes


Datum 28/02/2012 05/03/2012 05/03/2012 06/03/2012 07/03/2012 08/03/2012 08/03/2012 10/03/2012 19/03/2012 21/03/2012 23/03/2012 24/03/2012 27/03/2012 30/03/2012 1/04/2012 03/04/201206/04/2012 Programma N.V.T. N.V.T. Snake Snake Snake N.V.T. N.V.T. Snake N.V.T. N.V.T. Wat Bestellen van componenten: Seeduino, SD card shield, MicroSD 2GB, 2.8 TFT Touch Shield Aankomst bestelling Poging om het SD-shield en het TFT-Touch Screen aan te sturen Menu van snake aanmaken met bijbehorende acties Beginnen met code maken van snake spel ( beweging slang met touch detectie ) Overleg met mr. Van Bauwel in verband met tekort aan I/O om SD-shield en TFT-Touch Screen aan te sturen met 1 controller Bestellen van componenten: Seeeduino Stalker v2, UartSBee V4, Grove - Thumb Joystick Mogelijkheid maken om muren aan en af te zetten

Testen compatibiliteit van tft met Stalker Overleg met mr. Van Bauwel omdat de Seeeduino Stalker niet compatibel is met ons tft-touch scherm Photovieuwer IC concept bedenken om het tekort aan I/O op te vangen met (assist) behulp van 2 controlles en een communicatiebus Snake Snake Snake N.V.T. Verdere functies van snake spel afwerken waaronder bait,beweging met joystick,score teller, GUI in c# maken waarmee de maps worden gestuurd naar de slave via serieele communicatie Implementatie voor de Highscore(schrijven) functie op zowel master als slave via Ic en met gebruik van de SD als opslag plaats. Joystick solderen (gebrek aan GROVE kabel) Implementatie voor de Highscore(lezen) functie op zowel master als slave via Ic en met gebruik van de SD als opslag plaats. Maps van GUI naar SD op slave zetten en vervolgens naar master krijgen om daar te gebruiken als map. Afwerken snake ( enkele bugs met de randen proberen op te lossen beter calibratie van de joystick ) Verslagen maken ( verder bugs verwijderen )

07/04/2012 08/04/201209/04/2012 11/04/201218/04/2012 25/04/2012 28/04/201221/05/2012

Snake Snake Snake N.V.T

Verslag: TouchDuino

38/39

Bijlagen

Hier volgen namelijk datasheets en schematics van de schakelingen waarvan wij gebruik maken:

Verslag: TouchDuino

39/39

Micro-SD Specification

2F.No2.Shangsha Industral.FuTian District ShenZhen City China 2 2 Tel +86 755 83896667 83896577 Fax +86 755 83896109

Micro-SD card specification Proprietary&Confidential


Copyright 2006

Contents
A. General Description............................................................................... 1 B. Features..................................................................................................2 C. Pin Assignment...................................................................................... 3 D. Hardware Interface................................................................................. 5 E. System Power Consumption ................................................................ 6 F. Electrical Specifications........................................................................ 6 G. DC Characteristic................................................................................... 7 H.AC Characteristic................................................................................... 8

H1. Micro SD Interface timing (Default) ......................................................... 8 H2. Micro SD Interface timing (High-speed Mode) ................................... 10 I. Physical Outline Dimension................................................................... 11

A. General Description
The Micro Secure Digital (Micro-SD) card is fully compliant to the SD Memory Card Specification version 1.1 (backward compatible with 1.01). It provides the highest level of performance for Micro-SD supported consumer electronic devices. Micro-SD card is capable for storing up to 512MB of data.

The Micro-SD card is based on an advanced 8-pin interface, designed to operate at a maximum operating frequency of 50MHz and a low voltage range from 2.7V to 3.6V. It can alternate communication protocol between SD mode or SPI mode. It performs data error detection and correction with very low power consumption.

Micro Secure Digital card is one of the most popular cards today based on its high performance, good reliability and wide compatibility.

B. Features
Support SD system specification version 1.1 Support Capacity : 16MB / 32MB / 64MB / 128MB / 256MB / 512MB Voltage range : Basic communication (CMD0, CMD15, CMD55, ACMD41) : 2.0 - 3.6V. Other command and memory access : 2.7 - 3.6V. Designed for read-only and read/write cards. Default mode : Variable clock rate 0-25MHz, up to 12.5MB/sec interface speed(using 4 parallel data lines) High-Speed mode : Variable clock rate 0-50MHz, up to 25MB/sec interface speed(using 4 parallel data lines) Switch function command supports High-Speed. Copyrights Protection Mechanism - Complies with highest security of SDMI standard. Password Protection of cards (option). Write Protect feature using mechanical switch. Built-in write protection features (permanent and temporary). Support SD SPI mode High transmission speed (refer to speed test section) +4KV/-4KV ESD protection in contact pads. Dimension : 15mm(L) x 11mm(W) x 1mm(H)

C. Pin Assignment

SD Mode pin Name 1 2 3 4 5 6 7 8 DAT2 CD/DAT3 2 CMD VDD CLK VSS DAT0 DAT1 Type1 I/O/PP I/O/PP 3 PP S I S I/O/PP I/O/PP Description Data Line[bit2] Card Detect/ Data Line[bit3] Command/Response Supply voltage Clock Supply voltage ground Data Line[bit0] Data Line[bit1] Name RSV CS DI VDD SCLK VSS DO RSV I3 I S I S O/PP Type

SPI Mode Description

Chip Select (neg true) Data In Supply voltage Clock Supply voltage ground Data Out

(1) S: power supply, I:input; O:output using push-pull drivers; PP:I/O using push-pull drivers (2) The extended DAT lines(DAT1-DAT3)are input on power up. They start to operate as DAT lines after SET_BUS_WIDTH command. The Host shall keep its own DAT1-DAT3 lines in input mode, as well, while they are not used. It is defined so, in order to keep compatibility to MultiMedia Cards. (3) At power up this line has a 50KOhm pull up enabled in the card. This resistor serves two functions Card detection and Mode Selection. For Mode Selection, the host can drive the line high or let it be pulled high to select SD mode. If the host wants to select SPI mode it should drive the line low. For Card detection, the host detects that the line is pulled high. This pull-up should be disconnected by the user, during regular data transfer , with SET_CLR_CARD_DETECT(ACMD42) command. Name CID Width 128bit Description Card identification number; card individual number for identification. Mandatory Relative card address; local system address of a card, dynamically suggested by the card and approved by the host during initialization. Mandatory Driver Stage Register; to configure the cards output drivers. Optioanal Card Specific Data; information about the card operation conditions. Mandatory SD Configuration Register; information about the Micro SD Memory Cards Special Features capabilities. Mandatory Operation condition register. Mandatory

RCA DSR CSD

16bit 16bit 128bit

SDR OCR

64bit 32bit

D. Hardware Interface
The SD Memory Card has six communication lines and three supply lines: CMD: Command is a bidirectional signal. The host and card drivers are operating in push pull mode. Data lines are bidirectional signals. Host and card drivers are operating in push pull mode Clock is a host to card signal. CLK operates in push pull mode. VDD is the power supply line for all cards. Ground lines.

DAT0-3:

CLK: VDD: VSS:

Bus circuitry diagram

E. System Power Consumption


Table list as below is the power consumption of Micro SD card with the flash memory. (PS4043 + Flash Memory) Max Power up Current (uA) 150 200 Max Stand by Current (uA) 150 200 Max Read Current (mA) 60@ 3.6V 80@ 3.6V Max Write Current (mA) 60@ 3.6V 80@ 3.6V

Flash mode Single(1) flash(1x8bit) Parallel(2) flash(2x8bit)

(1) Data transfer mode is single channel. (2) Data transfer mode is dual channel.

F. Electrical Specifications
Absolute Maximum Rating

Item 1 2 3 4

Symbol VDD-VSS VIN Ta Tst

Parameter DC Power Supply Input Voltage Operating Temperature Storage Temperature

MIN -0.3 VSS-0.3 -25 -40

MAX +3.3 VDD+0.3 +85 +85

Unit V V


Unit

Parameter Operating Temperature VDD Voltage

Symbol Ta VDD

Min -25 2.0

MAX +85 3.6

G. DC Characteristic
Micro SD Controller DC Characteristics
Parameter Peak voltage on all lines All Inputs Input Leakage Current All Outputs Output Leakage Current Output High Voltage VOH -10 0.75*VDD 10 uA V IOH=-100uA @VDD Min IOL=100uA @VDD Min -10 10 uA Symbol Min -0.3 Max. VDD+0.3 Unit V

Output Low Voltage

VOL

0.125*VDD

Input High Voltage Input Low Voltage

VIH VIL

0.625*VDD VSS-0.3

VDD+0.3 0.25*VDD

V V

Bus Signal Levels

Bus signal levels Power Supply Voltage


Parameter Supply voltage Supply voltage differentials(Vss1,Vss2) Power up time symbol VDD Min 2.0 -0.3 Max 3.6 0.3 Unit V V

250

mS

from 0v to VDDMin.

Bus Signal Line Load Parameter Pull-up resistance for CMD symbol RCMD RDAT CL CL CCARD Min 10 Max 100 Unit K omh Remark to prevent bus floating

Bus signal line capacitance Bus signal line capacitance Single card capacitance Maximum signal line inductance Pull-up resistance inside card

250 100 10 16

pF pF pF nH K omh

fpp<5 MHz, 21 cards fpp<20 MHz, 7 cards

fpp<20 MHz May be used for card detection

RDAT3

10

90

H. AC Characteristic
H1. Micro SD Interface timing (Default)

Parameter Symbol Min Max. Unit Clock CLK (All values are referred to min(VIH) and max(VIL) Clock frequency Data Transfer fPP 0 25 MHz Mode Clock frequency Identification 400 Mode(the low freq. is required for fOD 0 KHz 0(1)/100KHz MultiMedia Card compatibility) Clock low time Clock high time Clock rise time Clock fall time Clock low time Clock high time Clock rise time Clock fall time Input set-up time Input hold time tWL tWH tTLH tTHL tWL tWH tTLH tTHL tISU tIH 5 5 50 50 50 50 10 10 10 10 ns ns ns ns ns ns ns ns ns ns

Remark CL100 pF (7 cards) CL250 pF (21 cards) CL100 pF (7 cards) CL100 pF (7 cards) CL100 pF (7 cards) CL100 pF (7 cards) CL250 pF (21 cards) CL250 pF (21 cards) CL250 pF (21 cards) CL250 pF (21 cards) CL25 pF (1 cards) CL25 pF (1 cards) CL25 pF (1 cards)

Inputs CMD, DAT (referenced to CLK)

Outputs CMD, DAT (referenced to CLK) Output Delay time tODLY 0 14 ns

(1) 0Hz means to stop the clock. The given minimum frequency range is for cases were continues clock is required.

H2. Micro SD Interface timing (High-speed Mode)

Parameter Symbol Min Max. Unit Clock CLK (All values are referred to min(VIH) and max(VIL) Clock frequency Data Transfer fPP 0 50 MHz Mode Clock low time 7 ns tWL Clock high time 7 ns tWH Clock rise time 3 ns tTLH Clock fall time tTHL 3 ns Inputs CMD, DAT (referenced to CLK) Input set-up time 6 ns tISU Input hold time 2 ns tIH Outputs CMD, DAT (referenced to CLK) Output Delay time 0 14 ns tODLY Output Hold time 2.5 ns tOH Total System Capacitance for CL 40 pF each line1
(1) In order to satify severe timing, host shall drive only one card.

Remark

I. Physical Outline Dimension

Clean Coding Company

TITLE: SUBJECT: AUTHOR: VERSION:

BMP Format Windows Bitmap File Format Specifications Wim Wouters V1.1

Copyright 2008, Last printed on Tuesday 4 November 2008

BMP Format Windows Bitmap File Format Specifications

Table of Contents
TABLE OF CONTENTS INTRODUCTION BITMAP FILE FORMAT
General BMP Contents

2 3 4
4 4

FIELD DETAILS
Height Field Bits Per Pixel Field Compression Field Colors Field Important Colors Field

6
6 6 7 9 10

Page 2

Clean Coding Company

Introduction
This document describes the Microsoft Windows and IBM OS/2 picture bitmap files, called Bitmaps or BMP files. Most of the descriptions of the BMP file concentrate on the Microsoft Windows BMP structures like BMPINFOHEADER and BMPCOREINFO , but only a few describe the file contents on byte level. This information is therefor only intended to be used in applications where direct reading and writing of a BMP file is required.

Page 3

BMP Format Windows Bitmap File Format Specifications

Bitmap File Format


The following chapters contain the detailed information on the contents of the BMP file. First more general information will be given regarding the byte order and file alignment. The second chapter will concentrate on the byte-level contents of a BMP file. The third chapter will elaborate on this chapter and explain some of the concepts - like compression - and/or values in detail.

General
The BMP file has been created by Microsoft and IBM and is therefor very strictly bound to the architecture of the main hardware platform that both companies support: the IBM compatible PC. This means that all values stored in the BMP file are in the Intel format, sometimes also called the Little Endian format because of the byte order that an Intel processor uses internally to store values. The BMP files are the way, Windows stores bit mapped images. The BMP image data is bit packed but every line must end on a dword boundary - if thats not the case, it must be padded with zeroes. BMP files are stored bottom-up, that means that the first scan line is the bottom line. The BMP format has four incarnations, two under Windows (new and old) and two under OS/2, all are described here.

BMP Contents
The following table contains a description of the contents of the BMP file. For every field, the file offset, the length and the contents will be given. For a more detailed discussion, see the following chapters. Offset 0000h Field Identifier Size 2 bytes Contents The characters identifying the bitmap. The following entries are possible: BM - Windows 3.1x, 95, NT, BA - OS/2 Bitmap Array CI - OS/2 Color Icon CP - OS/2 Color Pointer IC - OS/2 Icon PT - OS/2 Pointer Complete file size in bytes. Reserved for later use. Offset from beginning of file to the beginning of the bitmap data. Length of the Bitmap Info Header used to describe the bitmap colors, compression, The following sizes are possible:

0002h 0006h 000Ah 000Eh

File Size Reserved Bitmap Data Offset Bitmap Header Size

1 dword 1 dword 1 dword 1 dword

Page 4

Clean Coding Company

0012h 0016h 001Ah 001Ch

Width Height Planes Bits Per Pixel

1 dword 1 dword 1 word 1 word

001Eh

Compression

1 dword

0022h 0026h 002Ah 002Eh 0032h 0036h

Bitmap Data Size HResolution VResolution Colors Important Colors Palette

1 dword 1 dword 1 dword 1 dword 1 dword N * 4 byte

0436h

Bitmap Data

x bytes

28h - Windows 3.1x, 95, NT, 0Ch - OS/2 1.x F0h - OS/2 2.x Horizontal width of bitmap in pixels. Vertical height of bitmap in pixels. Number of planes in this bitmap. Bits per pixel used to store palette entry information. This also identifies in an indirect way the number of possible colors. Possible values are: 1 - Monochrome bitmap 4 - 16 color bitmap 8 - 256 color bitmap 16 - 16bit (high color) bitmap 24 - 24bit (true color) bitmap 32 - 32bit (true color) bitmap Compression specifications. The following values are possible: 0 - none (Also identified by BI_RGB) 1 - RLE 8-bit / pixel (Also identified by BI_RLE4) 2 - RLE 4-bit / pixel (Also identified by BI_RLE8) 3 - Bitfields (Also identified by BI_BITFIELDS) Size of the bitmap data in bytes. This number must be rounded to the next 4 byte boundary. Horizontal resolution expressed in pixel per meter. Vertical resolution expressed in pixels per meter. Number of colors used by this bitmap. For a 8-bit / pixel bitmap this will be 100h or 256. Number of important colors. This number will be equal to the number of colors when every color is important. The palette specification. For every entry in the palette four bytes are used to describe the RGB values of the color in the following way: 1 byte for blue component 1 byte for green component 1 byte for red component 1 byte filler which is set to 0 (zero) Depending on the compression specifications, this field contains all the bitmap data bytes which represent indices in the color palette.

Note: The following sizes were used in the specification above: Size char word dword # bytes 1 2 4 Sign signed unsigned unsigned

Page 5

BMP Format Windows Bitmap File Format Specifications

Field Details
Some of the fields require some more information. The following chapters will try to provide this information:

Height Field
The Height field identifies the height of the bitmap in pixels. In other words, it describes the number of scan lines of the bitmap. If this field is negative, indicating a top-down DIB, the Compression field must be either BI_RGB or BI_BITFIELDS. Top-down DIBs cannot be compressed.

Bits Per Pixel Field


The Bits Per Pixel (BBP) field of the bitmap file determines the number of bits that define each pixel and the maximum number of colors in the bitmap. When this field is equal to 1. The bitmap is monochrome, and the palette contains two entries. Each bit in the bitmap array represents a pixel. If the bit is clear, the pixel is displayed with the color of the first entry in the palette; if the bit is set, the pixel has the color of the second entry in the table. When this field is equal to 4. The bitmap has a maximum of 16 colors, and the palette contains up to 16 entries. Each pixel in the bitmap is represented by a 4-bit index into the palette. For example, if the first byte in the bitmap is 1Fh, the byte represents two pixels. The first pixel contains the color in the second palette entry, and the second pixel contains the color in the sixteenth palette entry. When this field is equal to 8. The bitmap has a maximum of 256 colors, and the palette contains up to 256 entries. In this case, each byte in the array represents a single pixel. When this field is equal to 16. The bitmap has a maximum of 2^16 colors. If the Compression field of the bitmap file is set to BI_RGB, the Palette field does not contain any entries. Each word in the bitmap array represents a single pixel. The relative intensities of red, green, and blue are represented with 5 bits for each color component. The value for blue is in the least significant 5 bits, followed by 5 bits each for green and red, respectively. The most significant bit is not used.

Page 6

Clean Coding Company

If the Compression field of the bitmap file is set to BI_BITFIELDS, the Palette field contains three dword color masks that specify the red, green, and blue components, respectively, of each pixel. Each word in the bitmap array represents a single pixel. Windows NT specific: When the Compression field is set to BI_BITFIELDS, bits set in each dword mask must be contiguous and should not overlap the bits of another mask. All the bits in the pixel do not have to be used. Windows 95 specific: When the Compression field is set to BI_BITFIELDS, Windows 95 supports only the following 16bpp color masks: A 5-5-5 16-bit image, where the blue mask is 0x001F, the green mask is 0x03E0, and the red mask is 0x7C00; and a 5-6-5 16-bit image, where the blue mask is 0x001F, the green mask is 0x07E0, and the red mask is 0xF800. When this field is equal to 24. The bitmap has a maximum of 2^24 colors, and the Palette field does not contain any entries. Each 3-byte triplet in the bitmap array represents the relative intensities of blue, green, and red, respectively, for a pixel. When this field is equal to 32. The bitmap has a maximum of 2^32 colors. If the Compression field of the bitmap is set to BI_RGB, the Palette field does not contain any entries. Each dword in the bitmap array represents the relative intensities of blue, green, and red, respectively, for a pixel. The high byte in each dword is not used. If the Compression field of the bitmap is set to BI_BITFIELDS, the Palette field contains three dword color masks that specify the red, green, and blue components, respectively, of each pixel. Each dword in the bitmap array represents a single pixel. Windows NT specific: When the Compression field is set to BI_BITFIELDS, bits set in each dword mask must be contiguous and should not overlap the bits of another mask. All the bits in the pixel do not have to be used. Windows 95 specific: When the Compression field is set to BI_BITFIELDS, Windows 95 supports only the following 32bpp color mask: The blue mask is 0x000000FF, the green mask is 0x0000FF00, and the red mask is 0x00FF0000.

Compression Field
The Compression field specifies the way the bitmap data is stored in the file. This information together with the Bits Per Pixel (BPP) field identifies the compression algorithm to follow. The following values are possible in this field: Value BI_RGB BI_RLE4 Meaning An uncompressed format. An RLE format for bitmaps with 4 bits per pixel. The compression format is a

Page 7

BMP Format Windows Bitmap File Format Specifications

BI_RLE8

BI_BITFIELDS

two-byte format consisting of a count byte followed by two word-length color indices. For more information, see the following Remarks section. A run-length encoded (RLE) format for bitmaps with 8 bits per pixel. The compression format is a two-byte format consisting of a count byte followed by a byte containing a color index. For more information, see the following Remarks section. Specifies that the bitmap is not compressed and that the color table consists of three double word color masks that specify the red, green, and blue components, respectively, of each pixel. This is valid when used with 16- and 32- bits-per-pixel bitmaps.

When the Compression field is BI_RLE8, the bitmap is compressed by using a run-length encoding (RLE) format for an 8-bit bitmap. This format can be compressed in encoded or absolute modes. Both modes can occur anywhere in the same bitmap. Encoded mode consists of two bytes: The first byte specifies the number of consecutive pixels to be drawn using the color index contained in the second byte. In addition, the first byte of the pair can be set to zero to indicate an escape that denotes an end of line, end of bitmap, or delta. The interpretation of the escape depends on the value of the second byte of the pair, which can be one of the following: 0 1 2 End of line. End of bitmap. Delta. The two bytes following the escape contain unsigned values indicating the horizontal and vertical offsets of the next pixel from the current position.

Absolute mode. The first byte is zero and the second byte is a value in the range 03H through FFH. The second byte represents the number of bytes that follow, each of which contains the color index of a single pixel. When the second byte is 2 or less, the escape has the same meaning as in encoded mode. In absolute mode, each run must be aligned on a word boundary.

The following example shows the hexadecimal values of an 8-bit compressed bitmap. 03 04 05 06 00 03 45 56 67 00 02 78 00 02 05 01 02 78 00 00 09 1E 00 01 This bitmap would expand as follows (two-digit values represent a color index for a single pixel): 04 04 04 06 06 06 06 06 45 56 67 78 78 move current position 5 right and 1 down 78 78 end of line 1E 1E 1E 1E 1E 1E 1E 1E 1E end of RLE bitmap

Page 8

Clean Coding Company

When the Compression field is BI_RLE4, the bitmap is compressed by using a run-length encoding format for a 4-bit bitmap, which also uses encoded and absolute modes: In encoded mode. The first byte of the pair contains the number of pixels to be drawn using the color indices in the second byte. The second byte contains two color indices, one in its high-order four bits and one in its low-order four bits. The first of the pixels is drawn using the color specified by the high-order four bits, the second is drawn using the color in the low-order four bits, the third is drawn using the color in the high-order four bits, and so on, until all the pixels specified by the first byte have been drawn. In absolute mode. The first byte is zero, the second byte contains the number of color indices that follow, and subsequent bytes contain color indices in their high- and low-order four bits, one color index for each pixel. In absolute mode, each run must be aligned on a word boundary. The end-of-line, end-of-bitmap, and delta escapes described for BI_RLE8 also apply to BI_RLE4 compression. The following example shows the hexadecimal values of a 4-bit compressed bitmap. 03 04 05 06 00 06 45 56 67 00 04 78 00 02 05 01 04 78 00 00 09 1E 00 01 This bitmap would expand as follows (single-digit values represent a color index for a single pixel): 0 4 0 0 6 0 6 0 4 5 5 6 6 7 7 8 7 8 move current position 5 right and 1 down 7 8 7 8 end of line 1 E 1 E 1 E 1 E 1 end of RLE bitmap

Colors Field
The Colors field specifies the number of color indices in the color table that are actually used by the bitmap. If this value is zero, the bitmap uses the maximum number of colors corresponding to the value of the BBP field for the compression mode specified by the Compression field. If the Colors field is nonzero and the BBP field less than 16, the Colors field specifies the actual number of colors the graphics engine or device driver accesses. If the BBP field is 16 or greater, then Colors field specifies the size of the color table used to optimize performance of Windows color palettes.

Page 9

BMP Format Windows Bitmap File Format Specifications

If BBP equals 16 or 32, the optimal color palette starts immediately following the three double word masks. If the bitmap is a packed bitmap (a bitmap in which the bitmap array immediately follows the bitmap header and which is referenced by a single pointer), the Colors field must be either 0 or the actual size of the color table.

Important Colors Field


The Important Colors field specifies the number of color indices that are considered important for displaying the bitmap. If this value is zero, all colors are important.

Page 10

You might also like