Drawing Bitmaps onto the OLED Screen ( PART II )

 Overview

This is a short tutorial that goes through how to store bitmap images into the available external memories, namely the MMC card (SD-Compatible) and the Dataflash chip, and then access these bitmaps and draw it to the OLED screen.


In this part, we’ll cover using the external Dataflash chip (DFlash).


What you would need:

Hardware

  • BlazingCore100
  • 2.83” OLED w/ Touch Screen Interface Board
  • Serial Comm.Key
  • Power Supply (6V – 9V DC)


Software

  • Sonata IDE

 

Introduction
The external dataflash chip onboard the BCore Board has a memory capacity of 1MB.
As such, it is meant for storing smaller image files and not a full screen (320x240 pixels) bitmap image.
Should you need to load larger files, please use an MMC card.

In this tutorial, we’ll be using the image as shown below;

Play Button

File Name: Play.bmp
Resolution: 32 x 32 pixels

First, Create a New Project and Save it.

Storing the Bitmap Image into the DFlash

  1. To store Bitmap files in the External DataFlash, make sure the Bitmap files you want loaded into the  DataFlash is stored in: “Your Project Folder
  2. Next, Select the data file (DATA1) under the DataFlash Resources of your project, and declare an array of type data.

DataCode

BC CodeCode:

‘DATA1
DATA IMAGE(1563) FROMFILE "Play.bmp"

The value 1563 is the size of the bmp file in word (16bit) meaning every 2 bytes make a word.

You may obtain the size by:
i.    Right-click on the bmp image
ii.    Select properties
iii.    Under “General” look for size. (Take the value within the bracket and divide it by 2.)

Image Size

3.    Click on the DataFlash tab;

DataFlash Tab

4.    Click on Compile. If there’s no pop up, that’s a good thing. (It means there are no problems).

DataFlash Compile

5.    Next, click on Download. The download will take some time depending on the amount of Data there is to be downloaded to the chip. The IDE may appear to hang at this stage. Don’t worry. It’s downloading.

DataFlash Download

6.    BMP files are now programmatically accessible through the use of the variable name (in this case, IMAGE) as per the example code under the OLED.Draw.BitmapDFlash Command.

Note: The data file downloads directly to the external data flash chip, separate from downloading the actual program. Downloading your program does NOT download the data from the data file to the external data flash chip at the same time.

 

Drawing the Bitmap to Screen

OLED.Draw.BitmapFromDFlash(Position,Address)

Parameters:
•    Position: Point XY location to draw bitmap
•    Address: Address of the Bitmap stored in the DFlash

You may get the address of your image by using the command AddressOf(variable name)

Since Data1 is separate from the main module, it is necessary to type the data code name “DATA1” along with the variable name in order to let the compiler know where the variable “IMAGE” is declared.

BC CodeCode:

Dim P1 As Point
Public Sub Main()
Dim I1 As Integer
DEBUG.PRINT "OLED - BITMAP"

OLED.INIT(0)
OLED.Background.Colour = Const.Colour.Black
I1 = DFlash.AddressOf(DATA1.IMAGE)
P1.X = 143
P1.Y = 103
OLED.DRAW. BitmapFromDFlash (P1, I1)
End Sub


Your image should end up in the middle of the screen as seen in the image right at the top.