GIGA Display Shield interference with analog functionalities

Hello All,

I want to display the values read from analog ports on the original GIGA display shield, but it seems that the display is interfering with the analogRead() function, and the display flickers. I also tried to use Arduino_advancedAnalog library, but it would not compile. The error is related to the pins description. I took a look at the schematics but could not spot any shared pin between the display and analog ports. My code is as follows:

#include "Arduino_H7_Video.h"
#include "Arduino_GigaDisplayTouch.h"

#include "lvgl.h"


Arduino_H7_Video          Display(800, 480, GigaDisplayShield); /* Arduino_H7_Video Display(1024, 768, USBCVideo); */
Arduino_GigaDisplayTouch  TouchDetector;

char buffer[20];

static void set_slider_val(void * bar, int32_t val) {
  lv_bar_set_value((lv_obj_t *)bar, val, LV_ANIM_ON);
}

void setup() {
  Display.begin();
  TouchDetector.begin();
}

void loop() {
  
    lv_obj_t * screen = lv_obj_create(lv_scr_act());
    lv_obj_set_size(screen, Display.width(), Display.height());

    static lv_coord_t col_dsc[] = { 500, LV_GRID_TEMPLATE_LAST};
    static lv_coord_t row_dsc[] = { 400, LV_GRID_TEMPLATE_LAST};

    lv_obj_t * grid = lv_obj_create(lv_scr_act());

    lv_obj_set_grid_dsc_array(grid, col_dsc, row_dsc);

    lv_obj_set_size(grid, Display.width(), Display.height());

    lv_obj_center(grid);

    lv_obj_t * label;
    lv_obj_t * obj;

    obj = lv_obj_create(grid);
    lv_obj_set_grid_cell(obj, LV_GRID_ALIGN_STRETCH, 0, 1,
                          LV_GRID_ALIGN_STRETCH, 0, 1);
    lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN);

    lv_obj_t * bar = lv_bar_create(obj);
    lv_obj_set_size(bar, 200, 20);
    lv_obj_center(bar);
    lv_bar_set_value(bar, 70, LV_ANIM_OFF);

    label = lv_label_create(obj);
    lv_label_set_text(label, "Hello World!");
    lv_obj_align_to(label, bar, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
  
  int i=0;
  while(1){
    i++;
    delay(100);
    lv_bar_set_value(bar, i, LV_ANIM_OFF);
    sprintf(buffer, "%d", analogRead(2));
    lv_label_set_text(label, buffer);

    if(i==100)
    i=0;
    lv_timer_handler();
  }
}

Same behavior seen. I ran the arduino logo display example, and added analog read every 100ms. Every analog read makes the display flicker.

Hi @rmnrmnd,
The problem is in the lv_timer_handler(). You should call this function about every 5 ms as mentioned in the LVGL documentation.
Also, you shouldn't use delay(100) but a non-blocking method to delay (See this example).
The problem could be remained in the analogRead() function that takes more then 5ms to execute. Try to use Arduino_AdvancedAnalog library.

Same problem here! I've tried many things none of them work so far.
1)Tried running analogRead() with delay(10) after lv_timer_handler() and the screen glitches.
2) Tried instead of analogRead to use advancedAnalog lib, couldnt use it because it had same declaration for a function with ArduinoGigaDisplayShield.h.
3)Tried analogRead from the co-processor and RPC to the main processor but had the same glitching (i cant explain this behaviour at all)
4) Tried advancedAnalog lib in the coproccessor but doesnt seem to work, seems you can only use this library in the main processor.
I am attaching the code for the 2 programs (for case 3):
M7 program:

#include <Arduino_H7_Video.h>
#include <Arduino_GigaDisplayTouch.h>
#include <RPC.h>


#include <lvgl.h>
#include <ui.h>


// AdvancedADC adc1(A0);
// AdvancedADC adc2(A1);

/* Insert resolution WxH according to your SquareLine studio project settings */
Arduino_H7_Video          Display(800, 480, GigaDisplayShield); 
Arduino_GigaDisplayTouch  Touch;
// holds the mode of the Endopillow 
String mode;
String prevMode;
// different vars for every parameter, arrays for the charts
int frequency,pulse,pressure,peak,peep,support;
int chart1[100];
int chart2[100];
int chart3[100];

void setup() {
  Serial.begin(115200);
  RPC.begin();
  randomSeed(analogRead(A5));
  Display.begin();
  Touch.begin();
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);

  mode = "None";
  prevMode = mode;
  // initialize charts
  for(int i=0; i<100; i++){
    chart1[i] = 0;
    chart2[i] = 0;
    chart3[i] = 0;
  }
  ui_init();
  
  // lv_chart_init_points(ui_Curve1, ser, value);
  // lv_chart_init_points(ui_Curve2, ser, value);
  // lv_chart_init_points(ui_Curve3, ser, value);

  lv_obj_add_event_cb(ui_modeJet, jetEvent, LV_EVENT_CLICKED, NULL); 
  lv_obj_add_event_cb(ui_modeTurbine, turbEvent, LV_EVENT_CLICKED, NULL); 
  lv_obj_add_event_cb(ui_modeJetAndTurbine, jetAndTurbEvent, LV_EVENT_CLICKED, NULL); 
}

