Go Down

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

david_prentice

Code: [Select]

//################################### UNO SHIELD on BOBUINO ##############################
#elif defined(__AVR_ATmega1284P__) || defined(USE_MIXIUS)
#warning regular UNO shield on USE_MIXIUS
#define RD_PORT PORTD
#define RD_PIN  6
#define WR_PORT PORTA
#define WR_PIN  1
#define CD_PORT PORTA
#define CD_PIN  0
#define CS_PORT PORTA
#define CS_PIN  2
#define RESET_PORT PORTD
#define RESET_PIN  7

#define write_8(x)    { PORTB = x; }
#define read_8()      ( PINB )
#define setWriteDir() { DDRB =  0xFF; }
#define setReadDir()  { DDRB = 0x00; }
#define write8(x)     { write_8(x); WR_STROBE; }
#define write16(x)    { uint8_t h = (x)>>8, l = x; write8(h); write8(l); }
#define READ_8(dst)   { RD_STROBE; dst = read_8(); RD_IDLE; }
#define READ_16(dst)  { uint8_t hi; READ_8(hi); READ_8(dst); dst |= (hi << 8); }

#define PIN_LOW(p, b)        (p) &= ~(1<<(b))
#define PIN_HIGH(p, b)       (p) |= (1<<(b))
#define PIN_OUTPUT(p, b)     *(&p-1) |= (1<<(b))

Untested.

David.

Mixius


david_prentice

Oops.   The conditional should be && andd not ||


Mixius

Good day! Sorry, I'm not a very good programmer, I am just starting. I am a good circuit engineer but not a programmer. Could you please help me set up my code to work with my file and my connection. I do not fully understand how your code works. Tell me where to read how to work in your library. Or tell me where I need to make changes so that I can use your code. What files do I need to do to make my display work? You can explain on any example from your library! Thank you in advance!

david_prentice

It is quite simple.    God invented Arduino Shields.   The Shield plugs into the Arduino header sockets.
The wiring is fixed.   All the pins are defined in the appropriate pins_arduino.h file e.g.
Code: [Select]

C:\Program Files (x86)\Arduino-1.8.1\hardware\arduino\avr\variants\leonardo\pins_arduino.h

If you have a MightyCore Bobuino there will be an appropriate pins_arduino.h

I provide all the necessary macros for boards with official Arduino headers in utility/mcufriend_shield.h
You plug the shield into the headers and everything works. 

If your Bobuino does not have proper headers you have to do is match each Shield pin with its "Arduino" pin.
Code: [Select]

#warning regular UNO shield on BOBUINO
#define LCD_RD  A0  //PA7
#define LCD_WR  A1  //PA6
#define LCD_RS  A2  //PA5
#define LCD_CS  A3  //PA4
#define LCD_RST A4  //PA3

#define LCD_D0 8   //PD5
#define LCD_D1 9   //PP6
#define LCD_D2 2   //PD2
#define LCD_D3 3   //PD3
#define LCD_D4 4   //PB0
#define LCD_D5 5   //PB1
#define LCD_D6 6   //PB2
#define LCD_D7 7   //PB3


If you want to invent your own custom wiring,  you must verify it first e.g. with the LCD_ID_readreg sketch.
You asked for a custom wiring in #2534
I wrote it for you.
I had assumed you had verified your wiring first.
You must add the statement block to the mcufriend_special.h and enable the appropriate USE_SPECIAL and USE_MIXIUS macros

You do not need to be Einstein to write your own SPECIAL for an AVR.
However it is extremely fiddly to write SPECIALs for random pins on an ARM.    Especially when STM32 has a weird Maple Core

David.

Mixius

We did not understand each other a little. In which file (name) I need to make the edits sent to you. Do I need to change anything in the sketch in order for my wiring to be applied?


Sorry you all wrote in the message, forgive my carelessness))))

david_prentice

You don't need to do anything.   Just wire up your shield correctly i.e. official "Bobuino".

If you want to connect wires to random pins you must VERIFY the wiring first with LCD_ID_readreg.ino.
This means defining your custom wired pins as proper Arduino pins.

