Go Down

Topic: MCUFRIEND_kbv Library for Uno 2.4, 2.8, 3.5, 3.6, 3.95 inch mcufriend Shields (Read 512687 times) previous topic - next topic

smmofidi

Hi david...

you was right exactly...
touch connections was broken...

this tft lcd's made in china and Unfortunately have not enough quality...!
I remove tft's touch connection from the   red main board and wired it directly  to  pins A1,A2,D6,D6...

and touch runs Properly...


thanks a lot for your guidance david...

MIRCIS

I apologize for my English.
I have MEGA2560 shield  and UNO shield  with  3.5" TFT mcufriend lcd display.

I received ID=6814 from MCUFRIEND_kvb example LCD_ID_readreg when  I directly connect UNO TFT shield with mega 2560 shield. LCD is working OK.
Graphics test  with MCUFRIEND_kvb example graphictest_kvb is OK.
TFT LCD uno shield is functional.

  For datalogger project which reads 16 analogue inputs A0-A15 on mega2560 I need to have free inputs A0, A1,A2,A3, A4. The LCD data bus  LCD_D0- LCD_D7  remains connected to the pins 8,9,2,3,4,5,6,7 of Mega2560 just as when the shields  are directly connected .

I tried re-asign LCD pins by next steps:
- In mcufriend_shield.h I activated line  #define USE_SPECIAL
- in mcufriend_shield.h I changed pin assignment  from PORTF 0->4 to free pins of Mega 43(RD), 39(WR),38(CD),40(CS),41(RST) this way
 //################################### MEGA2560 ##############################
#elif defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)       //regular UNO shield on MEGA2560
#define RD_PORT PORTL            
#define RD_PIN  6       
#define WR_PORT PORTG
#define WR_PIN  2       
#define CD_PORT PORTD
#define CD_PIN  7       
#define CS_PORT PORTG
#define CS_PIN  1       
#define RESET_PORT PORTG
#define RESET_PIN  0     

- In mcufriend_special.h I activated line  #define USE_MEGA_8BIT_SHIELD      // 4.7sec Mega2560 Shield
Files mcufriend_shield.h and mcufriend_special.h  I saved and next copied to the Arduino\libraries\MCUFRIEND_kbv-master\utility\ folder.

What else needs to be done so that the uno shields with TFT display will works with the mega2560 shield with changed pin interconnection  PORTF A0, A1,A2,A3,A4 inputs will be substituted by free pins of Mega 43(RD), 39(WR),38(CD),40(CS),41(RST) ?
When I compile MCUFRIEND_kvb example LCD_ID_readreg I can see only white screen.

I would very kindly ask somebody for help.
Thank you in advance.

david_prentice

God invented shields.    You plug the Shield into the Mega2560 (or Due, Uno, Zero, ...)

The Mega2560 has 16 Analog pins.   5 are used by the Shield.   Which leaves you 11 Analog pins.

David.

John_SB

I'm not sure if this is the right place to ask, but I've got my 2.4" ILI9341 shield working nicely on an Uno, and have run all the examples successfully, apart from the button_list alternative in button_simple.ino. When verifying it in IDE v1.8.9 I get the following errors:

Code: [Select]
button_list:81:20: error: 'Adafruit_GFX_Button' was not declared in this scope
 bool update_button(Adafruit_GFX_Button *b, bool down)
                    ^
button_list:81:41: error: 'b' was not declared in this scope
 bool update_button(Adafruit_GFX_Button *b, bool down)
                                         ^
button_list:81:44: error: expected primary-expression before 'bool'
 bool update_button(Adafruit_GFX_Button *b, bool down)
                                            ^
button_list:94:25: error: 'Adafruit_GFX_Button' was not declared in this scope
 bool update_button_list(Adafruit_GFX_Button **pb)
                         ^
button_list:94:47: error: 'pb' was not declared in this scope
 bool update_button_list(Adafruit_GFX_Button **pb)
                                               ^
/tmp/arduino_modified_sketch_255868/button_list.ino: In function 'bool update_button(Adafruit_GFX_Button*, bool)':
button_list:81:53: error: 'bool update_button(Adafruit_GFX_Button*, bool)' redeclared as different kind of symbol
 bool update_button(Adafruit_GFX_Button *b, bool down)
                                                     ^
/tmp/arduino_modified_sketch_255868/button_list.ino:81:6: note: previous declaration 'bool update_button'
 bool update_button(Adafruit_GFX_Button *b, bool down)
      ^
