Need help with graphing real time

Description

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

  • MCU/Processor/Board: Arduino (specify model if known)
  • Compiler: Arduino IDE

What LVGL version are you using?

  • Specify the version, for example, LVGL 8.3.6

What do you want to achieve?

  • I want to display ADC values read from a 0-10V sensor using an ADS1115 on an LVGL chart in real-time.

What have you tried so far?

  • I have successfully read the ADC values using an ADS1115 and printed them on the Serial Monitor. I need help integrating these values into an LVGL chart.

Code to reproduce

Below is a simplified version of your code with comments on where to add LVGL chart updating logic:

c

Copy

#include <Wire.h>
#include <Adafruit_ADS1X15.h>
#include "lvgl.h"

Adafruit_ADS1115 ads;
lv_obj_t * chart; // LVGL chart object
lv_chart_series_t * ser; // LVGL chart series

void setup() {
  Serial.begin(9600);
  Wire.begin(19, 20); // Initialize I2C communication on pins 19 (SDA) and 20 (SCL)
  lv_init(); // Initialize LVGL
  lv_obj_t * scr = lv_scr_act(); // Get the active screen
  chart = lv_chart_create(scr, NULL); // Create a chart
  lv_obj_set_size(chart, 200, 150); // Set the chart size
  lv_obj_align(chart, NULL, LV_ALIGN_CENTER, 0, 0); // Align the chart to the center
  ser = lv_chart_add_series(chart, LV_COLOR_RED); // Add a red series

  if (!ads.begin(0x49)) {
    Serial.println("Failed to initialize ADS1115 at address 0x49.");
    while (1); // Halt the program if initialization fails
  }
  Serial.println("ADS1115 initialized successfully.");
  ads.setGain(GAIN_TWOTHIRDS); // Set the gain
}

void loop() {
  int16_t adc0 = ads.readADC_SingleEnded(0);
  float voltage0 = adc0 * 0.000872; // Calculate voltage

  // Update chart with new value
  lv_chart_set_next(chart, ser, (lv_coord_t)(voltage0 * 1000));

  // Print ADC values and calculated voltages
  Serial.print("AIN0: "); Serial.print(adc0);
  Serial.print(" -> "); Serial.print(voltage0); Serial.println(" V");

  delay(1000); // Wait for 1 second before the next read
}