There is no point in going any further until you post a "good" output from LCD_ID_readreg.ino together with the your defines.

David.

domeemasters

Hallo David,

I have a 4inch TFT Touch Shield (https://www.waveshare.com/wiki/4inch_TFT_Touch_Shield) with an ILI9486 driver. I put the shield on an Red Board from SparkFun (https://www.sparkfun.com/products/13975). Then I installed the librarys MCUFRIEND_kbv and Adafruit_GFX like it was said in "mcufriend_how_to.txt". I started the example graphictest_kbv.ino, but the touchscreen stayed white or it flashed.

Like you suggested in some other topics I run diagnose_TFT_support.ino. There i got this response.

Code: [Select]

Diagnose whether this controller is supported
There are FAQs in extras/mcufriend_how_to.txt

tft.readID() finds: ID = 0x2828

MCUFRIEND_kbv version: 2.9.8


This ID is not supported
look up ID in extras/mcufriend_how_to.txt
you may need to edit MCUFRIEND_kbv.cpp
to enable support for this ID
e.g. #define SUPPORT_8347D

New controllers appear on Ebay often
If your ID is not supported
run LCD_ID_readreg.ino from examples/
Copy-Paste the output from the Serial Terminal
to a message in Displays topic on Arduino Forum
or to Issues on GitHub

Note that OPEN-SMART boards have diff pinout
Edit the pin defines in LCD_ID_readreg to match
Edit mcufiend_shield.h for USE_SPECIAL
Edit mcufiend_special.h for USE_OPENSMART_SHIELD_PINOUT


If I get it right my ID should not be ID = 0x2828, it should be:
ILI9486   320x480   ID=0x9486



So my question is, if and how I can work around this problem.


david_prentice

Go on.   You can see from the schematic that it is a shift-register abortion from Waveshare.
They take a cheap 8080-16 Parallel display and connect it to shift registers.

This sounds like a good wheeze i.e. drive a parallel display with SPI.

In practice the shift registers slow it down.   Especially when you compare it to the same ILI9486 controller using its native SPI interface.

Look at Bodmer's libraries.   He supports some of the RPi shift-register abortions.

Oh.   It is not possible to read from the shift-register abortion.    So you can't even use a SPI read_ID program.

David.

domeemasters

So if I understand you right, I can not get a decent library working on this display?

There is a library available from waveshave (https://www.waveshare.com/wiki/File:4inch_TFT_Touch_Shield_Code.7z), but it has not so many tools and I find it complicated to work with.

david_prentice

Bodmer has excellent libraries for Expressif chips e.g. ESP8266, ESP32

Bodmer has written libraries for AVR and ARM boards.   You will have to check for yourself.

I have only ever looked at Waveshare code for an SPI HX8347.   It was crap.

I am sure that someone has written a driver for Adafruit_GFX style library.   It would be trivial.   I have no interest in these shift register displays.

David.

Mixius


Good day, David! Thank you for your work. I managed to connect my display with your help. Everything is working. Thanks again!

david_prentice

Did you use the default BOBUINO pins and wiring ?
Or did you use the custom SPECIAL wiring that I wrote for you ?

It is a very BAD idea for MightyCore to produce three different wiring schemes.
If they emphasized board names like BOBUINO or MIXUINO punters could distinguish them.

David.

Mixius

No, I did not use the standard Bobuino contacts.
Yes, I used a special wiring that you wrote for me.
The device is of my own design, it is a board for studying the work of the microcontroller, as well as for my particular tasks.

The structure includes a DS18B20 temperature sensor, a DS3231 real-time clock, a radio receiver on the RDA5807, an MPU6500 accelerometer, the display was specialized based on SED1520, and now ILI9341V is installed with your help. The MCU immediately stood at ATMEGA32L but had to switch to ATMEGA1284, there was an acute problem and lack of memory.
Now everything is OK.
 
Unfortunately, the speed of work for large-scale tasks with the display is extremely low, but enough for my device.
I can send you a scheme if you are interested to see))))

Go Up