How to read out analog values on Arduino without the screen turning white


Hi, @kisvegabor I am trying to read an analog value from Pin A1 and display it on an external monitor. However, as soon as I have an analogRead(A1) in my code the screen turns white.

Additionally, I do not get anything on my Serial Monitor.

What MCU/Processor/Board and compiler are you using?

Aduino Portenta H7 / Arduino IDE 2.0

What LVGL version are you using?


What do you want to achieve?

Being able to get values from analogRead() without the screen turning white.

What have you tried so far?

So I tried to start the analogRead later with the help of an if statement. The display turns white as soon as I tried an analogRead once. It also does not display anything anymore after I have tried to do an analogRead. If I comment out the analogRead() the code works fine.
I also have problems when using the RS485.begin() from the ArduinoRS485 library.

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

/*You code here*/
#include "Portenta_LittleVGL.h"

static lv_obj_t *label;
static lv_obj_t *secondlabel;
int counter = 0;
int analogValue = 0;

lv_timer_t * timer;
lv_timer_t * secondtimer;

static void updateCounterTimer(lv_timer_t *timer) {
  // Print the count to the Serial monitor

  // Update the text of the label
  lv_label_set_text_fmt(label, "%d" , counter);    

  // Increase the count number

static void analogread(lv_timer_t *secondtimer) {

  analogValue = analogRead(A1);


  // Update the text of the label
  lv_label_set_text_fmt(secondlabel,"%d", analogValue);         

void setup() {  


  // Initialize Portenta's video interface

  // Setting up the label making it a child of the screen
  label = lv_label_create(lv_scr_act());
  secondlabel = lv_label_create(lv_scr_act());

  // Set the label's text
  lv_label_set_text(label , "Counter");
  lv_label_set_text(secondlabel , "Analogvalue");
  // We move it to the center of the screen and align it centered
  lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
  lv_obj_align(secondlabel, LV_ALIGN_CENTER, 0, 20);
  // Create a timer to update the counter
  timer = lv_timer_create(updateCounterTimer, 1000, NULL);
  secondtimer = lv_timer_create(analogread, 1000, NULL);

void loop() {
  // put your main code here, to run repeatedly:

The problem can be located anywhere.
Just commenting out the function analogRead does not mean analogRead makes any problem.

As far as I can see your example is a copy of some examples available on the inet.
So far I can’t see any obvious mistakes within your code.