Actually, this article covers several areas. As I still prefer using the handy 1.8"-TFT display, equipped with the ST7735 chip, I have to use the "TFT.h" library which unfortunately is labelled as "RETIRED". And as a matter of fact, this library does not support the (still) new ARDUINO R4. Even six months after introduction of the R4, I still could not manage to find an update or a working replacement for this library. That is why I sat down to write a library which supports both the R3 and the R4. Writing a library is nothing what you happen to do during your coffee break. I have to confess I did not write it from scratch, I found some code in a program published by Bruce E. Hall in May 2014, but this code had to be converted into a library, and AVR-related commands replaced.
My comparison is showing the same code using
- left: UNO R3 using the old library "TFT.h"
- center: UNO R3 using my new library "TFT18_R4.h"
- right: UNO R4 using my new library "TFT18_R4.h"
In order to compare the performance I ran some time-consuming program generating all magic 4x4-squares (there are 7040 of them).
Side note: you can find one of the solutions in the upper right corner of a famous copper engraving shown at this site:https://de.wikipedia.org/wiki/Datei:D%C3%BCrer_Melancholia_I.jpg
This is just one of that many solutions:
The total number of permutations of 1...16 is 16! = 20.922.789.888.000, but you can stop going any deeper as soon as one of the sums cannot reach the magic number. Each time the program finds a valid solution it updates the time stamp (left) and the solution number (right). The three devices were started pressing the RESET button at the same moment, the picture was taken after five hours and three minutes. I myself was surprised finding the results. The fastest one is the old R3 using my new library. Second is the R3 using the original (RETIRED) library. And the slowest one is the new R4 using my library.
The time stamp shown in the left corner includes the delay time used to display the current solution. You might want to subtract that time, but it affects all of the three devices in the same manner.
What could be the reason for this surprising result? Obviously, it must be the access to the hardware. Some clever people improved the "digitalWrite" function, naming it "digitalWriteFast". Replacing the standard function by the faster one did not make any difference. So the only explanation is the SPI protocol, which slows down the R4.
A short remark concerning hardware compatibility, advertised as a great advantage on store.arduino.cc. There you are told "The UNO R4 Minima maintains the same form factor, pinout, and 5 V operating voltage as its predecessor". But when you connect the TFT LCD directly to the port pins (as you used to do with the R3 without any problems) you are getting a foggy picture shown on the LCD. Either you have to use level shifters or simply insert 1 kohm resistors into these connections: pin-8-to-RESET, pin-9-to-A0, pin-13-to-SCK.
What else can you get from my code?
- recursive algorithm to solve the magic squares puzzle
- hue function to get the rainbow colors
- code to convert seconds-to-HH:MM:SS
Some remarks concerning graphics libraries:
When I search the net for graphics algorithms I find a lot of very different approaches.
- point (0, 0) top or bottom
- oder of colors RGB or GBR
- rectangles defined by two corners or by one corner an width/height
- off-by-one when working with areas
- and probably some more.
So my library ist still under construction, but you may have a try.
Comments