Go Down

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

T88-34D

Yes, 

David.
Thank you for your answer!

in my project I need to use 2 comports to receive data from two different devices (1 MasDuinoMD328 and ecu car).

so I am ready to solder the shield, to transfer the pins.
could you tell me, as smarter to do in this situation?

T88-34D

Code: [Select]

//######################## replace 2,3 with 10,11 on UNO ##############################
#elif defined(USE_T88_34D) && defined(__AVR_ATmega328P__)
#define RD_PORT PORTC
#define RD_PIN  0
#define WR_PORT PORTC
#define WR_PIN  1
#define CD_PORT PORTC
#define CD_PIN  2
#define CS_PORT PORTC
#define CS_PIN  3
#define RESET_PORT PORTC
#define RESET_PIN  4

#define BMASK         0x0F              //more intuitive style for mixed Ports
#define DMASK         0xF0              //does exactly the same as previous
#define write_8(x)    { PORTB = (PORTB & ~BMASK) | ((x) & BMASK); PORTD = (PORTD & ~DMASK) | ((x) & DMASK); }
#define read_8()      ( (PINB & BMASK) | (PIND & DMASK) )
#define setWriteDir() { DDRB |=  BMASK; DDRD |=  DMASK; }
#define setReadDir()  { DDRB &= ~BMASK; DDRD &= ~DMASK; }
#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.   Add it as a SPECIAL.    (in case you have not noticed,   the only difference is BMASK and DMASK values)

David.
Hello David!
please tell me, using this code, what should I modify the circuit?
 I realized that this port transfer, began to study the code.

david_prentice

1.  Snip off the male pins for LCD_D2 and LCD_D3.
2.  solder wires from the top of the snipped pins to the top of SD_CS, SD_MOSI pins.
3.  when the shield mates with the Uno,   the LCD_D2 signal will come from digital #10 and LCD_D3 from #11

4.  your microSD is no longer usable.

5.  insert angle header pins into the empty digital #2, #3 sockets.   Connect your external RXD, TXD pins to the angle pins.
6.  insert angle pin into GND socket next to #13 for the external Software Serial GND connection.

It is wise to buy header strip from Ebay.   Both straight  and angle.  The dual-row angle strip is useful for connecting to header sockets when a shield is mounted.    Most single-row angle strip has pins that are too short.     

David.

T88-34D

1.  Snip off the male pins for LCD_D2 and LCD_D3.
2.  solder wires from the top of the snipped pins to the top of SD_CS, SD_MOSI pins.
3.  when the shield mates with the Uno,   the LCD_D2 signal will come from digital #10 and LCD_D3 from #11

4.  your microSD is no longer usable.

5.  insert angle header pins into the empty digital #2, #3 sockets.   Connect your external RXD, TXD pins to the angle pins.
6.  insert angle pin into GND socket next to #13 for the external Software Serial GND connection.

It is wise to buy header strip from Ebay.   Both straight  and angle.  The dual-row angle strip is useful for connecting to header sockets when a shield is mounted.    Most single-row angle strip has pins that are too short.     

David.
Hello David!

Thank you for your prompt response!
 I have inserted this piece of code into my program, but the modified screen does not work, and the unmodified one works without changes.
 Maybe this code should be in the library? Please explain.



#define RD_PORT PORTC
#define RD_PIN  0
#define WR_PORT PORTC
#define WR_PIN  1
#define CD_PORT PORTC
#define CD_PIN  2
#define CS_PORT PORTC
#define CS_PIN  3
#define RESET_PORT PORTC
#define RESET_PIN  4

#define BMASK         0x0F              //more intuitive style for mixed Ports
#define DMASK         0xF0              //does exactly the same as previous
#define write_8(x)    { PORTB = (PORTB & ~BMASK) | ((x) & BMASK); PORTD = (PORTD & ~DMASK) | ((x) & DMASK); }
#define read_8()      ( (PINB & BMASK) | (PIND & DMASK) )
#define setWriteDir() { DDRB |=  BMASK; DDRD |=  DMASK; }
#define setReadDir()  { DDRB &= ~BMASK; DDRD &= ~DMASK; }
#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))

#include <Adafruit_GFX.h> // Hardware-specific library
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;       // hard-wired for UNO shields anyway.
#include <SoftwareSerial.h>
#include <TouchScreen.h>

char *name = "Please Calibrate.";  //edit name of shield
const int XP=7,XM=A1,YP=A2,YM=6; //ID=0x9341
const int TS_LEFT=135,TS_RT=912,TS_TOP=105,TS_BOT=940;

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

