Data sometimes lost when sending to ST7789V TFT-display with Adafruit_ST7789.h lib - Why?

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
adaloop
 
Posts: 25
Joined: Wed Feb 01, 2023 7:46 am

Data sometimes lost when sending to ST7789V TFT-display with Adafruit_ST7789.h lib - Why?

Post by adaloop »

Hi, Im making my first Arduino project. It should show a song-number on a TFT display when I turn a knob on my MIDI-device.
First I had issues that using the MIDI class and TFT class from Adafruit then the system was freezing/crashing if I turned the knob too fast!

Then I changed my code to basic serial class instead of midi class and build my own simple midi interpretor. It works fine now without crash. But then another problem occured that some data (song changes / ProgramChanges) now gets lost sometimes on its writing to the TFT display using the Adafruit library.

On the positive side I have verified that:
  • The MIDI-device are working
  • The MIDI-cables are working
  • The MIDI-data ARE coming into the program, as I can pass it on to the MIDI-out and receive it on a third external MIDI-device
  • The MIDI-shield are also working, as I have teste forward of the data both on the THU and the OUT port.
On the negative side:
  • Some ProgramChange MIDI data values are not shown / jumped over / forgotten on its way to the TFT-display, even the same data can easily be printed or send elsewhere without problems.
  • The RX LED on the Mega 2560 board are also not blinking when the data loss are happening
Note that, like when it with the MIDI lib was freezing when turning the knob too fast, now with Serial lib its instead loosing data, when the knob is turned too fast.

I have even optimized the writing to the TFT-display, so it only updates the small text area instead of the whole screen.

SIMPLIFIED CODE:

Code: Select all

/////////////////////////////////////////////////////////////////////////////////////
#include <Adafruit_ST7789.h>  // Hardware-specific library for ST7789
#include <SPI.h>              // Arduino SPI library (funny enough the code works without this sentence! Its included 4 levels down in the Adafruit hierarchy)

/////////////////////////////////////////////////////////////////////////////////////
// TFT SPI 2" ST-7789V 320x240px DISPLAY
/////////////////////////////////////////////////////////////////////////////////////

// ST7789 TFT module connections
#define TFT_CS 53  // changed from 10 as its a Mega  // define chip select pin
#define TFT_DC 9   // define data/command pin (special for the ST-7789V ?)
#define TFT_RST 8  // define reset pin, or set to -1 and connect to Arduino RESET pin

// Initialize an instance of the Adafruit ST7789 TFT library
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

bool firstTime = true;

/////////////////////////////////////////////////////////////////////////////////////
// MIDI INPUT FOR PROGRAM CHANGE
/////////////////////////////////////////////////////////////////////////////////////

const int MIDI_BaudRate = 31250;
byte MIDI_Byte1 = 0;
byte MIDI_Byte2 = 0;
const byte SERIAL_ProgramChange = 192; //~C0 i HEX

/////////////////////////////////////////////////////////////////////////////////////
// SETUP()
/////////////////////////////////////////////////////////////////////////////////////
void setup(void) {
  
  //MIDI
  Serial1.begin(MIDI_BaudRate); 

  //TFT
  tft.init(240, 320, SPI_MODE0);  
  tft.setRotation(1); 
  tft.fillScreen(ST77XX_RED);
  tft.setCursor(10, 10);
  tft.setTextSize(5);
  tft.print("READY");

} //setup()


/////////////////////////////////////////////////////////////////////////////////////
// LOOP()
/////////////////////////////////////////////////////////////////////////////////////
void loop() {

    //READ 1. MIDI BYTE
    MIDI_Byte1 = Serial1.read();
    if (MIDI_Byte1 == SERIAL_ProgramChange) {
      
      //READ 2. MIDI value "SONG"
      MIDI_Byte2 = Serial1.read();
      
      if (firstTime) {
        tft.fillScreen(ST77XX_RED);
        tft.setCursor(10, 10);
        tft.setTextSize(3); 
        tft.print("SONG: ");
        firstTime = false;
      }
      tft.fillRect(10+108, 10, 320-10-108, 23, ST77XX_RED); //Optimization of time for clearing the screen, now oinly behind the song number
      tft.setCursor(10+108, 10);
      //SHOW 2. MIDI value on TFT-display
      tft.println(MIDI_Byte2+1);
    }
}
QUESTIONS:
  • Is there a setting / property / callback event / buffer / check / wait / timer / baud rate / interrupt I need to comply?
  • Is the TFT display not the best? Are there some better/faster/more reliable displays with same size? 2" 320x240px around 52x36mm (visual display) 62x37mm (the PCB). (It could also be lower in the height. The important thing is that its wide, but max 62mm PCB in width)
  • Has it something to do with the extra DC pin9 which the ST7789V model has? What is it used for? And how is proper use?
