STM32_10.FullFish_STM32F411Ce

Full Fish Aquarium Controller

Full aquarium controller with alarm system, configuration and user interface. Extension of the STM32_11.KMU_FishSTM32G030F6P6 project.

STM32F4C++HALRTCTemperatureDisplayMenuAlarm

Project facts

  • Repository: STM32_10.FullFish_STM32F411Ce
  • Board / area: STM32F411CEU6 / RTC / Temperature / Display
  • Category: Automation
  • Status: Public repository

Technical description

  • The project is an extension and enhancement of the STM32_11.KMU_FishSTM32G030F6P6 project, which was a simple water level protection controller.
  • This new project offers a full aquarium control system with alarm functions, configuration and user interface.
  • The system handles temperature sensors, lighting and heater control, water level monitoring and RTC time management.
  • The project uses an advanced menu structure with encoder and button support for system configuration.
  • Alarm functions allow automatic on/off of lights and heaters based on settings and water temperature.
  • The system uses AT24C32 EEPROM memory to store configuration and system data.

What happens in the code

Selected key mechanisms from the project code. This is not a full repository dump, but an analysis of the parts responsible for the main firmware logic.

  • The project uses an interface-based architecture (IConfigStorage, IAlarmRTC, ITemperatureSensor) for better modularity.
  • The alarm system (AlarmRTC) handles automatic on/off of lights and heaters according to settings.
  • The menu system based on BuildMenu.cpp enables comprehensive system configuration using encoder and buttons.
  • Temperature control implemented by DS18B20Sensor with 1-Wire support and timer for generating delays.
  • Configuration stored in AT24C32 EEPROM with loading and saving of configuration data.
  • RTC time management with system synchronization and alarm functions.

Key code excerpts

The code is shortened to the parts that matter for understanding the project.

RTC Alarm System

Core/Src/AlarmRTC.cpp
void alarmRTC::ActionAlarms()
{
	HAL_RTC_GetTime(&hrtc, &time, RTC_FORMAT_BIN);
	HAL_RTC_GetDate(&hrtc, &date, RTC_FORMAT_BIN);
	
	if(_config->lightConfig.PowerOnOffLithtAuto == 1 && _config->lightConfig.PowerOnOffLithtManual == 0)
	{
		if(compareTime(&time, &_config->lightConfig.PowerOnLight) && _config->lightConfig.gpio.Enabled == 0)
		{
			_config->lightConfig.gpio.Enabled = 1;
			HAL_GPIO_WritePin(_config->lightConfig.gpio.port,_config->lightConfig.gpio.pin, GPIO_PIN_RESET);
		}

		if(compareTime(&time, &_config->lightConfig.PowerOffLight) && _config->lightConfig.gpio.Enabled == 1)
		{
			_config->lightConfig.gpio.Enabled = 0;
			HAL_GPIO_WritePin(_config->lightConfig.gpio.port,_config->lightConfig.gpio.pin, GPIO_PIN_SET);
		}
	}

	if(_config->heaterConfig.PowerOnOffHeaterAuto == 1 && _config->heaterConfig.PowerOnOffHeaterManual == 0)
	{
		int16_t temp = (int16_t)lroundf(SensorTemp);

		if((temp < _config->heaterConfig.TempMinONHeater  ) && (_config->heaterConfig.gpio.Enabled == 0))
		{
			_config->heaterConfig.gpio.Enabled = 1;
			HAL_GPIO_WritePin(_config->heaterConfig.gpio.port,_config->heaterConfig.gpio.pin, GPIO_PIN_RESET);
		}

		if((temp >_config->heaterConfig.TempMaxOffHeater  && temp > _config->heaterConfig.TempMinONHeater) && (_config->heaterConfig.gpio.Enabled == 1))
		{
			_config->heaterConfig.gpio.Enabled = 0;
			HAL_GPIO_WritePin(_config->heaterConfig.gpio.port,_config->heaterConfig.gpio.pin, GPIO_PIN_SET);
		}
	}
}

The ActionAlarms function handles automatic on/off of lights and heaters according to time settings and water temperature. It uses RTC to check the current time.

Menu Configuration

Core/Src/BuildMenu.cpp
static MenuItem miLightManualOnOff  {"Manual  wl/wyl ",[](){
	Action_SetOnOff(&aquaConfig.lightConfig.PowerOnOffLithtManual,true);
	if(aquaConfig.lightConfig.PowerOnOffLithtManual == 1)
	{
		aquaConfig.lightConfig.gpio.Enabled = 1;
		HAL_GPIO_WritePin(aquaConfig.lightConfig.gpio.port,aquaConfig.lightConfig.gpio.pin, GPIO_PIN_RESET);
	}
	else
	{
		aquaConfig.lightConfig.gpio.Enabled = 0;
		HAL_GPIO_WritePin(aquaConfig.lightConfig.gpio.port,aquaConfig.lightConfig.gpio.pin, GPIO_PIN_SET);
	}
}, {}};
static MenuItem miLightAutoOnOff  	{"Automat wl/wyl ",[](){Action_SetOnOff(&aquaConfig.lightConfig.PowerOnOffLithtAuto,false);}, {}};

Example menu configuration for light control - handles both manual and automatic modes with functions setting flags and controlling GPIO.

DS18B20 Temperature Control

Core/Src/TemperatureSensors.cpp
DS18B20Sensor::DS18B20Sensor(GPIO_TypeDef* dqPort, uint16_t dqPin, TIM_HandleTypeDef* htim)
: dqPort_(dqPort), dqPin_(dqPin), htim_(htim)
{
    // Timer do µs powinien już działać (HAL_TIM_Base_Start)
    // Linia 1-Wire w spoczynku ma być "puszczona" (input) + podciągnięta rezystorem 4.7k do 3.3V.
    LineInput();
}

void DS18B20Sensor::DelayUs(uint16_t us)
{
    // Założenie: timer tyka 1 MHz => 1 tick = 1 µs
    __HAL_TIM_SET_COUNTER(htim_, 0);
    while (__HAL_TIM_GET_COUNTER(htim_) < us) { }
}

The DS18B20Sensor class implements control of DS18B20 temperature sensor using 1-Wire bus and timers for generating delays.