MCUFRIEND_kbv Library for Uno 2.4, 2.8, 3.5, 3.6, 3.95 inch mcufriend Shields

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...

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.

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.

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:

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.

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?

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

You can solve the compilation errors by making forward declarations manually. e.g.

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:

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"

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.

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.

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

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.

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:

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

to

const int XP = 6, XM = A5, YP = A6, YM = 7; //ID=0x9341

But it also doesn't work like this

Thank you!

The most common Touch pin config:

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

Your Wiring would use:

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.

Thank you,

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

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)

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:

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

And the touchscreen works like a charm!

Your output is rubbish.

Change

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:

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,

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

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.

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.

Also posted @ MCUFRIEND_kbv before I realized that this is the place.

Hi David,
I have a similar problem to How to move data pins from interrup pins 2 and 3 · Issue #9 · prenticedavid/MCUFRIEND_kbv · GitHub (How to move data pins from interrup pins 2 and 3) on a breadboarded Atmega1284P. I really need the external interrupt pins for use with several external devices. I currently have the Kuman 3.5" 320x480 ILI9486 UNO shield display hooked up according to the Bobuino pinout and it works fine --- I just need those interrupts. I've attached an image showing the current hookup for the display. Used pins are marked with a red X and open (unused) pins are marked with a green circle. The interrupt pins I want are marked with a red circle --- .D6/PB2, D2/PD2, D3/PD3.

I've looked at the special.h files and the how_to , but can't really figure out how to go about changing anything. Do you have any sort of guide for making these changes? Or any advice? Seems like you always ask for the regs, so following is the output of LCD_ID_readnew.
Thank you so much for any help! Robby R

Read Registers on MCUFRIEND UNO shield
controllers either read as single 16-bit
e.g. the ID is at readReg(0)
or as a sequence of 8-bit values
in special locations (first is dummy)

diagnose any controller
reg(0x0000) 00 00 ID: ILI9320, ILI9325, ILI9335, ...
reg(0x0004) 00 54 80 66 Manufacturer ID
reg(0x0009) 00 00 61 00 00 Status Register
reg(0x000A) 00 08 Get Powsr Mode
reg(0x000C) 00 66 Get Pixel Format
reg(0x0030) 00 00 00 00 00 PTLAR
reg(0x0033) 00 00 00 00 00 00 00 VSCRLDEF
reg(0x0061) 00 00 RDID1 HX8347-G
reg(0x0062) 00 00 RDID2 HX8347-G
reg(0x0063) 00 00 RDID3 HX8347-G
reg(0x0064) 00 00 RDID1 HX8347-A
reg(0x0065) 00 00 RDID2 HX8347-A
reg(0x0066) 00 00 RDID3 HX8347-A
reg(0x0067) 00 00 RDID Himax HX8347-A
reg(0x0070) 00 00 Panel Himax HX8347-A
reg(0x00A1) 00 93 30 93 30 RD_DDB SSD1963
reg(0x00B0) 00 00 RGB Interface Signal Control
reg(0x00B3) 00 00 11 11 11 Frame Memory
reg(0x00B4) 00 00 Frame Mode
reg(0x00B6) 00 02 02 3B 3B Display Control
reg(0x00B7) 00 06 Entry Mode Set
reg(0x00BF) 00 00 00 00 00 00 ILI9481, HX8357-B
reg(0x00C0) 00 0E 0E 0E 0E 0E 0E 0E 0E Panel Control
reg(0x00C1) 00 44 00 00 Display Timing
reg(0x00C5) 00 00 Frame Rate
reg(0x00C8) 00 00 00 00 00 00 00 00 00 00 00 00 00 GAMMA
reg(0x00CC) 00 04 Panel Control
reg(0x00D0) 00 00 00 00 Power Control
reg(0x00D1) 00 00 00 00 VCOM Control
reg(0x00D2) 00 00 00 Power Normal
reg(0x00D3) 00 00 94 86 ILI9341, ILI9488
reg(0x00D4) 00 00 00 00 Novatek
reg(0x00DA) 00 54 RDID1
reg(0x00DB) 00 80 RDID2
reg(0x00DC) 00 66 RDID3
reg(0x00E0) 00 0F 21 1C 0B 0E 08 49 98 38 09 11 03 14 10 00 GAMMA-P
reg(0x00E1) 00 0F 2F 2B 0C 0E 06 47 76 37 07 11 04 23 1E 00 GAMMA-N
reg(0x00EF) 00 80 00 10 60 40 ILI9327
reg(0x00F2) 00 18 A3 12 02 B2 12 FF 10 00 00 00 Adjust Control 2
reg(0x00F6) 00 54 80 66 Interface Control

Thanks again, RR

I've looked at the special.h files and the how_to , but can't really figure out how to go about changing anything. Do you have any sort of guide for making these changes? Or any advice?

God invented Shields. I do not want to make it "easy" to change the wiring.

First off. The ATmega1284P (and all standard Arduino boards) has got PinChange interrupts on every pin.

It is a historic feature that Arduino concentrates on the INTn pins. Elderly mega8/16/32/8535 do not have PinChange.

If you really want to move the data bus from PB2, PD2, PD3 you have to tell me which pins you want to use instead.

Seriously. It would be wise to investigate PCINT interrupts.

David.

David, Any of the open/unused pins shown in the attached image would be fine. I've looked at pin-change interrupts, but I really want to use the External Interrupts for my project.
Thanks, RR

You must tell me.
I am not going to guess.

Ok.

Atmega1284P Bobuino

I'd like to move :

D2/PD2 to PC7 (note "C")

D3/PD3 to PC6 (note "C")

Thanks David!
RR