2 Replies Latest reply on Oct 15, 2015 8:21 PM by awesomeness01

    Porting Arduino TFT Shield For Intel Galileo


      I had an 2.8 TFT Touch Shield for Arduino. I noted the steps to make it work with Intel Galileo.


      Let's see our shield first. http://www.seeedstudio.com/wiki/2.8%27%27_TFT_Touch_Shield_v2.0



      Seeedstudio's TFT Screen shield uses SPI protocol and libraries to read/write registers on TFT device. TFT library is already being implemented for Arduino UNO and it is available at github Seeed-Studio/TFT_Touch_Shield_V2 · GitHub


      There are couple lines in the TFT library to implement for Quark SoC. Since the TFT library implemented with respect to microcontroller, pins have been driven with DDRX/PORTX registers. In order to make it work with SoC we need to reimplement this part compatible with Galileo. I made it with a very basic step with using pinMode and digitalWrite functions from wiring_digital library.


      Previously on TFTv2.h file [can be seen from github link]

      #define TFT_CS_LOW {DDRD |= 0x20;PORTD &=~ 0x20;}
      #define TFT_CS_HIGH {DDRD |= 0x20;PORTD |= 0x20;}
      #define TFT_DC_LOW {DDRD |= 0x40;PORTD &=~ 0x40;}
      #define TFT_DC_HIGH {DDRD |= 0x40;PORTD |= 0x40;}
      #define TFT_BL_OFF {DDRD |= 0x80;PORTD &=~ 0x80;}
      #define TFT_BL_ON {DDRD |= 0x80;PORTD |= 0x80;}
      #define TFT_CS_LOW  {pinMode(CS_PIN, OUTPUT);digitalWrite(CS_PIN, LOW);}
      #define TFT_CS_HIGH {pinMode(CS_PIN, OUTPUT);digitalWrite(CS_PIN, HIGH);}
      #define TFT_SD_LOW  {pinMode(SD_PIN, OUTPUT);digitalWrite(SD_PIN, LOW);}
      #define TFT_SD_HIGH {pinMode(SD_PIN, OUTPUT);digitalWrite(SD_PIN, HIGH);}
      #define TFT_DC_LOW  {pinMode(DC_PIN, OUTPUT);digitalWrite(DC_PIN, LOW);}
      #define TFT_DC_HIGH {pinMode(DC_PIN, OUTPUT);digitalWrite(DC_PIN, HIGH);}
      #define TFT_BL_OFF  {pinMode(BL_PIN, OUTPUT);digitalWrite(BL_PIN, LOW);}
      #define TFT_BL_ON   {pinMode(BL_PIN, OUTPUT);digitalWrite(BL_PIN, HIGH);}


      I also defined the pins as expected from the arduino pin map.

      //TFT Screen PIN Functions Refer to TFT Schematics
      #define SD_PIN 4
      #define CS_PIN 5
      #define DC_PIN 6
      #define BL_PIN 7


      Above additions and changes makes TFTv2 library compatible with Intel Galileo.

      One other item you need is pgmspace.h file which has been pointed in one of the other thread. Missing avr/pgmspace.h Direct link to source: http://github.com/mikalhart/galileo-Pgmspace.h/


      Edited version of TFTv2 library for Galileo can be found from: spitft/TFTv2 at master · odundar/spitft · GitHub


      TFTv2 library and pgmspace.h libraries are ready to use. Regular procedure to start using TFTv2 library and TFT shield is to copying the library from provided wiki page and open an example and run it. In this follow the regular path;


      Screenshot from 2014-05-05 16:52:58.png


      And here we go:




      I didn't work on the BMP and touch samples, they require some additions. The BMP samples has been designed to read from SD card on TFT.


      For a native C++ solution you can refer to sample code in github repo, examples - DrawCircle https://github.com/odundar/spitft/tree/master/examples


      To work on Native code as you all know, you need to first review BSP Build Guide to create image and Galileo native toolchain to work on. Intel's IoT Developer Kit is the best way to start, everything included. https://software.intel.com/en-us/iotdevkit

      I assume you have the environment and created a new project on Eclipse and get the DrawCircle C++ application sources from spitft/examples at master · odundar/spitft · GitHub .

      When you compile, build and deploy project to Galileo it will draw the circles like Arduino sketch did as native.



      #include <iostream>
      #include "TFTv2.h"
      #include "wiring_digital.h"
      #include "variant.h"
      using namespace std;
      int main(int argc, char *argv[]) {
          init(argc, argv);
          Tft.drawCircle(100, 100, 30, YELLOW); //center: (100, 100), r = 30 ,color : YELLOW
          Tft.drawCircle(100, 200, 40, CYAN); // center: (100, 200), r = 10 ,color : CYAN
          Tft.fillCircle(200, 100, 30, RED); //center: (200, 100), r = 30 ,color : RED
          Tft.fillCircle(200, 200, 30, BLUE); //center: (200, 200), r = 30 ,color : BLUE
          return 0;


      Seeedstudio 2.8" TFT Screen is ready to use as Arduino sketches and with native applications. Similar changes can be made to other shields as necessary.

        • 1. Re: Porting Arduino TFT Shield For Intel Galileo

          Hi odundar,


          I was trying to use TFT screen with the help of your steps above.


          I am getting following error:



          Did you also get this error?


          Can you share your SPI.h file?

          Mine is as follows:



          * Copyright (c) 2010 by Cristian Maglie <c.maglie@bug.st>

          * Copyright (c) 2013 Intel Corporation

          * SPI Master library for arduino.


          * This file is free software; you can redistribute it and/or modify

          * it under the terms of either the GNU General Public License version 2

          * or the GNU Lesser General Public License version 2.1, both as

          * published by the Free Software Foundation.


          #ifndef _SPI_H_INCLUDED

          #define _SPI_H_INCLUDED

          #include "Arduino.h"

          #define SPI_CLOCK_DIV4 0x00

          #define SPI_CLOCK_DIV16 0x01

          #define SPI_CLOCK_DIV64 0x02

          #define SPI_CLOCK_DIV128 0x03

          #define SPI_CLOCK_DIV2 0x04

          #define SPI_CLOCK_DIV8 0x05

          #define SPI_CLOCK_DIV32 0x06

          //#define SPI_CLOCK_DIV64 0x07


          #define SPI_MODE0 0x00

          #define SPI_MODE1 0x04

          #define SPI_MODE2 0x08

          #define SPI_MODE3 0x0C



          class SPIClass {


            byte transfer(byte _data);

            void transferBuffer(const uint8_t *, uint8_t *, uint32_t);


            // SPI Configuration methods

            void attachInterrupt();

            void detachInterrupt(); // Default


            void init();

            void begin(); // Default

            void end();


            void setBitOrder(uint8_t);

            void setDataMode(uint8_t);

            void setClockDivider(uint8_t);


            // SPI Write String

            // SPIWriteString will write an array of chars (str) of length

            // len out to SPI. Write order is [0], [1], ..., [len-1].

            void WriteString(char * str, uint8_t len);

            // SPIWriteByte will write a single byte out of SPI.

            void WriteByte(uint8_t b);



            int fd;

            uint8_t mode;

            uint8_t bitOrder;

            uint8_t clkDiv;



          extern SPIClass SPI;





          My code compiles if I comment "void init();" line , but the screen is still blank. Can you help me out?





          • 2. Re: Porting Arduino TFT Shield For Intel Galileo

            Hi! I'm having trouble with galileo gen2.  It works, but moves very slowly. I got the library and took SPI.init() out of TFTv2.cpp. Any suggestions?