Notifications
Clear all

No-name 2.4" TFT Touchscreen and Adafruit Libraries

21 Posts
3 Users
0 Likes
4,653 Views
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

In practice, there will only be one for() loop in the main loop().

Once the new data is displayed, it will be held in the oldData[] array, until it is required to delete the data from the screen, whereafter the new data will be written to the screen.

And so on and so on.......Ad Nauseum


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@pugwash

Posted by: @pugwash

Now when the data changes it runs down the screen like a wave!

Perhaps you have an idea of how to improve the performance of data changing on the screen?

I haven't had a chance to run an example, but in prior experience with these displays, specifically under UNO, it seems to just come down to purely processing power, and 16 MHz just isn't the greatest when you come across higher resolution displays.

Some things I can suggest to try and help are as follows:

1) Try to reduce program size to make it more efficient:
    a)    Use the F() macro where possible
    b)    Given that you set the cursor position, you should just be able to replace print() with println()
    c)    Use byte (for x) and const char* instead of int and String in your function parameter lists

2) For function execution speed, you can try the following:

inline void changeDataValue(byte x1, int y1, const char* oldString, const char* newString) {

...and:

inline void changeTitle(byte x1, byte x2, int y1, int y2, const char* oldString, const char* newString){

...respectively

Using the inline keyword can actually make the code slightly larger, but it can speed up function execution too.  Note: - the C++ standard does not guarantee that the compiler will inline the functions for you, but you're giving the compiler a hint to try.

Also, you can check if Arduino is compiling in debug or production mode, and depending on how Arduino actually passes each file (translation unit) to the compiler, you may be able to hack the file it uses to pass in compiler optimisation flags which may also help... for example -g(3) for g++, etc...

Other than that... a faster processor is in order - Remember, UNO/Mega aren't really power units!

Cheers!


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 
Posted by: @pugwash

@frogandtoad

I have another question for you! I was looking through the Adafruit example code and I discovered they were using the function yield(); quite a lot. I have seen this in Python when dealing with threads but I was wondering what its purpose is in an Arduino sketch. It must be there for a reason, but I would love to know "when and where" I should use it!

Sorry, but no, I don't know anything about this function... and reading below, I guess it no longer matters now 🙂


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@pugwash

Posted by: @pugwash

After refactoring the code I am now down to this:

No worries, I'll have a look at it.


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
Topic starter  

@frogandtoad

Changing to an inline function does nothing to speed up the data display refresh, which is almost instantaneous, even without the inline function!

I guess I have reached the maximum speed already, and I am so used to driving up to 240km/hr here that I expect the same from my Arduino 🤣 🤣 🤣 


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@pugwash

Posted by: @pugwash

Changing to an inline function does nothing to speed up the data display refresh, which is almost instantaneous, even without the inline function!

Indeed, I just tested it... and like I said, it's just a hint to the compiler, so the compiler is not guaranteed to inline it.  However, changing the 'x' to byte, strings to oldData[8][12] and newData[8][12], and function signatures to const char*, and println to print, did in fact shave off ~1ms 😛 

-- Default (no changes) --
94.78000 milliseconds
94.77600 milliseconds
94.77200 milliseconds
94.78000 milliseconds
94.77600 milliseconds
94.78000 milliseconds
94.77200 milliseconds
94.77600 milliseconds
94.78000 milliseconds
94.78000 milliseconds

-- Yield() removed --
94.78000 milliseconds
94.77600 milliseconds
94.77200 milliseconds
94.78000 milliseconds
94.77600 milliseconds
94.78000 milliseconds
94.77200 milliseconds
94.77600 milliseconds
94.78000 milliseconds
94.78000 milliseconds

-- With suggested changes and no yield() --
93.90800 milliseconds
93.90800 milliseconds
93.90000 milliseconds
93.90400 milliseconds
93.90000 milliseconds
93.90400 milliseconds
93.90800 milliseconds
93.90800 milliseconds
93.90800 milliseconds
93.90800 milliseconds


   
ReplyQuote
Page 2 / 2