ALSO NOTE that:
  • I use Arduino Mega 2560
  • I also have incoming MIDI BPM tempo sync ticks which I also need to interpret
  • I need to write to 11 displays totally in the final project
Thanx in advance

User avatar
adaloop
 
Posts: 25
Joined: Wed Feb 01, 2023 7:46 am

Re: Data sometimes lost when sending to ST7789V TFT-display with Adafruit_ST7789.h lib - Why?

Post by adaloop »

Does anyone have experience with one of these 2 Adafruit displays: https://www.adafruit.com/product/5394 and https://www.adafruit.com/product/398 ?

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Data sometimes lost when sending to ST7789V TFT-display with Adafruit_ST7789.h lib - Why?

Post by adafruit_support_carter »

Is the Adafruit_ST7789.h library not suitable for my "Drive IC ST7789V" 2" 320x240px RGB TFT display (https://www.aliexpress.com/item/1005004237117445.html) ?
We have only tested the library with TFT's from the Adafruit shop.
Is there a setting / property / callback event / buffer / check / wait / timer / baud rate / interrupt I need to comply?
Maybe? That's a lot of varied topics intermixed together. Baud rate would apply to serial connections. Interrupts in general are a complex topic, etc.
Is the TFT display not the best? Are there some better/faster/more reliable displays with same size? 2" 320x240px around 52x36mm (visual display) 62x37mm (the PCB). (It could also be lower in the height. The important thing is that its wide, but max 62mm PCB in width)
This is up to you. There is no one display that is "best". They all have trade offs.
Has it something to do with the extra DC pin9 which the ST7789V model has? What is it used for? And how is proper use?
The DC pin is the Data/Command pin. In general, it let's the TFT know that the data being sent is either a command (like changing a TFT setting) or data (actual image data to display). You'd want to look in the datasheet for it's proper use as it can depend on various aspects of how the TFT is used.

User avatar
adaloop
 
Posts: 25
Joined: Wed Feb 01, 2023 7:46 am

Re: Data sometimes lost when sending to ST7789V TFT-display with Adafruit_ST7789.h lib - Why?

Post by adaloop »

Ok, let me rephrase...

1) What could be the most obvious reason causing loosing data sent to a TFT-display with your libs, if the datas are coming too fast after each other?

2) Would your 2 320px displays listed below also loose data or are they in combination with your Adafruit libraries 100% reliable?
a) 2" https://www.adafruit.com/product/4311
b) 1,9" https://www.adafruit.com/product/5394

3) Which of these 2 above displays of yours are the fastest?

4) What makes your "ST7789_fast" lib faster than your "ST7789" lib?

5) Does your "ST7789_fast" or "ST7789" libs support "ST7789V" IC? If not will you make it support it?

6) Are you aware of that your libs doesnt support other dimensions than 240x240 bcs your variables is not supported/used consistently downwards in all levels of the include files hierarchy? Is this something you will correct? E.g. some parts of your "fast" lib works, but other parts doesnt take care of handling correct screen sizes and orientations.

7) Can u sell your 2 mentioned displays in versions without the SD card? Link?

Thanx

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Data sometimes lost when sending to ST7789V TFT-display with Adafruit_ST7789.h lib - Why?

Post by adafruit_support_carter »

The PID 4311 and PID 5394 TFT's are both supported by their corresponding Adafruit library:
https://github.com/adafruit/Adafruit-ST7735-Library
https://learn.adafruit.com/2-0-inch-320 ... iring-test
https://learn.adafruit.com/adafruit-1-9 ... iring-test

Can you link to the library you are referring to as "ST7789_fast".

User avatar
adaloop
 
Posts: 25
Joined: Wed Feb 01, 2023 7:46 am