/tmp/arduino_modified_sketch_255868/button_list.ino: In function 'bool update_button_list(Adafruit_GFX_Button**)':
button_list:94:49: error: 'bool update_button_list(Adafruit_GFX_Button**)' redeclared as different kind of symbol
 bool update_button_list(Adafruit_GFX_Button **pb)
                                                 ^
/tmp/arduino_modified_sketch_255868/button_list.ino:94:6: note: previous declaration 'bool update_button_list'
 bool update_button_list(Adafruit_GFX_Button **pb)
      ^
button_list:98:34: error: 'update_button' cannot be used as a function
         update_button(pb[i], down);
                                  ^
/tmp/arduino_modified_sketch_255868/button_list.ino: In function 'void loop()':
button_list:107:31: error: 'update_button_list' cannot be used as a function
     update_button_list(buttons);  //use helper function
                               ^
exit status 1
'Adafruit_GFX_Button' was not declared in this scope


Because everything else is working fine, it suggests there are bugs in the sketch. My understanding of the language is slowly improving, but I can't get my head round lines 75, 81 and 94, where the problem seems to be.

Code: [Select]

75: Adafruit_GFX_Button *buttons[] = {&on_btn, &off_btn, NULL};

81: bool update_button(Adafruit_GFX_Button *b, bool down)

94: bool update_button_list(Adafruit_GFX_Button **pb)



Can someone fix the problem, or point me to somewhere I can learn what I need to make sense of it?

david_prentice

Sure enough,   the example does not work with v1.8.9

You can solve the compilation errors by making forward declarations manually.  e.g.
Code: [Select]

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

Adafruit_GFX_Button on_btn, off_btn;
extern bool update_button(Adafruit_GFX_Button *b, bool down);
extern bool update_button_list(Adafruit_GFX_Button **pb);


When the Arduino IDE processes the INO files it detects any unknown functions and places forward declarations into the "sketch_ino.cpp" in a temporary directory.
It is this "sketch_ino.cpp" that is sent to the C++ compiler.

As a general rule,   the main sketch.ino always gets processed successfully.
If you have multiple INO files,  these get concatenated but the processing is not always perfect.

David.

Here is a successful build report for the "button_list" version:
Code: [Select]

Using library Adafruit_GFX_Library at version 1.7.2 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Adafruit_GFX_Library
Using library Mcufriend_kbv at version 2.9.8 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Mcufriend_kbv
Using library Adafruit_TouchScreen at version 1.0.4 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Adafruit_TouchScreen
Using library SPI at version 1.0 in folder: C:\Program Files (x86)\Arduino-1.8.9\hardware\arduino\avr\libraries\SPI
"C:\\Program Files (x86)\\Arduino-1.8.9\\hardware\\tools\\avr/bin/avr-size" -A "C:\\Users\\DAVIDP~1\\AppData\\Local\\Temp\\arduino_build_869752/button_simple.ino.elf"
Sketch uses 19296 bytes (59%) of program storage space. Maximum is 32256 bytes.
Global variables use 430 bytes (20%) of dynamic memory, leaving 1618 bytes for local variables. Maximum is 2048 bytes.

You can see where the temp directory where the "build" is performed.
You can inspect your files by examining your particular "temp directory"

John_SB

Thanks David. Adding the forward declarations worked. Then I thought about your comment on how concatenating multiple INO files can cause a problem, so I copied button_list on its own into a new sketch, and it worked without the forward declarations. Maybe having two sketches with a lot of the same code is what caused the confusion.

david_prentice

Putting two alternatives into one sketch folder seemed ok at the time.    It worked ok with IDE v1.8.1 or whatever was current at the time of MCUFRIEND_kbv v2.9.8 Release

Yes,   you can simply copy-paste one of the alternatives into a single INO sketch in your sketch folder..

Personally,   I think that the "library locate" is an excellent feature of the Arduino build.
But forward references should be the responsibility of the User.   i.e.  follow C++ rules

Hey-ho.   Arduino has been very successful.    It is too late to change the rules now.

Thanks for reporting the problem.    I am surprised that no one else had noticed.

David.

John_SB

I can do Arduino reasonably well, but haven't got as far as learning C++ rules yet  ;) .

I'm about to start adding a screenful of buttons to it, as it does seem to be a very useful sketch, so I wonder why no one else has spotted it.

Thanks for your help.

