Hi lvgl community,
i’m a complete beginner with LVGL lib, and i intend to plot a temperature reading data on my display using the lv_chart , I’m using esp32 board, so far , the data point seems to show temperature along the x axis but does not show in y axis continously ,
I have spent a lot of time searching solution online and i found this demo, which is using stm32
and bellow is the undesired results,
is there any help on how to plot the graph periodically?
and here is my code
static void TemperatureChart( void )
{
uint16_t idx = 0u;
// this should match with the temperature buffer length
uint16_t chart_hor_res = 260;
uint16_t chart_ver_res = lv_disp_get_ver_res(NULL) - 100;
int16_t data = 20;
lv_obj_clean( lv_scr_act() ); // Clean the screen
// Create a chart object
chart = lv_chart_create( lv_scr_act() );
// Create a label for Title text
lv_obj_t * lbl_title = lv_label_create( lv_scr_act() );
lv_label_set_text( lbl_title, "Temperature Graph");
lv_obj_set_style_text_align( lbl_title, LV_TEXT_ALIGN_CENTER, 0);
lv_obj_align( lbl_title, LV_ALIGN_TOP_MID, 0, 0 );
lv_obj_add_style( lbl_title, &style, 0 );
lv_obj_set_size( chart, (lv_disp_get_hor_res(NULL) - 100), chart_ver_res );
// TODO: XS I don't want to center it, will check later
// lv_obj_center( chart );
lv_obj_align( chart, LV_ALIGN_CENTER, LV_PCT(5), 0 );
// lv_obj_align( chart, LV_ALIGN_BOTTOM_RIGHT, 0, 0 );
// Set Chart Type to Line Chart
lv_chart_set_type( chart, LV_CHART_TYPE_LINE );
// By Default the number of points are 10, update it to chart width
lv_chart_set_point_count( chart, chart_hor_res );
// Update mode shift or circular, here shift is selected
lv_chart_set_update_mode( chart, LV_CHART_UPDATE_MODE_SHIFT );
// Specify Vertical Range
lv_chart_set_range( chart, LV_CHART_AXIS_PRIMARY_Y, 10, 60);
lv_chart_set_axis_tick(chart, LV_CHART_AXIS_PRIMARY_Y, 10, 5, 10, 2, true, 50);
temp_series = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_RED), LV_CHART_AXIS_PRIMARY_Y);
for( idx=0; idx<sizeof(temp_sensor); idx++ )
{
temp_series->y_points[idx] = (lv_coord_t)(temp_sensor);
}
lv_chart_refresh(chart); /*Required after direct set*/
}
static void TemperatureChartRefresh(void)
{
uint16_t idx = 0;
// this should match with the temperature buffer length
uint16_t chart_hor_res = 260;
for( idx=0; idx<sizeof(temp_sensor);idx++)
{
temp_series->y_points[idx] = (lv_coord_t)(temp_sensor);
}
lv_chart_refresh(chart); /*Required after direct set*/
}