Re: Data sometimes lost when sending to ST7789V TFT-display with Adafruit_ST7789.h lib - Why?

Post by adaloop »

And the other questions?

User avatar
adaloop
 
Posts: 25
Joined: Wed Feb 01, 2023 7:46 am

Re: Data sometimes lost when sending to ST7789V TFT-display with Adafruit_ST7789.h lib - Why?

Post by adaloop »

8) And do u have any suggestions how to make flicker-free fast text updates on a screen?
Any Adafruit display, routines or technique you can recommend for this?
Thanx

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Data sometimes lost when sending to ST7789V TFT-display with Adafruit_ST7789.h lib - Why?

Post by adafruit_support_carter »

There is no general generic answer for this. Maybe increasing the SPI bus clock speed might help? If someone has written a library that does things differently to make it "fast", then could maybe use that library? Other details involve how the TFT updates are being interleaved with non-TFT code (like MIDI) and are application dependent.

User avatar
adaloop
 
Posts: 25
Joined: Wed Feb 01, 2023 7:46 am

Re: Data sometimes lost when sending to ST7789V TFT-display with Adafruit_ST7789.h lib - Why?

Post by adaloop »

Can I affect how the TFTs updates? E.g. waiting for its ready or finish writing or using flush() or call it in beginning or end of loop() or do ANYTHING to prevent the data losses?

or can I read TFTs updating frequence somehow?

User avatar
adaloop
 
Posts: 25
Joined: Wed Feb 01, 2023 7:46 am

Re: Data sometimes lost when sending to ST7789V TFT-display with Adafruit_ST7789.h lib - Why?

Post by adaloop »

I have now bought several of this display: https://learn.adafruit.com/adafruit-1-9 ... iring-test
What should I do (hardware-pin & software-wise) in order to send different data to different displays?

I need 10 displays in total to be connected and adressed with different data.
PS: I have Mega 2560.

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Data sometimes lost when sending to ST7789V TFT-display with Adafruit_ST7789.h lib - Why?

Post by adafruit_support_carter »

MOSI/MISO/SCLK pins are shared between displays.

Each display needs it's own separate CS pin.

Then create a new instances for each display, passing in the specific CS pin for each.

User avatar
adaloop
 
Posts: 25
Joined: Wed Feb 01, 2023 7:46 am

Re: Data sometimes lost when sending to ST7789V TFT-display with Adafruit_ST7789.h lib - Why?

Post by adaloop »

Did u see my post and questions of 1. feb?
This issue I also need to have solved/solutions for with the new Adafruit displays.

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Data sometimes lost when sending to ST7789V TFT-display with Adafruit_ST7789.h lib - Why?

Post by adafruit_support_carter »

Please restate the question(s). A lot of them appear to be related to a non-Adafruit library called "ST7789_fast".

User avatar
adaloop
 
Posts: 25
Joined: Wed Feb 01, 2023 7:46 am

Re: Data sometimes lost when sending to ST7789V TFT-display with Adafruit_ST7789.h lib - Why?

Post by adaloop »

Sorry it was from 3rd feb:
I repeat here:
Can I affect how the TFTs updates? E.g. waiting for its readyness or finishes writing or using flush() or call it in beginning or end of loop() or do ANYTHING to prevent the data loss from MIDI in to TFT out?

or can I read TFTs updating frequence somehow?

Is there a certain recommended programming tactic for Arduino Mega 2560 to avoid data loss from serial port in (MIDI in) interpretted in the code and send out as text, screenfills & lines to TFT's?
Last edited by adaloop on Thu Mar 02, 2023 4:16 pm, edited 4 times in total.

User avatar
adaloop
 
Posts: 25
Joined: Wed Feb 01, 2023 7:46 am

Re: Data sometimes lost when sending to ST7789V TFT-display with Adafruit_ST7789.h lib - Why?

Post by adaloop »

There is a mismatch in your guidance link about the pins and the actual text on the TFTs pcb!
In your guide u write use "3-5v Vin" OR "V+"
But on your pcb there is no such labels, only "Vin" and "3V", so theres a conflicting disturbance there. So what is what? What should be connected to what?
Last edited by adaloop on Thu Mar 02, 2023 4:18 pm, edited 1 time in total.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”