Support MCUFriend UNO TFT Shield on UNO R4

Topic created by Jean-Marc Zingg

I have updated my fork Arduino_GFX aka GFX_Library_for_Arduino with support for MCUFriend UNO Shields.
See Arduino_UNOPAR8.cpp databus driver class.

Thanks to this post: https://forum.arduino.cc/t/digitalwritefast-with-uno-r4/1145206/11 from @trevormakes.
-jz-

6 Likes

Works like a charm! Thanks alot for your work. Arduino R4 Wifi with ILI9486. But took some time to get the examples to work, had to find the Arduino_UNOPAR8 bus type in the source code to get my display to work

1 Like

I have updated bus class Arduino_UNOPAR8 in my fork. Now uses preset control pins according to the MCUFriend UNO shields instead of pins from constructor parameters.
This allows to achieve faster speed.

ILI9341 8bit parallel MCUFriend shield on Arduino UNO R4
Arduino_GFX library Test!
Benchmark micro-secs
Screen fill 340204
Text 56359
Pixels 1139533
Lines 1075651
Horiz/Vert Lines 40209
Rectangles (filled) 966288
Rectangles (outline) 24883
Triangles (filled) 328035
Triangles (outline) 62037
Circles (filled) 144576
Circles (outline) 99174
Arcs (filled) 103068
Arcs (outline) 204806
Rounded rects (filled) 976163
Rounded rects (outline) 59339
Done!

ILI9341 8bit parallel MCUFriend shield on Arduino UNO R3
Arduino_GFX library Test!
Benchmark micro-secs
Screen fill 768060
Text 360800
Pixels 3028136
Lines 3997836
Horiz/Vert Lines 88248
Rectangles (filled) 2157228
Rectangles (outline) 60136
Triangles (filled) 1011436
Triangles (outline) 222660
Circles (filled) 395712
Circles (outline) 339752
Arcs (filled) 1183140
Arcs (outline) 3109208
Rounded rects (filled) 2220820
Rounded rects (outline) 206528
Done!

The timing test was done using PDQgraphicstest.

As soon as I receive my Arduino UNO R4 minima, I will re-test and then add a Pull Request to https://github.com/moononournation/Arduino_GFX.
-jz-

1 Like

Great work! Do post a video of that working :smiley:

I have no experience with taking videos, but my Sony Cyber-shot was able...

Can't upload MP4. Trying to zip it. But it is too big.

MAH00666.MP4

Don't know how to make it play directly. But GitHub lets you download it.
-jz-

https://www.youtube.com/shorts/r4yulq_ZHaU

UNO TFT shield on UNO R4 - YouTube

After 25 days I just got a mail that my order will be delayed even further.

I have taken your library and installed it in my IDE, but when compiling it gives me an error that the library does not enter arduino uno rev4. Should the installation be done in a different way than downloading the zip?

I don't understand this message. Please post the complete error message.
Yes, ZIP install should work.
See also: 2.8" TFT LCD on R4 Wifi Issue - #4 by ZinggJM

I have the following code

#include "Robot-emotion-images.h"
//#include "structData.h"

//#include <Arduino_GFX_Library.h>


//Arduino_DataBus *bus = new Arduino_HWSPI(16 /* DC */, 5 /* CS */);
//Arduino_GFX *gfx = new Arduino_ILI9341(bus, 17 /* RST */);


void setup() {
  Serial.begin(9600);
}

void loop() {
  //int16_t wid = gfx->width();
  //int16_t ht = gfx->height();
  for (int instanceIndex = 0; instanceIndex < sizeof(feliz) / sizeof(feliz[0]); ++instanceIndex) {
    const uint8_t* image = feliz[instanceIndex];     
    
    //gfx->drawBitmap(0, 0, image, 400, 240, BLACK);
    delay(500);
  }

  delay(10000);
}

and it generates the following message if I compile it