void jetEvent(lv_event_t *event){
  mode = "jet";
  lv_label_set_text_fmt(ui_Setting1Title,"Frequency");
  lv_label_set_text_fmt(ui_Setting2Title,"Pulse %");
  lv_label_set_text_fmt(ui_Setting3Title,"Pressure");

}
void turbEvent(lv_event_t *event){
  mode = "turb";
   lv_label_set_text_fmt(ui_Setting1Title,"Frequency");
  lv_label_set_text_fmt(ui_Setting2Title,"Peep");
  lv_label_set_text_fmt(ui_Setting3Title,"Peak");


}
void jetAndTurbEvent(lv_event_t *event){
  mode = "jetAndTurb";
   lv_label_set_text_fmt(ui_Setting1Title,"Frequency");
  lv_label_set_text_fmt(ui_Setting2Title,"Pulse");
  lv_label_set_text_fmt(ui_Setting3Title,"Support %");
}


int val1,val2,val3;
// int pot1,pot2,pot3;
// int timer_c = 0;
// int offs = 400;
void loop() {

  val1 = lv_slider_get_value(ui_Slider1);
  lv_label_set_text_fmt(ui_Slider1val,"%d",val1);

  val2 = lv_slider_get_value(ui_Slider2);
  lv_label_set_text_fmt(ui_Slider2val,"%d", val2);

  val3 = lv_slider_get_value(ui_Slider3);
  lv_label_set_text_fmt(ui_Slider3val,"%d", val3);

  if(mode != prevMode){
    lv_slider_set_value(ui_Slider1,75,LV_ANIM_OFF);
    lv_slider_set_value(ui_Slider2,75,LV_ANIM_OFF);
    lv_slider_set_value(ui_Slider3,75,LV_ANIM_OFF);
  }

  if(mode == "turb"){
    frequency = val1;
    peep = val2;
    peak = val3;
  }else if(mode == "jet"){
    frequency = val1;
    pulse = val2;
    pressure = val3;
  }else if(mode=="jetAndTurb"){
    frequency = val1;
    pulse = val2;
    support = val3;
  }


  analogWrite(5,val1);
  analogWrite(6,val2);
  analogWrite(7,val3);

    String buffer = "";

    while (RPC.available()) {
      buffer += (char)RPC.read();
    }

    if (buffer.length() > 0) {
      Serial.println(buffer);
    }

  prevMode = mode; 
  lv_timer_handler();

  delay(10);
}

M4 program:

#include <RPC.h>

void setup() {
  RPC.begin();
  pinMode(A0,INPUT);
  digitalWrite(13,HIGH);

}
void loop(){
  int pot1 = analogRead(A0);
  RPC.println(pot1);
  delay(30);
}

I am using Arduino Giga, Arduino Giga Shield, 4 LEDs and 3 potentiometers in A0,A1,A2.
For the graphics I've used Squareline.
I dont know if I'm burnt out or what but I cannot understand what analogRead in the coprocessor has to do with displaying graphics.
Thanks in advance!

Hi @kyriakstrat,
Please could you clarify this point? What error did you encounter?

In file included from c:\Arduino sketches\libraries\Arduino_GigaDisplayTouch\src/Arduino_GigaDisplayTouch.h:35:0,
from C:\Arduino sketches\troubleshoot_analogRead\troubleshoot_analogRead.ino:3:
C:\Users\kyriakstrat\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.0.8\cores\arduino/pinDefinitions.h:8:8: error: redefinition of 'struct _PinDescription'
struct _PinDescription
^~~~~~~~~~~~~~~
In file included from c:\Arduino sketches\libraries\Arduino_AdvancedAnalog\src/AdvancedAnalog.h:25:0,
from c:\Arduino sketches\libraries\Arduino_AdvancedAnalog\src/AdvancedADC.h:22,
from c:\Arduino sketches\libraries\Arduino_AdvancedAnalog\src/Arduino_AdvancedAnalog.h:27,
from C:\Arduino sketches\troubleshoot_analogRead\troubleshoot_analogRead.ino:1:
C:\Users\kyriakstrat\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.0.8\cores\arduino/pinDefinitions.h:8:8: note: previous definition of 'struct _PinDescription'
struct _PinDescription
^~~~~~~~~~~~~~~
In file included from c:\Arduino sketches\libraries\Arduino_GigaDisplayTouch\src/Arduino_GigaDisplayTouch.h:35:0,
from C:\Arduino sketches\troubleshoot_analogRead\troubleshoot_analogRead.ino:3:
C:\Users\kyriakstrat\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.0.8\cores\arduino/pinDefinitions.h:16:8: error: redefinition of 'struct _AnalogPinDescription'
struct _AnalogPinDescription
^~~~~~~~~~~~~~~~~~~~~
In file included from c:\Arduino sketches\libraries\Arduino_AdvancedAnalog\src/AdvancedAnalog.h:25:0,
from c:\Arduino sketches\libraries\Arduino_AdvancedAnalog\src/AdvancedADC.h:22,
from c:\Arduino sketches\libraries\Arduino_AdvancedAnalog\src/Arduino_AdvancedAnalog.h:27,
from C:\Arduino sketches\troubleshoot_analogRead\troubleshoot_analogRead.ino:1:
C:\Users\kyriakstrat\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.0.8\cores\arduino/pinDefinitions.h:16:8: note: previous definition of 'struct _AnalogPinDescription'
struct _AnalogPinDescription
^~~~~~~~~~~~~~~~~~~~~