david_prentice

Look at the instructions for using a SPECIAL in the extras/mcufriend_how_to.txt file

You need to:

1.  utilty/mcufriend_shield.h:   enable USE_SPECIAL
2.  utility/mcufiend_special.h:  add your special USE_T88_34D define.  add your special conditional block.


I have NO intention of putting every conceivable SPECIAL into the library.

The whole point of Arduino Shields is to "plug and go".   Can be used by anyone,  anywhere in the world.

If an individual wants to do something differently for herself,  she must be prepared to put her brain into gear.   e.g.  modify hardware,  modify software.

David.

T88-34D

Look at the instructions for using a SPECIAL in the extras/mcufriend_how_to.txt file

You need to:

1.  utilty/mcufriend_shield.h:   enable USE_SPECIAL
2.  utility/mcufiend_special.h:  add your special USE_T88_34D define.  add your special conditional block.


I have NO intention of putting every conceivable SPECIAL into the library.

The whole point of Arduino Shields is to "plug and go".   Can be used by anyone,  anywhere in the world.

If an individual wants to do something differently for herself,  she must be prepared to put her brain into gear.   e.g.  modify hardware,  modify software.

David.
Hello David!

Thank you for your prompt response!

Delete everything except my code in the file? In utility/mcufiend_special.h:


#define USE_T88_34D

//######################## replace 2,3 with 10,11 on UNO ##############################
#elif defined(USE_T88_34D) && defined(__AVR_ATmega328P__)
#define RD_PORT PORTC
#define RD_PIN  0
#define WR_PORT PORTC
#define WR_PIN  1
#define CD_PORT PORTC
#define CD_PIN  2
#define CS_PORT PORTC
#define CS_PIN  3
#define RESET_PORT PORTC
#define RESET_PIN  4

#define BMASK         0x0F              //more intuitive style for mixed Ports
#define DMASK         0xF0              //does exactly the same as previous
#define write_8(x)    { PORTB = (PORTB & ~BMASK) | ((x) & BMASK); PORTD = (PORTD & ~DMASK) | ((x) & DMASK); }
#define read_8()      ( (PINB & BMASK) | (PIND & DMASK) )
#define setWriteDir() { DDRB |=  BMASK; DDRD |=  DMASK; }
#define setReadDir()  { DDRB &= ~BMASK; DDRD &= ~DMASK; }
#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))


#define SSD1289_JUMPERS 2       //Uno Shield with VERY different pin-out to Mcufriend
// only define one "USE_XXX" macro at any time
//#define USE_SSD1289_SHIELD_UNO
//#define USE_SSD1289_SHIELD_MEGA
//#define USE_SSD1289_SHIELD_DUE
//#define USE_MEGA_8BIT_PROTOSHIELD
//#define USE_MEGA_8BIT_SHIELD      // 4.7sec Mega2560 Shield
//#define USE_MEGA_16BIT_SHIELD     // 2.14sec Mega2560 Shield
//#define USE_BLD_BST_MEGA32U4
//#define USE_BLD_BST_MEGA2560      // 12.23sec Uno Shield (17.38s C)
//#define USE_DUE_8BIT_PROTOSHIELD
//#define USE_DUE_16BIT_SHIELD        //RD on PA15 (D24)
//#define USE_BOBCACHELOT_TEENSY
//#define USE_FRDM_K20
//#define USE_OPENSMART_SHIELD_PINOUT //thanks Michel53
//#define USE_ELECHOUSE_DUE_16BIT_SHIELD    //Untested yet
//#define USE_MY_BLUEPILL

#if 0
#elif defined(__AVR_ATmega328P__) && defined(USE_SSD1289_SHIELD_UNO)    //on UNO
#warning using SSD1289 Shield for mega328
#define RD_PORT PORTC
#define RD_PIN  3
#define WR_PORT PORTC
#define WR_PIN  2
#define CD_PORT PORTC
#define CD_PIN  1
#define CS_PORT PORTC
#define CS_PIN  0
#define RESET_PORT PORTB
#define RESET_PIN  1   







david_prentice

I did ask you to put your brain into gear.

You don't need to be Einstein.    Just look at the conditional blocks.   It is pretty obvious where to insert an "extra" block.

I would like you to work it out for yourself.    A nice cup of tea always helps.

If you still have a problem,   ask for further help.

Yes,   I suppose you could throw all the other blocks away.   e.g. just use #if 0 #elif YOUR BLOCK #endif
Then you will buy a USE_MEGA_16BIT_SHIELD style display and you will not know how to use it.