bluebirdsoftware

Hi david,

I am using an Atmega1284 with the MCUFRIEND 3.5" display, everything is working except the touch function. When u use the TouchScreen_Calibr_native, i get the message: "BROKEN TOUCHSCREEN" on the display.

I have tested everything on an arduino mini and everything worked (including the touch functions).

I connected all the wires as described here:


When i use the MCUfriend calibration, the display shows "Touchscreen broken" and the serial output is:




I also changed this:
Code: [Select]
const int XP = 6, XM = A2, YP = A1, YM = 7; //ID=0x9341


to
Code: [Select]
const int XP = 6, XM = A5, YP = A6, YM = 7; //ID=0x9341


But it also doesn't work like this

Thank you!

david_prentice

The most common Touch pin config:
Code: [Select]

const int XP = 6, XM = A2, YP = A1, YM = 7; //ID=0x9341

Your Wiring would use:
Code: [Select]

const int XP = 2, XM = A5, YP = A6, YM = 3; //ID=0x9341



Bobuino has an unusual pin mapping.
The Touch pin diagnosis is designed for regular Uno, Mega, ... style wiring.
You could change the loop variables to test Analog A4..A7 against Digital 0..15


David.

bluebirdsoftware

Thank you,

I managed to edit the diagnose_touchpins program but got this output, this is not correct or is it?

Code: [Select]
Making all control and bus pins INPUT_PULLUP
Typical 30k Analog pullup with corresponding pin
would read low when digital is written LOW
e.g. reads ~25 for 300R X direction
e.g. reads ~30 for 500R Y direction

Testing : (A5, D5) = 18
Testing : (A5, D6) = 17
Testing : (A5, D7) = 17
Testing : (A5, D8) = 19
Testing : (A5, D9) = 17
Testing : (A6, D5) = 30
Testing : (A6, D6) = 30
Testing : (A6, D7) = 29
Testing : (A6, D8) = 30
Testing : (A6, D9) = 28
Diagnosing as:-
YP,YM:  (A5, D5) = 18
XM,XP:  (A5, D6) = 17
done



I updated the code because the Atmega1284 has 8 analog pins and 31 digital pins, but maybe i am doing something wrong here, i don't know what the function is from the last loop (between 5 an 10)

Code: [Select]

for (i = A0; i < A7; i++) pinMode(i, INPUT_PULLUP);
    for (i = 2; i < 31; i++) pinMode(i, INPUT_PULLUP);
    for (i = A0; i < A7; i++) {
        for (j = 5; j < 10; j++) {




edit:

Many thanks!

I updated the code to this:
Code: [Select]

const int XP = 2, XM = A5, YP = A6, YM = 3; //ID=0x9341


And the touchscreen works like a charm!

david_prentice

Your output is rubbish.

Change
Code: [Select]

for (i = A0; i < A7; i++) pinMode(i, INPUT_PULLUP);
    for (i = 2; i < 31; i++) pinMode(i, INPUT_PULLUP);
    for (i = A0; i < A7; i++) {
        for (j = 5; j < 10; j++) {

to:
Code: [Select]

for (i = A0; i < A7; i++) pinMode(i, INPUT_PULLUP);
    for (i = 0; i < 16; i++) pinMode(i, INPUT_PULLUP);
    for (i = A0; i < A7; i++) {
        for (j = 0; j < 16; j++) {


See if it diagnoses
YP,YM:  (A6, D3) = 30
XM,XP:  (A5, D2) = 25

I suspect that you might just force the Touch pins.    Possibly swapping X, Y if the directions are wrong.

David,

bluebirdsoftware

Thanks, i edited after your reply and it worked, i now have a working touchscreen, thank you

John_SB

Has anyone managed to get the 2.4" touchscreen shield working on an Uno with an nRF24L01 2.4GHz transceiver? I've almost managed it, but it wasn't working properly. I don't want to spend any more time trying to make it work, as I have other things to do, but if someone has an answer I'll go back to this project. With only pins 0, 1 and A5 free, CS on A5 and CE on 0 was the only option I got to work at all. I'd like to use it with the SD socket, so don't want to remove the physical connections to it if it can be avoided, but might do so if I was certain the nRF24L01 would definitely work.

david_prentice

Please post a link to your actual Arduino "Uno with an nRF24L01 2.4GHz transceiver"

I doubt if you have enough pins.    But if you provide the info,   I can give you a proper answer.

David.

Go Up