i want to display voltage of ADC with " ssd1306 OLED " in STM32 when i change the voltage with potentiometer

28 Views Asked by At

but it only display 0. i wrote my code in Keil . can somebody explain what's wrong with the code. i've already swap some of codes places and it still doesn't work. i would appreciate if you take a look

#include "main.h" 
#include "ssd1306.h" 
#include "ssd1306_fonts.h"

#include <string.h> 
#include <math.h> 
#include <stdlib.h> 
#include <stdio.h>

/* USER CODE BEGIN PV */

unsigned int value;
float voltage = 0.0;
char f[5];
int i=0;

/* USER CODE END PV */

/* USER CODE BEGIN 2 */
  
ssd1306_Init();
    
   ssd1306_Fill(Black);
   ssd1306_SetCursor(1,10);
   ssd1306_WriteString("voltage: ",Font_11x18 ,White); 
        
/* USER CODE END 2 */

while (1) 
{
      HAL_ADC_Start(&hadc1);    
      value = HAL_ADC_GetValue(&hadc1);
    voltage = (3.3 * value / 4095);
    sprintf(f, "%f", voltage);
    ssd1306_SetCursor(40,33);
    ssd1306_WriteString(f,Font_16x26,White);
    ssd1306_UpdateScreen();
      HAL_ADC_Stop(&hadc1);
    HAL_Delay(500);
}
0

There are 0 best solutions below