El Sketch usa 33584 bytes (12%) del espacio de almacenamiento de programa. El máximo es 262144 bytes.
Las variables Globales usan 2524 bytes (7%) de la memoria dinámica, dejando 30244 bytes para las variables locales. El máximo es 32768 bytes.

If I activate the library then the following message appears

/home/adria/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld: /tmp/arduino/sketches/E89C27448B011D5C0C31789D07E43477/Robot-emotion-slave.ino.elf section `.text' will not fit in region `FLASH'
/home/adria/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld: region `FLASH' overflowed by 1831296 bytes
collect2: error: ld returned 1 exit status

exit status 1

Compilation error: exit status 1```

I am to lazy to get that translated, but I assume you used up nearly all available RAM already.
But it is the region FLASH that overflows.

Did you comment out more than the library for the first compilation?

This is what I get compiling PDQgraphictest:

Sketch uses 72816 bytes (27%) of program storage space. Maximum is 262144 bytes.
Global variables use 5024 bytes (15%) of dynamic memory, leaving 27744 bytes for local variables. Maximum is 32768 bytes.

No, just the bookstore. I left the rest of the code the same to make sure it didn't hurt too much.

If you need help or analysis, then you need to provide the complete code, both versions, and with all include files (except the unmodified library).
-jz-

I give you the example that I was trying to do, you will see that it is very simple.
I must upload it as a code that, being new, does not let me upload files. Thanks for the help.

Robot-slave.ino

#include "Robot-emotion-images.h"

#include <Arduino_GFX_Library.h>


Arduino_DataBus *bus = new Arduino_HWSPI(16 /* DC */, 5 /* CS */);
Arduino_GFX *gfx = new Arduino_ILI9341(bus, 17 /* RST */);


void setup() {
  Serial.begin(9600);
}

void loop() {
  int16_t wid = gfx->width();
  int16_t ht = gfx->height();
  for (int instanceIndex = 0; instanceIndex < sizeof(feliz) / sizeof(feliz[0]); ++instanceIndex) {
    const uint8_t* image = feliz[instanceIndex];     
    
    gfx->drawBitmap(0, 0, image, 400, 240, BLACK);
    delay(500);
  }

  delay(10000);
}

Robot-emotion-images.h

#ifndef ROBOTEMOTIONSCONST_H
#define ROBOTEMOTIONSCONST_H
#include <Arduino.h>

#include "base.c"

#include "happy2.c"
#include "happy3.c"
#include "happy4.c"
#include "happy5.c"
#include "happy6.c"
#include "happy7.c"

const uint8_t* feliz[] = {base, happy2, happy3, happy4, happy5, happy6, happy7};



#endif

base.c


/*******************************************************************************
* generated by lcd-image-converter rev.030b30d from 2019-03-17 01:38:34 +0500
* image
* filename: happy.jpg
*
* preset name: 
* data block size: 8 bit(s), uint8_t
* RLE compression enabled: no
* conversion type: Monochrome, Diffuse Dither 128
* split to rows: yes
* bits per pixel: 24
*
* preprocess:
*  main scan direction: top_to_bottom
*  line scan direction: forward
*  inverse: no
*******************************************************************************/
#include <stdint.h>
//#include "structData.h"

static const uint8_t base[288000] = {
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
...

I had to remove the content of the array because it was too much for the web.

You have now been promoted to a higher "trust level" with the forum software, which will allow you to add files as attachments to posts.

I think this is already too much for the FLASH of an Arduino UNO R4.
Maximum is 262144 bytes

but it compiles for me without problem and indicates the message that I showed you above that if it enters.

I am complicated what I want to do with a screen and arduino!

As others have mentioned, your images will not fit as is into the flash memory of these processors.

The board has: RA4M1 256 kB Flash, 32 kB RAM

And your base.c defines a structure: static const uint8_t base[288000]
Which is larger than the flash all by itself.

And I am guessing that your other files are about the same size, as
288k*7 - 256K is pretty inline with the message you posted.

Note: your image file shows it is outputting 24 bits per pixel. Not sure if there would be any way to compress that data down enough to fit. Maybe use an external flash and/or SD Card?

Good luck

Yes, you are too complicated. Your program is too complicated, too big to compile for this processor.

Start with a simpler example, e.g. Clock or PDQgraphicstest.

I now understand what you mean by this, and where your misunderstanding stems from.

Your program is syntactically correct, and the compiler and code-generator accept it.
But the linker complains, because when the code is linked together, it doesn't fit (is doesn't "enter" as you called it).