David.

T88-34D

I did ask you to put your brain into gear.

You don't need to be Einstein.    Just look at the conditional blocks.   It is pretty obvious where to insert an "extra" block.

I would like you to work it out for yourself.    A nice cup of tea always helps.

If you still have a problem,   ask for further help.

Yes,   I suppose you could throw all the other blocks away.   e.g. just use #if 0 #elif YOUR BLOCK #endif
Then you will buy a USE_MEGA_16BIT_SHIELD style display and you will not know how to use it.

David.
Hello David!

Thank you for your prompt response!

Thank you for your help! I figured it out and I was able to transfer the ports. But there is a new problem, has stopped working com ports to receive the data

david_prentice

Please invest 10 minutes of your life.  e.g. by describing what your problem is.   what you expected.  what you got.

Post a minimal sketch that exhibits your problem.

David.

T88-34D

Please invest 10 minutes of your life.  e.g. by describing what your problem is.   what you expected.  what you got.

Post a minimal sketch that exhibits your problem.

David.
Hello David!

Thank you for your prompt response!

The problem is that this code works without problems with hardware comport.
 But with a library softseal to the reception data Rx is not working. On data transfer Tx works without problems.

You may need to make changes to the utilty/mcufriend_serial file.h?



#include <SoftwareSerial.h>


SoftwareSerial mySerial(2, 3); // RX, TX



byte a = 0;
byte b = 0;
int c = 0;
int scr = 0;
int scrm = 0;
long crc16 = 0;
unsigned int d = 0;
unsigned int i1 = 0;
long crcpac = 0;
long crcpacegt = 0;

byte incominBytesegt[22] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};



void setup(){

 
  mySerial.begin(19200);

 
 
}
 
