├── HumiditySensorPresentation.pptx
├── README.md
└── HumiditySensor.c
/HumiditySensorPresentation.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gabrieldim/HumiditySensor/HEAD/HumiditySensorPresentation.pptx
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # HumiditySensor - “Embedded systems”
2 |
3 | - First week:
4 | The first week was the introduction to embedded systems by getting acquainted with the STM32 boards on which the whole project was based. This week's activities were divided into two parts: in the first part of the day before the break there were several presentations that would help us to make the main project we chose in the second week, and in the second part we tried and saw the application of the previously presented material.
5 | I worked with the STM32L100C board in the first week. I learned solidly how to use Atollic TrueSTUDIO, STM32CubeMX and TouchGFX, which I initially had difficulty with.
6 | I also had the opportunity during the whole internship to keep my board and try to learn additional things after the working day.
7 | At the end of the first week we had project proposals from the mentor and we could think for a few days on what topic we would like to work on.
8 |
9 |
10 | - Second week:
11 | At the beginning of the second week we divided into groups and chose topics. I was working with another colleague on a team on "Automated Smart Irrigation System".
12 | We first made the project on the STM32L100C board, but since this board did not have a built-in screen we switched to the STM32f769i Discovery in order for the final
13 | presentation to be better. In the main program I enabled to read the values given by the sensor and I also performed the mapping of the same.
14 | We set a condition for soil moisture in order to prevent the plants from drying out, and we prevented that with a special pump that irrigated the
15 | soil if the condition is met, ie the humidity is lower than we want. Since every plant needs a different level of soil moisture, we set an interrupt which,
16 | by clicking on the button that is built into the plate, increases the limit by 5% until we reach 100% and then returns to the initial set value.
17 |
18 |
19 | - Third week:
20 | In the third week we made a display of the change in humidity on the screen from the board itself in the form of a graph that when it reached the end of
21 | the screen we took the second part of the values and put them at the beginning so that the measurements could continue and be seen. part of the previous ones.
22 | During this week we have created special conditions with which appropriate messages appear on the screen. For example a message if the sensor is not in the
23 | ground or the sensor is not well connected and so on.
24 |
25 |
26 | - Fourth week:
27 | Last week we tested the project and saw what little things we could add to make it look better (such as changing the colors on the screen).
28 | Once we were sure that everything was working as we wanted we had to make a presentation of what we had made.
29 |
30 |
31 | => Gabriel Dimitrievski
32 |
--------------------------------------------------------------------------------
/HumiditySensor.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file ADC/ADC_TemperatureSensor/Src/main.c
4 | * @author MCD Application Team
5 | * @brief This example describes how to use the Temperature Sensor to
6 | * calculate the junction temperature of the device.
7 | ******************************************************************************
8 | * @attention
9 | *
10 | *
© COPYRIGHT(c) 2016 STMicroelectronics
11 | *
12 | * Redistribution and use in source and binary forms, with or without modification,
13 | * are permitted provided that the following conditions are met:
14 | * 1. Redistributions of source code must retain the above copyright notice,
15 | * this list of conditions and the following disclaimer.
16 | * 2. Redistributions in binary form must reproduce the above copyright notice,
17 | * this list of conditions and the following disclaimer in the documentation
18 | * and/or other materials provided with the distribution.
19 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software
21 | * without specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 | *
34 | ******************************************************************************
35 | */
36 |
37 | /* Includes ------------------------------------------------------------------*/
38 | #include "main.h"
39 |
40 | /** @addtogroup STM32F7xx_HAL_Examples
41 | * @{
42 | */
43 |
44 | /** @addtogroup ADC_TemperatureSensor
45 | * @{
46 | */
47 |
48 | /* Private typedef -----------------------------------------------------------*/
49 | /* Private define ------------------------------------------------------------*/
50 | #define TEMP_REFRESH_PERIOD 900 /* Internal temperature refresh period */
51 | #define humidity 25 /* Ambient Temperature */
52 | #define MAX_Value 3730.01 //za 5v e 3150 a na 3.3v 4050
53 | #define procent 100.0021
54 |
55 |
56 | /* Private macro -------------------------------------------------------------*/
57 | /* Private variables ---------------------------------------------------------*/
58 | /* ADC handler declaration */
59 | ADC_HandleTypeDef AdcHandle;
60 | /* Variable used to get converted value */
61 | __IO int32_t ConvertedValue = 0.01;
62 | int32_t JTemp = 0x0;
63 |
64 | /* Private function prototypes -----------------------------------------------*/
65 | void SystemClock_Config(void);
66 | static void LCD_Config(void);
67 | static void ADC_Config(void);
68 | static void Error_Handler(void);
69 | static void CPU_CACHE_Enable(void);
70 | //za gpio to
71 | static void MX_GPIO_Init(void);
72 | /* Private functions ---------------------------------------------------------*/
73 |
74 | /**
75 | * @brief Main program.
76 | * @param None
77 | * @retval None
78 | */
79 | int main(void)
80 | {
81 | /* Enable the CPU Cache */
82 | CPU_CACHE_Enable();
83 |
84 | /* STM32F7xx HAL library initialization:
85 | - Configure the Flash prefetch
86 | - Systick timer is configured by default as source of time base, but user
87 | can eventually implement his proper time base source (a general purpose
88 | timer for example or other time source), keeping in mind that Time base
89 | duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
90 | handled in milliseconds basis.
91 | - Set NVIC Group Priority to 4
92 | - Low Level Initialization
93 | */
94 | HAL_Init();
95 |
96 | /* Configure the system clock to 200 MHz */
97 | SystemClock_Config();
98 |
99 | /* Configure LED1 and LED2 */
100 | BSP_LED_Init(LED1);
101 | BSP_LED_Init(LED2);
102 |
103 | /*##-1- Configure the LCD peripheral #########################################*/
104 | LCD_Config();
105 | MX_GPIO_Init();
106 | /*##-2- Configure the ADC peripheral #########################################*/
107 | ADC_Config();
108 |
109 | /*##-3- Start the conversion process #######################################*/
110 | HAL_ADC_Start_DMA(&AdcHandle, (uint32_t*)&ConvertedValue, 1);
111 |
112 | /* Infinite loop */
113 | while (1)
114 | {
115 | /* Insert a delay define on TEMP_REFRESH_PERIOD */
116 | HAL_Delay(TEMP_REFRESH_PERIOD);
117 |
118 | /* Compute the Junction Temperature value */
119 | JTemp= (float)(ConvertedValue/MAX_Value)*procent;
120 | Show_Humidity();
121 | //JTemp= (float)(ConvertedValue);
122 |
123 | /* Display the Temperature Value on the LCD */
124 |
125 | if(JTemp>=25 && JTemp<=30)
126 | {
127 | HAL_GPIO_WritePin(GPIOF, GPIO_PIN_6,0);
128 | Show_Waring_Sensor();
129 | BSP_LED_Toggle(LED2);
130 | BSP_LED_Toggle(LED1);
131 | HAL_Delay(1000);
132 | }
133 | else
134 | {
135 | if(JTemp<=5){
136 | BSP_LED_Toggle(LED1);
137 |
138 | Sensor_Eject();
139 | }
140 | else{
141 | Show_Humidity();
142 | BSP_LED_Toggle(LED2);
143 | // HAL_GPIO_WritePin(GPIOI,GPIO_PIN_5,255);
144 | // HAL_GPIO_WritePin(GPIOI, GPIO_PIN_5, GPIO_PIN_RESET);
145 | HAL_GPIO_WritePin(GPIOF, GPIO_PIN_6,0);
146 | }
147 | if(JTemp<=38)
148 | {
149 | HAL_GPIO_WritePin(GPIOF, GPIO_PIN_6,100);
150 | }
151 | }
152 | if(JTemp==109)
153 | {
154 | Sensor_Alert_GNR();
155 | BSP_LED_Toggle(LED2);
156 | BSP_LED_Toggle(LED1);
157 | }
158 |
159 |
160 |
161 | /* Toggle LED2 */
162 |
163 | }
164 | }
165 |
166 |
167 | void Show_Humidity(void)
168 | {
169 |
170 | char desc[50];
171 | BSP_LCD_Clear(LCD_COLOR_WHITE);
172 | sprintf(desc, "Humidity is %ld %%", JTemp);
173 | BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()/2 + 45, (uint8_t *)desc, CENTER_MODE);
174 | BSP_LCD_ClearStringLine(30);
175 | }
176 |
177 | void Show_Waring_Sensor(void)
178 | {
179 | char desc[50];
180 |
181 | BSP_LCD_Clear(LCD_COLOR_WHITE);
182 |
183 | sprintf(desc, "!!!Check the Sensor Wires!!!");
184 | BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()/2 + 45, (uint8_t *)desc, CENTER_MODE);
185 | BSP_LCD_ClearStringLine(30);
186 | }
187 | void Sensor_Eject(void)
188 | {
189 | int c;
190 | char desc[50];
191 |
192 | BSP_LCD_Clear(LCD_COLOR_WHITE);
193 |
194 | sprintf(desc, "!!!The Sensor is Ejected!!!");
195 | BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()/2 + 45, (uint8_t *)desc, CENTER_MODE);
196 | BSP_LCD_ClearStringLine(30);
197 |
198 | }
199 |
200 | void Sensor_Alert_GNR(void){
201 | int c;
202 | char desc[50];
203 |
204 | BSP_LCD_Clear(LCD_COLOR_WHITE);
205 |
206 | sprintf(desc, "Check the GNR of the sensor!!!");
207 | BSP_LCD_DisplayStringAt(3, BSP_LCD_GetYSize()/2 + 45, (uint8_t *)desc, CENTER_MODE);
208 | BSP_LCD_ClearStringLine(33);
209 | }
210 | /**
211 | * @brief System Clock Configuration
212 | * The system Clock is configured as follow :
213 | * System Clock source = PLL (HSE)
214 | * SYSCLK(Hz) = 200000000
215 | * HCLK(Hz) = 200000000
216 | * AHB Prescaler = 1
217 | * APB1 Prescaler = 4
218 | * APB2 Prescaler = 2
219 | * HSE Frequency(Hz) = 25000000
220 | * PLL_M = 25
221 | * PLL_N = 400
222 | * PLL_P = 2
223 | * PLL_Q = 9
224 | * PLL_R = 7
225 | * VDD(V) = 3.3
226 | * Main regulator output voltage = Scale1 mode
227 | * Flash Latency(WS) = 7
228 | * @param None
229 | * @retval None
230 | */
231 | void SystemClock_Config(void)
232 | {
233 | RCC_ClkInitTypeDef RCC_ClkInitStruct;
234 | RCC_OscInitTypeDef RCC_OscInitStruct;
235 | HAL_StatusTypeDef ret = HAL_OK;
236 |
237 | /* Enable HSE Oscillator and activate PLL with HSE as source */
238 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
239 | RCC_OscInitStruct.HSEState = RCC_HSE_ON;
240 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
241 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
242 | RCC_OscInitStruct.PLL.PLLM = 25;
243 | RCC_OscInitStruct.PLL.PLLN = 400;
244 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
245 | RCC_OscInitStruct.PLL.PLLQ = 9;
246 | RCC_OscInitStruct.PLL.PLLR = 7;
247 |
248 | ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);
249 | if(ret != HAL_OK)
250 | {
251 | while(1) { ; }
252 | }
253 |
254 | /* Activate the OverDrive to reach the 216 MHz Frequency */
255 | ret = HAL_PWREx_EnableOverDrive();
256 | if(ret != HAL_OK)
257 | {
258 | while(1) { ; }
259 | }
260 |
261 | /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */
262 | RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
263 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
264 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
265 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
266 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
267 |
268 | ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7);
269 | if(ret != HAL_OK)
270 | {
271 | while(1) { ; }
272 | }
273 | }
274 |
275 | /**
276 | * @brief Configure the LCD for display.
277 | * @param None
278 | * @retval None
279 | */
280 | static void LCD_Config(void)
281 | {
282 | uint32_t lcd_status = LCD_OK;
283 |
284 | /* Initialize the LCD */
285 | lcd_status = BSP_LCD_Init();
286 | while(lcd_status != LCD_OK);
287 |
288 | BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS);
289 |
290 | /* Clear the LCD */
291 | BSP_LCD_Clear(LCD_COLOR_WHITE);
292 |
293 | /* Set LCD Example description */
294 | BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE);
295 | BSP_LCD_SetFont(&Font12);
296 | BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 20, (uint8_t *)"Copyright (c) STMicroelectronics", CENTER_MODE);
297 | BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
298 | BSP_LCD_FillRect(0, 0, BSP_LCD_GetXSize(), 120);
299 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
300 | BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
301 | BSP_LCD_SetFont(&Font24);
302 | BSP_LCD_DisplayStringAt(0, 10, (uint8_t *)"Humidity Sensor Measure", CENTER_MODE);
303 | BSP_LCD_SetFont(&Font16);
304 | BSP_LCD_DisplayStringAt(0, 60, (uint8_t *)"This example shows how to measure the Junction", CENTER_MODE);
305 | BSP_LCD_DisplayStringAt(0, 75, (uint8_t *)"Temperature of the device via an Internal", CENTER_MODE);
306 | BSP_LCD_DisplayStringAt(0, 90, (uint8_t *)"Sensor and display the Value on the LCD", CENTER_MODE);
307 |
308 | BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
309 | BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
310 | BSP_LCD_SetFont(&Font24);
311 | }
312 |
313 | /**
314 | * @brief Configure the ADC.
315 | * @param None
316 | * @retval None
317 | */
318 |
319 | static void MX_GPIO_Init(void)
320 | {
321 | GPIO_InitTypeDef GPIO_InitStruct = {0};
322 |
323 | /* GPIO Ports Clock Enable */
324 | __HAL_RCC_GPIOI_CLK_ENABLE();
325 | __HAL_RCC_GPIOF_CLK_ENABLE();
326 | __HAL_RCC_GPIOC_CLK_ENABLE();
327 | __HAL_RCC_GPIOA_CLK_ENABLE();
328 | __HAL_RCC_GPIOB_CLK_ENABLE();
329 |
330 | /*Configure GPIO pin Output Level */
331 | HAL_GPIO_WritePin(GPIOI, GPIO_PIN_5, GPIO_PIN_RESET);
332 |
333 | /*Configure GPIO pin Output Level */
334 | HAL_GPIO_WritePin(GPIOF, GPIO_PIN_6, GPIO_PIN_RESET);
335 |
336 | /*Configure GPIO pin : PI5 */
337 | GPIO_InitStruct.Pin = GPIO_PIN_5;
338 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
339 | GPIO_InitStruct.Pull = GPIO_NOPULL;
340 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
341 | HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);
342 |
343 | /*Configure GPIO pin : PF6 */
344 | GPIO_InitStruct.Pin = GPIO_PIN_6;
345 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
346 | GPIO_InitStruct.Pull = GPIO_NOPULL;
347 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
348 | HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
349 |
350 | /*Configure GPIO pins : PA4 PA6 PA5 */
351 | GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_6|GPIO_PIN_5;
352 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
353 | GPIO_InitStruct.Pull = GPIO_NOPULL;
354 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
355 |
356 | /*Configure GPIO pin : PC5 */
357 | GPIO_InitStruct.Pin = GPIO_PIN_5;
358 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
359 | GPIO_InitStruct.Pull = GPIO_NOPULL;
360 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
361 |
362 | /*Configure GPIO pin : PB1 */
363 | GPIO_InitStruct.Pin = GPIO_PIN_1;
364 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
365 | GPIO_InitStruct.Pull = GPIO_NOPULL;
366 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
367 | }
368 | static void ADC_Config(void)
369 | {
370 | ADC_ChannelConfTypeDef sConfig;
371 |
372 | /* Configure the ADC peripheral */
373 | AdcHandle.Instance = ADC1;
374 |
375 | AdcHandle.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV4;
376 | AdcHandle.Init.Resolution = ADC_RESOLUTION_12B;
377 | AdcHandle.Init.ScanConvMode = DISABLE; /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */
378 | AdcHandle.Init.ContinuousConvMode = ENABLE; /* Continuous mode enabled to have continuous conversion */
379 | AdcHandle.Init.DiscontinuousConvMode = DISABLE; /* Parameter discarded because sequencer is disabled */
380 | AdcHandle.Init.NbrOfDiscConversion = 0;
381 | AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; /* Conversion start not trigged by an external event */
382 | AdcHandle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1;
383 | AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT;
384 | AdcHandle.Init.NbrOfConversion = 1;
385 | AdcHandle.Init.DMAContinuousRequests = ENABLE;
386 | AdcHandle.Init.EOCSelection = DISABLE;
387 |
388 | if (HAL_ADC_Init(&AdcHandle) != HAL_OK)
389 | {
390 | /* ADC initialization Error */
391 | Error_Handler();
392 | }
393 |
394 | /* Configure ADC Temperature Sensor Channel */
395 | sConfig.Channel = ADC_CHANNEL_6;
396 | sConfig.Rank = 1;
397 | sConfig.SamplingTime = ADC_SAMPLETIME_56CYCLES;
398 | sConfig.Offset = 0;
399 |
400 | if (HAL_ADC_ConfigChannel(&AdcHandle, &sConfig) != HAL_OK)
401 | {
402 | /* Channel Configuration Error */
403 | Error_Handler();
404 | }
405 | }
406 |
407 | /**
408 | * @brief This function is executed in case of error occurrence.
409 | * @param None
410 | * @retval None
411 | */
412 | static void Error_Handler(void)
413 | {
414 | while (1)
415 | {
416 | /* LED1 blinks */
417 | BSP_LED_Toggle(LED1);
418 | HAL_Delay(20);
419 | }
420 | }
421 |
422 | #ifdef USE_FULL_ASSERT
423 |
424 | /**
425 | * @brief Reports the name of the source file and the source line number
426 | * where the assert_param error has occurred.
427 | * @param file: pointer to the source file name
428 | * @param line: assert_param error line source number
429 | * @retval None
430 | */
431 | void assert_failed(uint8_t *file, uint32_t line)
432 | {
433 | /* User can add his own implementation to report the file name and line number,
434 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
435 |
436 | /* Infinite loop */
437 | while (1)
438 | {
439 | }
440 | }
441 |
442 | #endif
443 |
444 | /**
445 | * @brief CPU L1-Cache enable.
446 | * @param None
447 | * @retval None
448 | */
449 | static void CPU_CACHE_Enable(void)
450 | {
451 | /* Enable I-Cache */
452 | SCB_EnableICache();
453 |
454 | /* Enable D-Cache */
455 | SCB_EnableDCache();
456 | }
457 |
458 | /**
459 | * @}
460 | */
461 |
462 | /**
463 | * @}
464 | */
465 |
466 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
467 |
--------------------------------------------------------------------------------