STM32-Load-Cell-Amplifier-HX711-main.c

by Marwen Maghrebi
/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "hx711.h"
#include <stdio.h>
#include <string.h>

/* Private variables ---------------------------------------------------------*/
TIM_HandleTypeDef htim1;

UART_HandleTypeDef huart1;

/* USER CODE BEGIN PV */
hx711_t loadcell;
float weight;
char MSG[50];
char MSG1[] = "HX711 scale demo \n\r";
char MSG2[] = "Reset scale to 0 assuming no weight at startup.\n\r";

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_TIM1_Init(void);
static void MX_USART1_UART_Init(void);



int main(void)
{

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
  /* Configure the system clock */
  SystemClock_Config();
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_TIM1_Init();
  MX_USART1_UART_Init();
  /* USER CODE BEGIN 2 */
  HAL_UART_Transmit(&huart1, (uint8_t*)MSG1, strlen(MSG1), 100);
  HAL_UART_Transmit(&huart1, (uint8_t*)MSG2, strlen(MSG2), 100);

  hx711_init(&loadcell, GPIOA, GPIO_PIN_1, GPIOA, GPIO_PIN_2);
  hx711_coef_set(&loadcell, 36057.14); // read afer calibration  36057.14
  hx711_tare(&loadcell, 10);
  /* USER CODE END 2 */

  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
    /* USER CODE BEGIN 3 */
    HAL_Delay(500);
    weight = hx711_weight(&loadcell, 10);
    HAL_Delay(10);
    sprintf(MSG,"\n\rhx711_weight = %.2f Kg\n\r",weight);
    HAL_UART_Transmit(&huart1,(uint8_t*)MSG, strlen(MSG), 100);
  }
  /* USER CODE END 3 */
}
Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?
-
00:00
00:00
Update Required Flash plugin
-
00:00
00:00