Arduino Uno: Bitmap Animation on ILI9341 TFT Touchscreen Display Shield With Visuino

by BoianM in Circuits > Arduino

19885 Views, 56 Favorites, 0 Comments

Arduino Uno: Bitmap Animation on ILI9341 TFT Touchscreen Display Shield With Visuino

Arduino Uno: Bitmap animation on ILI9341 TFT Touchscreen Display Shield with Visuino

ILI9341 based TFT Touchscreen Display Shields are very popular low cost Display Shields for Arduino. Visuino has had support for them for quite a while, but I never had chance to write a Tutorial on how to use them. Recently however few people asked questions about using displays with Visuino, so I decided to make a tutorial.

In this Tutorial, I will show you how easy it is, to connect the Shield to Arduino, and program it with Visuino to animate a Bitmap to move around on the Display.

Components

581960d14fbade2cf7000bc1.jpeg
  1. One Arduino Uno compatible board (It may work with Mega too, but I have not tested the shield with it yet)
  2. One ILI9341 2.4" TFT Touchscreen Shield for Arduino

Connect the ILI9341 TFT Touchscreen Display Shield to Arduino

581961cb50e1b663bd0006e0.jpeg
5819619f15be4dc0f5000f04.jpeg
581961ae937ddbd8b60007db.jpeg

Plug the TFT Shield on top of the Arduino Uno as shown on the pictures

Start Visuino and Add TFT Display Shield

AddShields.png
ShieldAdding.png

To start programming the Arduino, you will need to have the Arduino IDE installed from here: http://www.arduino.cc/.

Make sure that you install 1.6.7 or higher, otherwise this Instructable will not work!

The Visuino: https://www.visuino.com also needs to be installed.

  1. Start Visuino as shown in the first picture
  2. Click on the "Arrow Down" button of the Arduino component to open the Drop Down Menu (Picture 1)
  3. From the Menu select "Add Shields..." (Picture 1)
  4. In the "Shields" dialog expand the "Displays" category, and select the "TFT Color Touch Screen Display ILI9341 Shield", then click on the "+" button to add it (Picture 2)

In Visuino: Add Draw Text Element for the Text Shadow

ShieldAdded.png
AddText.png
AddTextSetColor.png
AddTextSetSize.png
AddTextSetText.png
AddTextSetY.png

Next we need to add Graphics elements to render text and bitmap. First we will add graphics element to draw the shadow of the text:

  1. In the Object Inspector, click on the "..." button next to the value of the "Elements" property of the "TFT Display" Element (Picture 1)
  2. In the Elements editor select “Draw Text”, and then click on the "+" button (Picture 2) to add one (Picture 3)
  3. In the Object Inspector set the value of the "Color" property of the "Draw Text1" element to "aclSilver" (Picture 3)
  4. In the Object Inspector set the value of the "Size" property of the "Draw Text1" element to "4" (Picture 4). This makes the text bigger
  5. In the Object Inspector set the value of the "Text" property of the "Draw Text1" element to "Visuino" (Picture 5)
  6. In the Object Inspector set the value of the "X" property of the "Draw Text1" element to "43" (Picture 6)
  7. In the Object Inspector set the value of the "Y" property of the "Draw Text1" element to "278" (Picture 6)

In Visuino: Add Draw Text Element for the Text Foreground

AddText2.png
AddText2Size.png
AddText2Text.png
AddText2Y.png

Now we will add graphics element to draw the text:

  1. In the Elements editor select “Draw Text”, and then click on the "+" button (Picture 1) to add second one (Picture 2)
  2. In the Object Inspector set the value of the "Size" property of the "Draw Text1" element to "4" (Picture 2)
  3. In the Object Inspector set the value of the "Text" property of the "Draw Text1" element to "Visuino" (Picture 3)
  4. In the Object Inspector set the value of the "X" property of the "Draw Text1" element to "40" (Picture 4)
  5. In the Object Inspector set the value of the "Y" property of the "Draw Text1" element to "275" (Picture 4)

In Visuino: Add Draw Bitmap Element for the Animation

AddBitmap.png
BitmapOpen.png
BitmapLoad.png
FileOpenDialog.png
BitmapCloseDialog.png

Next we will add graphics element to draw the bitmap:

  1. In the Elements editor select “Draw Bitmap”, and then click on the "+" button (Picture 1) to add one (Picture 2)
  2. In the Object Inspector, click on the "..." button next to the value of the "Bitmap" property of the "Draw Bitmap1" Element (Picture 2) to open the "Bitmap Editor" (Picture 3)
  3. In the "Bitmap Editor" click on the "Load..." button (Picture 3) to open the File Open Dialog (Picture 4)
  4. In the File Open Dialog, select the bitmap to draw, and click on the "Open" button (Picture 4). If the file is too big it may not be able to fit in the Arduino memory. If you get out of memory error during the compilation, you may need to select a smaller bitmap
  5. In the "Bitmap Editor" click on the "OK." button (Picture 5) to close the dialog

In Visuino: Add Pins for the X and Y Properties of the Draw Bitmap Element

BitmapPinX.png
BitmapPinXSelect.png
BitmapPinY.png
BitmapPinYSelect.png

