Notifications
Clear all

No-name 2.4" TFT Touchscreen and Adafruit Libraries

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

Yesterday, my 2.4" TFT touchscreen shield arrived at last! Despite the webpage claiming that it would work with the Adafruit TFTLCD and GFX libraries, it didn't!

I followed the instructions to change the flag in the Adafruit_TFTLCD.h file, breakout board to Arduino shield, to no avail.

In desperation, I tried an alternative library MCUFRIEND_kbv.h and all works as expected.


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

@pugwash

Good one... it looks like the same one I have, and much better than the LCD you previously used.

Next, you can start logging to SD storage, and a nice menu wouldn't go astray either 😉


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

@pugwash

Good one... it looks like the same one I have, and much better than the LCD you previously used.

Next, you can start logging to SD storage, and a nice menu wouldn't go astray either 😉

Yes, a vast improvement on the 20/04 LCD. My first laptop had a 320 x 240 resolution (CGA), albeit a 14" diagonal display, and weighed a ton.

I have been trying to get access to the SD reader on this unit but haven't cracked it yet, any tips??


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

@pugwash

Posted by: @pugwash

I have been trying to get access to the SD reader on this unit but haven't cracked it yet, any tips??

Sure... it has to do with your chip select pin.

Load up the Arduino SD ReadWrite sketch from the examples.

Change:

  if (!SD.begin(4)) {

To:

  if (!SD.begin()) {

I looked up the begin(...) member function and it had a default value (SD_CHIP_SELECT_PIN), so I just tried using that by removing the argument and it worked.

If you know the "SS" pin (it's 10 for me) on your display unit, then correct it, otherwise try the above 🙂


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

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

@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!


   
ReplyQuote
(@zeferby)
Member
Joined: 5 years ago
Posts: 355
 
Posted by: @pugwash

It must be there for a reason, but I would love to know "when and where" I should use it!

Maybe this ?

https://www.arduino.cc/en/Reference/Scheduler

Eric


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

@zeferby

Interesting but it doesn't seem to apply to the Mega or Uno boards and the code examples are not directly nor indirectly invoking the scheduler.h library.


   
ReplyQuote
(@zeferby)
Member
Joined: 5 years ago
Posts: 355
 

@pugwash

Ok, it is definitely intended for multi-thread usage.  The standard Arduino defines it "weakly" as an empty function that can be redefined : it is in hooks.c (C:\Users\<<username>>\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.2\cores\arduino\hooks.c)

Here's the comment :

/**
* Empty yield() hook.
*
* This function is intended to be used by library writers to build
* libraries or sketches that supports cooperative threads.
*
* Its defined as a weak symbol and it can be redefined to implement a
* real cooperative scheduler.
*/

 

So for example for ESPduino it is redefined, to allow for background WiFi/BLE management

Eric


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

@zeferby

So it is really doing nothing at all??


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

@zeferby

One thing I had noticed that Adafruit was calling the yield() function directly after the fillScreen() function, which is one of the most time consuming functions used with these TFT displays. I could quite understand using yield() in a multi-threaded program, but I am guessing when I say that this is only possible with a microprocessor and NOT with a microcontroller!!


   
ReplyQuote
(@zeferby)
Member
Joined: 5 years ago
Posts: 355
 
Posted by: @pugwash

So it is really doing nothing at all??

Yep ! In the base avr implementation from Arduino, the weak definition is :

static void __empty() {
// Empty
}
void yield(void) __attribute__ ((weak, alias("__empty")));

But keeping it called probably helps some libraries to be compatible with ESP or other multi-threaded platforms Arduino environments, because these platforms would actually need to keep some form of scheduling going on behind the scenes.

Eric


   
ReplyQuote
(@zeferby)
Member
Joined: 5 years ago
Posts: 355
 
Posted by: @pugwash

only possible with a microprocessor and NOT with a microcontroller

Well, an ESP32 has 2 cores, and usually the programmer uses one, while the other is best left to the system for ongoing communications.

Eric


   
ReplyQuote
(@zeferby)
Member
Joined: 5 years ago
Posts: 355
 

@pugwash

Also in the ESP8266 Arduino Core library version of these functions, you can see mention of their yield() being delay(0) , and delay() itself giving some CPU time to comms : https://arduino-esp8266.readthedocs.io/en/2.6.1/reference.html#timing-and-delays

Eric


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

   
ReplyQuote
Page 1 / 2