But linking is part of the compilation chain. If it fails, the whole compilation has failed, and the code can't be uploaded to the processor!

Thank you very much to all,

Several of the things you mentioned occurred, images that were too large and problems with the library version. After solving everything I managed to paint an image on the screen.

Now I find another problem. I want to encapsulate the functionality within a class of its own. But when I pass as a parameter to the constructor of my class

*gfx = new Arduino_ILI9486(bus, A4, 1, false);

So I get very rare compilation errors, like it can't find libraries.

In file included from /home/adria/Arduino/libraries/Arduino_GFX/src/Arduino_GFX_Library.h:4:0,
                 from /home/adria/Escritorio/git/Robot-Tank/ejemplos/print_image_small/reset.h:4,
                 from /home/adria/Escritorio/git/Robot-Tank/ejemplos/print_image_small/reset.c:2:
/home/adria/Arduino/libraries/Arduino_GFX/src/Arduino_DataBus.h:248:1: error: unknown type name 'class'
 class Arduino_DataBus
 ^~~~~
/home/adria/Arduino/libraries/Arduino_GFX/src/Arduino_DataBus.h:249:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 {
 ^
In file included from /home/adria/Arduino/libraries/Arduino_GFX/src/Arduino_GFX_Library.h:6:0,
                 from /home/adria/Escritorio/git/Robot-Tank/ejemplos/print_image_small/reset.h:4,
                 from /home/adria/Escritorio/git/Robot-Tank/ejemplos/print_image_small/reset.c:2:
/home/adria/Arduino/libraries/Arduino_GFX/src/databus/Arduino_UNOPAR8.h:8:1: error: unknown type name 'class'
 class Arduino_UNOPAR8 : public Arduino_DataBus
 ^~~~~
/home/adria/Arduino/libraries/Arduino_GFX/src/databus/Arduino_UNOPAR8.h:8:23: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
 class Arduino_UNOPAR8 : public Arduino_DataBus
                       ^
In file included from /home/adria/.arduino15/packages/arduino/hardware/renesas_uno/1.0.4/cores/arduino/api/Print.h:25:0,
                 from /home/adria/.arduino15/packages/arduino/hardware/renesas_uno/1.0.4/cores/arduino/api/Stream.h:25,
                 from /home/adria/.arduino15/packages/arduino/hardware/renesas_uno/1.0.4/cores/arduino/api/HardwareSPI.h:23,
                 from /home/adria/.arduino15/packages/arduino/hardware/renesas_uno/1.0.4/libraries/SPI/SPI.h:22,
                 from /home/adria/Arduino/libraries/Arduino_GFX/src/databus/Arduino_HWSPI.h:8,
                 from /home/adria/Arduino/libraries/Arduino_GFX/src/Arduino_GFX_Library.h:27,
                 from /home/adria/Escritorio/git/Robot-Tank/ejemplos/print_image_small/reset.h:4,
                 from /home/adria/Escritorio/git/Robot-Tank/ejemplos/print_image_small/reset.c:2:
/home/adria/.arduino15/packages/arduino/hardware/renesas_uno/1.0.4/cores/arduino/api/Printable.h:23:1: error: unknown type name 'namespace'
 namespace arduino {
 ^~~~~~~~~
/home/adria/.arduino15/packages/arduino/hardware/renesas_uno/1.0.4/cores/arduino/api/Printable.h:23:19: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 namespace arduino {
                   ^
In file included from /home/adria/.arduino15/packages/arduino/hardware/renesas_uno/1.0.4/cores/arduino/api/Stream.h:25:0,
                 from /home/adria/.arduino15/packages/arduino/hardware/renesas_uno/1.0.4/cores/arduino/api/HardwareSPI.h:23,
                 from /home/adria/.arduino15/packages/arduino/hardware/renesas_uno/1.0.4/libraries/SPI/SPI.h:22,
                 from /home/adria/Arduino/libraries/Arduino_GFX/src/databus/Arduino_HWSPI.h:8,
                 from /home/adria/Arduino/libraries/Arduino_GFX/src/Arduino_GFX_Library.h:27,
                 from /home/adria/Escritorio/git/Robot-Tank/ejemplos/print_image_small/reset.h:4,
                 from /home/adria/Escritorio/git/Robot-Tank/ejemplos/print_image_small/reset.c:2:
/home/adria/.arduino15/packages/arduino/hardware/renesas_uno/1.0.4/cores/arduino/api/Print.h:32:1: error: unknown type name 'namespace'
 namespace arduino {
 ^~~~~~~~~
/home/adria/.arduino15/packages/arduino/hardware/renesas_uno/1.0.4/cores/arduino/api/Print.h:32:19: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 namespace arduino {
                   ^
/home/adria/.arduino15/packages/arduino/hardware/renesas_uno/1.0.4/cores/arduino/api/Print.h:96:1: error: unknown type name 'using'; did you mean 'isinf'?
 using arduino::Print;
 ^~~~~
 isinf
/home/adria/.arduino15/packages/arduino/hardware/renesas_uno/1.0.4/cores/arduino/api/Print.h:96:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
 using arduino::Print;
              ^
In file included from /home/adria/.arduino15/packages/arduino/hardware/renesas_uno/1.0.4/cores/arduino/api/HardwareSPI.h:23:0,
                 from /home/adria/.arduino15/packages/arduino/hardware/renesas_uno/1.0.4/libraries/SPI/SPI.h:22,
                 from /home/adria/Arduino/libraries/Arduino_GFX/src/databus/Arduino_HWSPI.h:8,
                 from /home/adria/Arduino/libraries/Arduino_GFX/src/Arduino_GFX_Library.h:27,
                 from /home/adria/Escritorio/git/Robot-Tank/ejemplos/print_image_small/reset.h:4,
                 from /home/adria/Escritorio/git/Robot-Tank/ejemplos/print_image_small/reset.c:2:
/home/adria/.arduino15/packages/arduino/hardware/renesas_uno/1.0.4/cores/arduino/api/Stream.h:37:1: error: unknown type name 'namespace'
 namespace arduino {
 ^~~~~~~~~
/home/adria/.arduino15/packages/arduino/hardware/renesas_uno/1.0.4/cores/arduino/api/Stream.h:37:19: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 namespace arduino {
                   ^
In file included from /home/adria/.arduino15/packages/arduino/hardware/renesas_uno/1.0.4/cores/arduino/api/HardwareSPI.h:23:0,
                 from /home/adria/.arduino15/packages/arduino/hardware/renesas_uno/1.0.4/libraries/SPI/SPI.h:22,
                 from /home/adria/Arduino/libraries/Arduino_GFX/src/databus/Arduino_HWSPI.h:8,
                 from /home/adria/Arduino/libraries/Arduino_GFX/src/Arduino_GFX_Library.h:27,
                 from /home/adria/Escritorio/git/Robot-Tank/ejemplos/print_image_small/reset.h:4,
                 from /home/adria/Escritorio/git/Robot-Tank/ejemplos/print_image_small/reset.c:2:
/home/adria/.arduino15/packages/arduino/hardware/renesas_uno/1.0.4/cores/arduino/api/Stream.h:133:1: error: unknown type name 'using'; did you mean 'isinf'?
 using arduino::Stream;
 ^~~~~
 isinf
/home/adria/.arduino15/packages/arduino/hardware/renesas_uno/1.0.4/cores/arduino/api/Stream.h:133:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
 using arduino::Stream;
              ^
In file included from /home/adria/.arduino15/packages/arduino/hardware/renesas_uno/1.0.4/libraries/SPI/SPI.h:22:0,
                 from /home/adria/Arduino/libraries/Arduino_GFX/src/databus/Arduino_HWSPI.h:8,
                 from /home/adria/Arduino/libraries/Arduino_GFX/src/Arduino_GFX_Library.h:27,
                 from /home/adria/Escritorio/git/Robot-Tank/ejemplos/print_image_small/reset.h:4,
                 from /home/adria/Escritorio/git/Robot-Tank/ejemplos/print_image_small/reset.c:2:
/home/adria/.arduino15/packages/arduino/hardware/renesas_uno/1.0.4/cores/arduino/api/HardwareSPI.h:27:1: error: unknown type name 'namespace'
 namespace arduino {
 ^~~~~~~~~
/home/adria/.arduino15/packages/arduino/hardware/renesas_uno/1.0.4/cores/arduino/api/HardwareSPI.h:27:19: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 namespace arduino {
                   ^
In file included from /home/adria/Arduino/libraries/Arduino_GFX/src/databus/Arduino_HWSPI.h:8:0,
                 from /home/adria/Arduino/libraries/Arduino_GFX/src/Arduino_GFX_Library.h:27,
                 from /home/adria/Escritorio/git/Robot-Tank/ejemplos/print_image_small/reset.h:4,
                 from /home/adria/Escritorio/git/Robot-Tank/ejemplos/print_image_small/reset.c:2:
/home/adria/.arduino15/packages/arduino/hardware/renesas_uno/1.0.4/libraries/SPI/SPI.h:30:10: fatal error: tuple: No such file or directory
 #include <tuple>
          ^~~~~~~
compilation terminated.

My class is like this right now after several attempts, but I don't understand why this error appears.

#include "reset.h"



ResetGfx::ResetGfx(){  
  Arduino_DataBus *bus = new Arduino_UNOPAR8;
  *gfx = new Arduino_ILI9486(bus, A4, 1, false);
}

bool ResetGfx::begin(){
   if (!gfx->begin()){
    return false;
  }
  screen_w = gfx->width();
  screen_h = gfx->height();

  gfx->fillScreen(BLACK);
  return true;
}

void ResetGfx::reset(){
  resetEntreOjos(screen_w, screen_h);
}




void resetEntreOjos(int16_t screen_w, int16_t screen_h){
  int16_t space = (screen_w - width_image_result)/2;
  int16_t ocupado = (space + width_image)*2;
  int16_t w = screen_w - ocupado;
  int16_t x = space + width_image;
  int16_t h = height_image;
  int16_t y = (screen_h - height_image_result)/2;
/*
  Serial.print("space: ");
  Serial.println(space);
  Serial.print("ocupado: ");
  Serial.println(ocupado);
  Serial.print("w: ");
  Serial.println(w);
  Serial.print("h: ");
  Serial.println(h);
  Serial.print("x: ");
  Serial.println(x);
  Serial.print("y: ");
  Serial.println(y);
  */
  //gfx->fillRect(x, y, w, h, WHITE);
}

reset.h

#ifndef ResetGfx_h
#define ResetGfx_h

#include <Arduino_GFX_Library.h>

int width_image_result = 400;
int height_image_result = 240;

int width_image = 154;
int height_image = 154;

//extern Arduino_GFX *gfx;


class ResetGfx {  

  public:
    ResetGfx();
    bool begin();
    void reset();

  protected:
    int16_t screen_w;
    int16_t screen_h;
    Arduino_GFX *gfx;

  private:

};

#endif

any ideas?

I have solved c++ problems that I was not doing well. I update how the files are, if you can help me see why I can't use the library from my own class.
print_image_small.ino (773 Bytes)
reset.cpp (988 Bytes)
reset.h (487 Bytes)