To animate the Bitmap, we need to control its X and Y position. For this we will add pins for the X and Y properties:

  1. In the Object Inspector click on the "Pin" button at front of the "X" property of the "Draw Bitmap1" element (Picture 1), and select "Integer SinkPin" (Picture 2)
  2. In the Object Inspector click on the "Pin" button at front of the "Y" property of the "Draw Bitmap1" element (Picture 3), and select "Integer SinkPin" (Picture 4)

In Visuino: Add 2 Integer Sine Generators, and Configure the First One

ComponentSineGen.png
ComponentSineGen1Amplitude.png
ComponentSineGen1Offset.png
ComponentSineGen1Frequency.png

We will use 2 Integer sine generators to animate the bitmap movement:

  1. Type "sine" in the Filter box of the Component Toolbox then select the "Sine Integer Generator" component (Picture 1), and drop two of them it in the design area
  2. In the Object Inspector, set the value of the "Amplitude" property of the SineIntegerGenerator1 component to "96" (Picture 2)
  3. In the Object Inspector, set the value of the "Offset" property of the SineIntegerGenerator1 component to "96" (Picture 3)
  4. In the Object Inspector, set the value of the "Frequency" property of the SineIntegerGenerator1 component to "0.2" (Picture 4)

In Visuino: Configure the Second Sine Generator, and Connect the Sine Generators to the X and Y Coordinate Pins of the Bitmap

ComponentSineGen2Amplitude.png
ComponentSineGen2Offset.png
ComponentSineGen2Frequency.png
ComponentSineGen1Connect.png
ComponentSineGen2Connect.png
  1. In the Object Inspector, set the value of the "Amplitude" property of the SineIntegerGenerator2 component to "120" (Picture 1)
  2. In the Object Inspector, set the value of the "Offset" property of the SineIntegerGenerator2 component to "120" (Picture 2)
  3. In the Object Inspector, set the value of the "Frequency" property of the SineIntegerGenerator2 component to "0.03" (Picture 3)
  4. Connect the "Out" output pin of the SineIntegerGenerator1 component to the "X" input pin of the "Shields.TFT Sisplay.Elements.Draw Bitmap1" element of the Arduino component (Picture 4)
  5. Connect the "Out" output pin of the SineIntegerGenerator2 component to the "Y" input pin of the "Shields.TFT Display.Elements.Draw Bitmap1" element of the Arduino component (Picture 5)

In Visuino: Add and Connect Start and Clock Multi Source Components

ComponentRepeat.png
ComponentClockMultiSource.png
ComponentClockMultiSourceConnect1.png
ComponentClockMultiSourceConnect2.png
ComponentClockMultiSourceConnect3.png
ComponentClockMultiSourceConnect4.png

To render the bitmap every time the X and Y position are updated we need to send a clock signal to the "Draw Bitmap1" element. To send the command after the positions have been changed, we need a way to synchronize the events. For this we will use Repeat component to constantly generate events, and Clock Multi Source to generate 2 events in sequence. The first event will clock the sine generators to update the X and Y positions, and the second will clock the "Draw Bitmap1" :

  1. Type "repeat" in the Filter box of the Component Toolbox, then select the "Repeat" component (Picture 1), and drop it in the design area (Picture 2)
  2. Type "multi" in the Filter box of the Component Toolbox, then select the "Clock Multi Source" component (Picture 2), and drop it in the design area (Picture 3)
  3. Connect the "Out" output pin of the Repeat1 component to the "In" input pin of the ClockMultiSource1 component (Picture 3)
  4. Connect the "Pin[ 0 ]" output pin of the "Out" pins of the ClockMultiSource1 component to the "In" input pin of the SineIntegerGenerator1 component (Picture 4)
  5. Connect the "Pin[ 0 ]" output pin of the "Out" pins of the ClockMultiSource2 component to the "In" input pin of the SineIntegerGenerator1 component (Picture 5)
  6. Connect the "Pin[ 1 ]" output pin of the "Clock" input pin of the "Shields.TFT Display.Elements.Draw Bitmap1" element of the Arduino component (Picture 6)

Generate, Compile, and Upload the Arduino Code

Generate.png
ArduinoIDE.png
  1. In Visuino, Press F9 or click on the button shown on Picture 1 to generate the Arduino code, and open the Arduino IDE
  2. In the Arduino IDE, click on the Upload button, to compile and upload the code (Picture 2)

And Play...

VisuinoDiagramCrop.png
5819629450e1b6f029001e41.jpeg
581962acdeafa4298e001092.jpeg
DSC05930.JPG
DSC05931.JPG
Demo: Arduino Uno: Bitmap animation on ILI9341 TFT Touchscreen Display Shield with Visuino

Congratulations! You have completed the project.

Pictures 2, 3, 4 and 5 and the Video show the connected and powered up project. You will see the Bitmap moving around the ILI9341 based TFT Touchscreen Display Shield as seen on the Video.

On Picture 1 you can see the complete Visuino diagram.
Also attached is the Visuino project, that I created for this Instructable, and the bitmap with the Visuino logo. You can download and open it in Visuino: https://www.visuino.com

Project Files

VisuinoColor.bmp

Here is the Bitmap image that I used for the project.

Also included is the Visuino project file.