Docs

Micro-controllers, wireless transmission and database

Head

ADS1115 with Blue Pill using STM32CubeIDE

Prerequisites

This project assumes you have already installed STM32CubeIDE. You need to have previously done a basic blink sketch with blue-pill using STM32CubeIDE. I have made a complete video from installing STM32CubeIDE to LED blink program. You can watch it by clicking this link. https://www.youtube.com/watch?v=kXg467nVd_A

Wiring Diagram

Diagram

Image

STM32CubeIDE Settings

Click connectivity --> Click I2C1

For I2C select I2C

Libraries

Taken from https://github.com/DanielMartensson/STM32-Libraries/tree/master/ADS1015_ADS1115

and https://github.com/eziya/STM32_HAL_I2C_HD44780

Inside Core/Inc Folder

ADS1015_ADS1115.h liquidcrystal_i2c.h

Inside Core/Src Folder

ADS1015_ADS1115.c liquidcrystal_i2c.c

Additional code on top of STM32CubeIDE generated code

/* USER CODE BEGIN Includes */
#include "ADS1015_ADS1115.h"
#include "liquidcrystal_i2c.h"
/* USER CODE END Includes */

  /* USER CODE BEGIN 2 */
  ADS1xx5_I2C i2c;
  int16_t adc1;
  int millivolt;
  char snum[7];
  ADS1115(&i2c, &hi2c1, ADS_ADDR_GND); // Or ADS1015(&i2c, &hi2c1, ADS_ADDR_GND);
  ADSsetGain(&i2c, GAIN_ONE);
  HD44780_Init(2);
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    adc1 = ADSreadADC_SingleEnded(&i2c, 1);
    millivolt = adc1 * 4.096 * 1000 / 32768;
    millivolt = millivolt - 0; // Calibrate at 100mV
    itoa(millivolt, snum, 10);
    HD44780_Clear();
    HD44780_SetCursor(0,0);
    HD44780_PrintStr(snum);
    HAL_Delay(100);
    /* USER CODE END WHILE */