exit status 1

Compilation error: exit status 1

CODE:

#include <Arduino_AdvancedAnalog.h>
#include <Arduino_H7_Video.h>
#include <Arduino_GigaDisplayTouch.h>
// #include <RPC.h>
// #include <ArduinoBLE.h>
#include <lvgl.h>
#include <ui.h>


/* Insert resolution WxH according to your SquareLine studio project settings */
Arduino_H7_Video          Display(800, 480, GigaDisplayShield); 
Arduino_GigaDisplayTouch  Touch;
// holds the mode of the Endopillow 
String mode;
String prevMode;
// different vars for every parameter, arrays for the charts
int frequency,pulse,pressure,peak,peep,support;
int chart1[100];
int chart2[100];
int chart3[100];


void setup() {
  Serial.begin(115200);
  Display.begin();
  Touch.begin();
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);

  mode = "None";
  prevMode = mode;
  // initialize charts
  for(int i=0; i<100; i++){
    chart1[i] = 0;
    chart2[i] = 0;
    chart3[i] = 0;
  }
  ui_init();
  
  // lv_chart_init_points(ui_Curve1, ser, value);
  // lv_chart_init_points(ui_Curve2, ser, value);
  // lv_chart_init_points(ui_Curve3, ser, value);

  lv_obj_add_event_cb(ui_modeJet, jetEvent, LV_EVENT_CLICKED, NULL); 
  lv_obj_add_event_cb(ui_modeTurbine, turbEvent, LV_EVENT_CLICKED, NULL); 
  lv_obj_add_event_cb(ui_modeJetAndTurbine, jetAndTurbEvent, LV_EVENT_CLICKED, NULL); 
}


void jetEvent(lv_event_t *event){
  mode = "jet";
  lv_label_set_text_fmt(ui_Setting1Title,"Frequency");
  lv_label_set_text_fmt(ui_Setting2Title,"Pulse %");
  lv_label_set_text_fmt(ui_Setting3Title,"Pressure");

}
void turbEvent(lv_event_t *event){
  mode = "turb";
   lv_label_set_text_fmt(ui_Setting1Title,"Frequency");
  lv_label_set_text_fmt(ui_Setting2Title,"Peep");
  lv_label_set_text_fmt(ui_Setting3Title,"Peak");


}
void jetAndTurbEvent(lv_event_t *event){
  mode = "jetAndTurb";
   lv_label_set_text_fmt(ui_Setting1Title,"Frequency");
  lv_label_set_text_fmt(ui_Setting2Title,"Pulse");
  lv_label_set_text_fmt(ui_Setting3Title,"Support %");
}


int val1,val2,val3;



void loop() {
  // put your main code here, to run repeatedly:
  val1 = lv_slider_get_value(ui_Slider1);
  lv_label_set_text_fmt(ui_Slider1val,"%d",val1);

  val2 = lv_slider_get_value(ui_Slider2);
  lv_label_set_text_fmt(ui_Slider2val,"%d", val2);

  val3 = lv_slider_get_value(ui_Slider3);
  lv_label_set_text_fmt(ui_Slider3val,"%d", val3);

  if(mode != prevMode){
    lv_slider_set_value(ui_Slider1,75,LV_ANIM_OFF);
    lv_slider_set_value(ui_Slider2,75,LV_ANIM_OFF);
    lv_slider_set_value(ui_Slider3,75,LV_ANIM_OFF);
  }
  if(mode == "turb"){
    frequency = val1;
    peep = val2;
    peak = val3;
  }else if(mode == "jet"){
    frequency = val1;
    pulse = val2;
    pressure = val3;
  }else if(mode=="jetAndTurb"){
    frequency = val1;
    pulse = val2;
    support = val3;
  }


  analogWrite(5,val1);
  analogWrite(6,val2);
  analogWrite(7,val3);

  prevMode = mode; 
  lv_timer_handler();

  delay(5);


}

Thanks for sharing error log!
Try to apply this fix on your pinDefinitions.h file and let me know if compilation issue is fixed!

This fix will be include in the next release.

If you don't know where your board core files are located, follow this guide:

2 Likes

worked!!! thank you very much!

1 Like

Can you clarify if the screen flickering issue also fixed by using the new AdvancedAnalog Lib? Or is there only fixed the compilation issue?

yes, Advanced analog works fine for me!