void loop()
{

 

   byte incominBytesegt[22] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; 
  if (mySerial.available()>24) {
    a = mySerial.read();
       if (a == 19 ) {c = 1;}
     if (a == 76 && c == 1) {
     
     mySerial.readBytesUntil(19, incominBytesegt, 22);
     crc16=0; c = 0;
     
     for (d=0; d <= 19; d++ ){crc16=crc16+incominBytesegt[d]; }
     
      b = incominBytesegt[20];
      i1 = incominBytesegt[21];
      crcpacegt = b*256+i1+crc16+22;
     }
}

david_prentice

1.  Put your brain into gear.
2.  describe your hardware.  e.g. Shield mounted or not.
3.  put your code within Code Tags.   (icon at top-left)

Your sketch works with Serial but not with SoftSerial(2, 3)

If the Shield is not mounted and you do not access the TFT,   your problem has nothing to do with Shield or TFT library.

If you described what data you expect,   someone could simulate the data and test your sketch.
I would expect SoftwareSerial to "work" the same as Serial for a modest throughput.  e.g. 24 bytes @ 19200 baud.

You should always test individual components separately.   Verify they are ok.
Only then can you attempt combining code in a complex sketch/

David.

T88-34D

1.  Put your brain into gear.
2.  describe your hardware.  e.g. Shield mounted or not.
3.  put your code within Code Tags.   (icon at top-left)

Your sketch works with Serial but not with SoftSerial(2, 3)

If the Shield is not mounted and you do not access the TFT,   your problem has nothing to do with Shield or TFT library.

If you described what data you expect,   someone could simulate the data and test your sketch.
I would expect SoftwareSerial to "work" the same as Serial for a modest throughput.  e.g. 24 bytes @ 19200 baud.

You should always test individual components separately.   Verify they are ok.
Only then can you attempt combining code in a complex sketch/

David.
Hello David!

Thank you for your prompt response!

David! You're absolutely right!

 The screen had nothing to do with it!

 These are incomprehensible for me problems with the library softserial.

 My device sends a 24-byte packet of data:

13 4C 00 00 00 00 00 00 00 00 1F 00 1F 00 1F 00 1E 00 00 00 1F 00 7F 50

If I recive this package hardware —Āomport, all right, I get this package of 24 bytes.

But if I recive package softserial, it turns out the packet of 20 bytes. I don't know what the problem is...

sorry for my bad English


09 33 10 08 04 00 00 40 A0 02 3D 00 4F A0 02 01 4F 20 02 01 00 4F A0 21



rainwulf

Hi David, got an interesting one for you.

I have a bunch of those UC8230 shields from our local electronics store in australia. (Jaycar)

I managed to get the shield and LCD working, but there is a very interesting bug.

The sketch locks up if i have text rotation 1 or 3, but is ok on 0 and 2.

I nailed it down to a tft.println command, if i dont print, no lock up. if i do, it locks up.
If i print in portrait mode, no issue. If i print in landscape mode, the sketch locks up.

I am running this LCD shield with a arduino ethernet module, and this is on a MEGA2560, and using an SD card in the ethernet shield.

I have tracked it down to this code here.
When in portrait mode, this works fine.


Serial.println("BAR1");
EthernetClient client = server.available();
Serial.println("BAR2");

I see BAR1 and BAR2 in my console.

AS soon as i do this:
 tft.setRotation(1);
and then print, the ethernet lib locks up at "EthernetCLient"

I see "BAR1" but dont see BAR2.

I checked for pin conflicts, and there are no pins between the ethernet shield and the LCD shield that are common.

As soon as i unplug the LCD, the program then continues.

With no common pins.. how? honestly confused. Got any ideas?

The only difference between the entire sketch working and not working is setting rotation. If its 0 or 2, everything works fine.
Perhaps some kind of memory overflow?


Ok new data:
Ethernet.client works if i unplug the SD card. Looks like some SDcard issue. As to why rotation affects this... no idea!
I cut of the pins that go to the SD card slot on the card to see if that would help, no difference.
Sketch locks up on the following conditions:
Using SD card, LCD and Ethernet.
Rotation 1 or 3

To continue running the sketch, i either unplug the SD card or unplug the LCD, even though none of those share pins anymore.

More info.
PIN 4 is SD card CS on the ethernet shield. Its also LCD D4. So i have to find out how to use the SD card at the same time as the LCD.


And FIXED!!!

With SD and Ethernet libraries loaded, they take control of pin 4 and 10 for their respective access.
However, pin4 gets set to whatever when writing graphics data.
If it happens to bet set to 0 after writing data, it enables the SD card, and then the ethernet library goes to write data to the chip, and the SDcard goes "oh hey can i play with this shiny SPI data?" And of course, the ethernet library is waiting for a response from the ethernet chip, NOT the SD card poking its nose where it doesn't belong.


Fixed my entire code with one line after the only 4 places that write stuff to the LCD.
digitalWrite(4, 1); // disable SDcard again if graphics library has left it low.





david_prentice

I have never owned or even seen a UC8230 shield.
Are they current stock in JayCar ?

I have always assumed that obsolete TFT panels appear on the Chinese surplus market as companies stop supporting obsolete Mobile Phones.
i.e. distributors clear out spare parts e.g. replacement screens.

This is why we get weird and wonderful controllers like SSD1283 or UC8230 that come from the early 2000s.

It is also fascinating how some have "unusual features".   e.g. ST7781 does not implement scrolling properly.
e.g. UC8230 has strange BGR and READ_BGR behaviour

setRotation() configures controller registers.   It will not affect other GPIO pins.   UC8230 behaves like ILI9320.

Yes,   you will have a conflict with SD if the SD uses digital#4.   I suggest that you either re-route SD_CS on the Ethernet board or simply use the microSD on the TFT Shield.

I would be very interested to hear any "other features" of the UC8230 but I am 100% confident that setRotation() would not have any conflict with non-TFT GPIO pins.

David.

Edit.  I would expect every setRotation() call to leave LCD_D4 low.   Regardless of PORTRAIT, LANDSCAPE. ...
Yes,  you can just write pinMode(4, HIGH) to "disable" the Ethernet SD
But it is inevitable that LCD_D4 is written to the appropriate level in every write to the TFT.
The SD is "slightly immune" to random CS changes.   It needs specific SPI commands before it responds but it is MUCH safer to re-route the Ethernet SD CS pin.

rainwulf

Thanks David for your input. I have decided to split the system in 2 pieces. The mega with its ethernet and SD shield only, and then a UNO with the LCD shield onto it, and the two communicating via high speed serial.

I plan on using the uno as a "video card" taking messages via serial and then doing things on the screen in response. For example "at x1, y1, put 'menu'"

A backpack of types. So i now get to make a meta language that the two arduinos can talk to each other with. I plan on having a few "pages" on the uno that can be written to by the mega, and when the mega says "SHOW PAGE 1" the uno shows it on the LCD, while the mega keeps doing its own thing.

Same thing with touch events. The mega will send a command to draw a button then keep working, while the uno actually does all the drawing and parsing of touch events.

The beauty of this is that the uno can run the LCD so much faster. With your graphics test, the mega takes about 19 seconds. On the uno, same program takes 7.02 seconds.

I am actually super excited about this haha.

Go Up