Those who are having problems with the temperature value, here are few things you should do to diagnose 1. In the set_gpio_input() function, try using GPIO_PULLUP instead of NOPULL. 2. Check the microsecond delay. This is the most vital part and 90% chances are that you have problem here. You can blink some LED every 1 second using us delay. Try the below code HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_1); for (int i=0; i
I have repeated your code with DHT11. At the first time it did not work at all, only DHT11_Start () function did properly and i could clearly see the response from sensor with help of osciloscope. Actually i had to extend HAL_Delay(1000) after all readings up to 1200 ms and it started working continuosly . Thank you so much for helping.
Hola, espero lo entiendan en español. El problema de que no arranque el DHT11 es por el comienzo de la señal enviada por el MCU. El sensor espera una señal en alto y luego los 18 mS en bajo. Se ve claramente en los diagramas del datasheet. Lo solucioné agregando unas líneas en el código de DHT11_Start de la siguiente manera: void DHT11_Start (void) { Set_Pin_Output(DHT11_PORT, DHT11_PIN); HAL_GPIO_WritePin(DHT11_PORT, DHT11_PIN, 1); /* Nivel de comienzo de comunicación */ delay(1000); HAL_GPIO_WritePin(DHT11_PORT, DHT11_PIN, 0); delay (18000); HAL_GPIO_WritePin(DHT11_PORT, DHT11_PIN, 1); delay(20); Set_Pin_Input(DHT11_PORT, DHT11_PIN); } Espero les sirva. Muy bueno el posteo y gracias, me fue de muchísima ayuda.
Sensor response doesn't work at all for me, doesnt matter if you connect data pin or not, program never enters if statement in DTH11_Response, and at the end of function the code is stuck on this while loop if you dont connect the data pin I dont know what I'm doinf wrong.
Hi sir! Could you consider making a video using these sensors without stopping the machine? I mean, it has a lot of delay that will affect the operation of the most sensitive systems. It would be interesting if you combined it with Rtos. Greetings, I've been following you for years!
You need to give delay even if you use freeRTOS. The sensor won't work if ypu try to read faster. Try considering some other sensor if you need faster readings.
1st The program goes to the response waiting function if (!(HAL_GPIO_ReadPin (DHT_PORT, DHT_PIN))) then it skips because at this time GPIOA_PIN_1 is SET and it runs to the while function while((HAL_GPIO_ReadPin (DHT_PORT, DHT_PIN))); // wait for the pin to go low and it's stuck in this loop because GPIO_PIN_1 is still SET without RESET. Even though in theory it should be low. I don't understand why it works like that but when I try to unplug the power to put the GPIO pin down low level and plug the power back in, the program works normally. It only crashes the first time the code is loaded. Do you know why?🙂🙂🙂
it ran on me, but need to start timer6 with "HAL_TIM_Base_Start(&htim6);" and need pull up resistor. two sides of setup have open drain or not. i used 3.3k resistor for 3.3volt setup and ds18b20 worked 3.3v.
Thank you! Everything works great on a Nucleo32-L432KC w/o any pullup resistor and with the DHT22 powered directly from Nucleo's 3.3V VCC pin. Great explanations! Subbed! :D
If u are gonna make the clock frequency 100 MHz, the DS18B20 is working correctly. The 100MHz is required for creating nanoseconds delay and please dont forget to add 4.7 K (pull up) resister to data pin.
does the delays have to be super precise? to test it out, i tried a 10 microsecond delay with a toggle pin and i get a pwm with 51.5 kHz frequency. Sometimes for highest delay like, 200 us, i get 2.488 khz.
Thanks for the helpful video. I had the problem of receiving the correct temperature in the L476RG-stm32 board. But I solved it by setting "80-1" instead of "50-1" in the prescaler in the TIMER stetting of the board scheme.
@@katiaihaddadene7457 Hi thanks for your watching and comment, yes it worked, afte you programmed the board, reset the board by pushing reset bottom or disconnect power once.
I had a problem, but I fixed it. I was using 8 MHz HCLK, but once I increased it to 48 MHz (plus increased prescaler on timer) everything started working fine
thanks for the tutorial, however I cant get the DS18B20 working, I get the presence pulse, I check the data line with my scope, timing looks right, I tried all your alternative solution, the only is issue I can see is the transition from output to input is about 17us so when writing a "1" im a bit over the 15us limit, could you confirm that on your end ? thanks
I'm getting stuck in the infinite loop.. I've checked the timer delay, the pull up resistor. But still the same response. Do you have a solution for that?
*UPDATE* I've connected an external power source after reading the comments. Now I'm out of the infinity loop. But the value of my response variable is -1 or 255. Still suffering with the sensor. Would appreciate if anyone helps.
Why the program does not work when i use extra delay or delay included functions? example lcd_init(). because lcd_init include extra HAL_delay(). how can i solve it?
What would be the prescaler and counter period for STM32F3030k8 tim 6 configuration? With the ioc configuration you suggested its counting 10 seconds in 60 seconds.
I want to display temperature by 7 segment. what should i do on this code? Temp_byte1 = DS18B20_Read(); Temp_byte2 = DS18B20_Read(); TEMP = (Temp_byte2
Hi I am trying to interface dht22 with stm32l476rg. I followed all your steps. But I cant get the readings to display in my lcd. It shows some funny characters all the time. In my debugger its showing error as well. Cant seem to find the exact problem. Please help….
What should be the clock configurations for stm32f072rb discovery (48MHZ) ?? Because code doesnt work, there is no error, but when i open the live expression it only gives 0. So i taught the problem could be the clock congifuration. BTW this is my project for embedded system design so please answer
THankyou for this video!DS18B20 works perfect. Can you tell how to change the resolution of sensor and will the code work for negative temperature values?
There could be many reasons for this. Try this video it explains how it actually works. If you have a logi analyzer or an oscilloscope, it will be easier to debug this. ruclips.net/video/9RmLBkyb_Gw/видео.html
But why there is that division by 16 with DS18B20 (25:36 - line 401)? How did you know you have to divide by exactly 16? It is from documentation or what (i can't find it there and i don't understand) :(
@@ControllersTech so what different 8 bit integral and 8 bit decimal :( and what the effect of 8 bit decimal because i dont see u use it to display in LCD
Hi. I am using STM32L476RG Nucleo board. I am getting the values of Temperature and Humidity variables but they seem to be coming in 255-1024 range. E.g my temp is showing 331 and Humidity is showing 665. These values changes when parameters changes . when I put a lighter in front of dht22 the temperature values starts going up. Kindly help.
@@ControllersTech wow you're absolutely right!!!!! Dividing by 10 shows the values correctly now. P.S this is me running the compiled code in which both DHT11 and 22 are included. Analogue pin 1 and DHT22 sensor with 3 pins. Also I didn't have to power the DHT22 separately or use a pull up resistor. Thanks a lot for this video. Amazing stuff :)
@@ControllersTech ok, I think that I solved my problem with timers but I got another problem. In function DHT22_Check_Response you need to wait for the pin to go low, but my pin does not go to low state. What could be the problem?
Why did u put PA1(the sensor data) as output and not as input ? the sensor is supposed to send data to the MC not the opposite right ? i'm new so don't laugh at my questions xD
You are right. Actually in this one wire communication, we need to send the command to sensor and receive data from sensor using the same pin. Setting input and output based on the Requirements is taken care inside the code itself. So here it really doesn't matter if u choose input or output.
@@ControllersTech oh i see thanks ! however i have a little issue that i need ur help with ! i managed to adapt the code to my f407VG however ,the sensor seems to give the first mesure and then stops ! i'm not getting a refresh unless i restart it manually ! here's my code ! i really wish u could take a look and tell me what could be wrong ! www.mediafire.com/file/2gcatlkl1v4dh8g/dht11.txt/file
i used lib and viewed the temp&hum of DHT11 in debug successfully but when I also add i2c-lcd lib, LCD cannot show the temp and hum value. Then i try to send simple string to LCD like Hello and it also doesn't work. why? Maybe error when I add 2 different lib file in project ( DHT.c and i2c-lcd.c)
Muchas gracias por su ayuda, lo probé con el DS18B20 en el programa STM32cubeIDE, al principio no me funcionó, y por alguna razón no corre el programa general cuando uso el HAL_delay, así que solo usé el delay() de la función creada, en este caso al ser solo para datos de 16bits, para los los retardos mas grandes usé la estructura for.
hi, I am using stm32f401re for dht11 and in the function Check_Response it stuck in the while ((HAL_GPIO_ReadPin (DHT11_PORT, DHT11_PIN)));// gpio port A, pin 0 , timer 2 and the responce variable is 0 can you tell me how to try to fix it?
Hello, I have a problem with displaying data to LCD, when I debug, it works well, but when I try to put it to LCD, it doesn't display the value. I use LCD with I2C. Can you check it, please? Many thanks
Lcd display only ascii values so make sure you convert the data to the ascii format first. Use sprintf to do so. If it's still not displaying, check if the lcd works separately or not.
@@ControllersTech It seems like the problem occurs when I use LCD_Init(), when i use that it seems the DHT stops working. Can you tell where is the problem? Thanks
define: char line1[32]=" "; char line2[32]=" "; then add begin2 to: lcd_init(); and put this codes in while loop: sprintf(line2,"%.2f ",Humidity); lcd_put_cur(0,1); lcd_send_string(line2); HAL_Delay(500); sprintf(line1,"%.2f ",Temperature); lcd_put_cur(1,1); lcd_send_string(line1); HAL_Delay(500);
Hi, I use your code and setting in STM32CubeIDE. (I use DS18B20 with stm32f767zi) and I want it to return temp in Teraterm. but it return nothing. Tempurature is always 0 *c. What should I do?
Oh, Hi ☺ I finally fixed it, but it's long time ago and i forgot it already ... I just repeat this video and follow each step carefully and then it works ...
Hi This video was very interesting, however my sensor DHT11 only read the first value, then this stop the activity. What can do to solve this? I´m working in a STM32f303K8. Thanks.
@@ControllersTech Hi I was checking the code with debug, I see that the function "DHT11_Check_Response" stop when it's arrived at " while ((HAL_GPIO_ReadPin (DHT11_PORT, DHT11_PIN)));", because, the pin never get "low", I'm not sure that can be, can you help me? can we speak in Discord? Thanks.
I have a question. I did everything from the DHT11 sensor tutorial with LCD and it doesn't work for me. Just introduce me TEMP: 0.00 C RH: 0.00% My DHT11 sensor works but I don't see anything change on the LCD. Please help. i'm using STM32F401
Those variables where you want to store the temp and humidity values. I passed them as the parameters to function right.. don't do that. just declare new variables and save the temp and hum values into them
Hi, I have tried your code on the stm32F4 disc board, and the STM32L0 for the DHT11 chip. It gets stuck in the while loop: while ((HAL_GPIO_ReadPin (DHT11_PORT, DHT11_PIN))) in the response function. Any ideas why?
Based on all the requests I get on all these sensors, I think you are doing something wrong in the following sections 1. you made some mistake with the microsecond delay. 2. Sensor itself is not connected properly.
@@ControllersTech that's a shame, I checked the timer on the oscilloscope and its perfect, as for the wiring it's almost impossible to mess up. I wonder if there's different types of DHT11 sensors. I will work it out and let you know!
@@ControllersTech I have found the issue is STMCubeIDE, turns out if you put a break-point on DHT11_Start() and jump to the next line the IDE hangs. A glitch to report to ST at some point. Thanks for your help !
You should not stop the execution after starting the DHT11... This sensor works on precise timing. When you stop the execution, the mcu stops but the sensor will keep working. So when you read the data in next instruction, you will get some unexpected behaviour
Hello, I have a problem that my temperature gets read initialy and it never updates again no matter of what i put on the sensor value, like the while loop breaks or something, do you know what could be the cause? Thanks
Try giving atleast 3second delay between successive reads. Also DEBUG... i don't know how you guys write codes without debugging. When it stop updating, pause the debugger and see where the control is.
I am facing the same problem. I'm using stm32f401re + dht22 and I'm running a simulation on proteus. When I run the simulation the values of temperature and humidity are read correctly. However when I vary either value while the simulation is still running the new values are not being updated on my lcd. The only way I can display those new values is by stopping and running the simulation again. BTW I used the unified DHT library provided in the description link. I've tried many solutions and I'm lost and i don't know what to do
hi i am trying to run the code but i get an error in this line of code __HAL_TIM_SET_COUNTER (& htim6,0); I am using a stm32l051c8t6 I still can't find the problem.
@@ControllersTech if I have configured timer 6 as is the tutorial my problem is that in the debugger I see values of 4095.9375 for the temperature NOTE: I have a pull UP resistor of 4k7 OHM Does it influence when reading the DS18B20? according to the tutorial, said resistance should not be
hi i dont know why but when a i use dht22 , i get wrong values, humidity seems to be right but i get 102.4 as temperature which is obviously wrong any ideas?
Are u getting consistent 102.4 ? Are the values fluctuating a little ? You can try putting your sensor in the refrigerator for a while and then test. Check the values for both humidity and temperature..
hello, i have problem with viewing the temperature and humidity after starting program lcd views initializing and then i dont se anything, i changed your timer from 6 to 1. Can u help what can i do?
Hi and good job! How can I make the temperature sensor show me the data every 30 minutes or every estimated period of time... IS IT POSSIBLE? that so that I do not consume a lot of energy
It's not the timer. You have to use RTC. Once the mcu goes into standby, timers don't work anymore. We can wake the mcu only using certain things and RTC alarm is one of them.
My problem is solved( I use STM32F103C8, Timer 4). My solutions: 1. In DHT11_Start(), I change the code by: { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, 1); //Initialize with Data pin HIGH HAL_Delay(1000); Set_Pin_Output (DHT11_PORT, DHT11_PIN); // set the pin as output HAL_GPIO_WritePin (DHT11_PORT, DHT11_PIN, 0); // pull the pin low HAL_Delay(18); //wait for 18ms HAL_GPIO_WritePin (DHT11_PORT, DHT11_PIN, 1); // pull the pin high delay(20); //20us Set_Pin_Input(DHT11_PORT, DHT11_PIN); // set as input } 2. In main(), I add function HAL_TIM_Base_Start(&htim4); { ..... MX_GPIO_Init(); MX_I2C1_Init(); MX_TIM4_Init(); HAL_TIM_Base_Start(&htim4); .... }
All of those who has been having trouble because of the infinite loop: With this modification it works on my case. void MODO_SALIDA(){ RCC->AHB2ENR|=(RCC_AHB2ENR_GPIOAEN); GPIOA->MODER |= (0
i had a problem that i wasn't able to solve, but then i just changed gpio_output, to gpio_input and everything works!!! In this case is the same because is one wire communication
I tried change mode of Pin A0 from GPIO_MODE_OUTPUT_PP to GPIO_MODE_OUTPUT_OD and in DHT11_Start() function you guys can remove Set_Pin_Output and Set_Pin_Input funcion (must set PA0 to high first). void DHT11_Start (void) { HAL_GPIO_WritePin (DHT11_PORT, DHT11_PIN, 0); // pull the pin low delay (20000); // wait for >18ms HAL_GPIO_WritePin (DHT11_PORT, DHT11_PIN, 1); // pull the pin high delay (45); // wait for about 40us, đợi DHT11 respone } In DHT11_Check_Response() function remove 'delay (40)' after 'uint8_t Response = 0'. Let's try it, it works fine
I 100% followed the video and the code but still doesn't work then after >10 Hours of debugging, I found out it magically works well if I turned the data pin back to Reset_State Still can't figure out why, but it works so whatever lolll
I watched the video and followed all the steps properly and DHT11 sensor worked for me in 1st attempt (I am using stm32f407 discovery board), later for one project I needed to use the temp sensor with HC-SR04 sensor and 16x2 lcd without i2c driver but it was not working I checked and found out the program was getting struck, I scrolled thru the comments and saw one guy giving some suggestion @electrolabs337 (Electro Labs) was his name, His solution no 1 worked flawlessly (big thanks to him) but can anyone explain why is his solution working, I would really really like to know
Controllers Tech ya I tried to light up the led every single second using the us delay and it seemed to work just fine. However, it looped inside the while loop infinitely waiting for the pin to go low in check response function. I’m using an stm32f407 board and have the same setting for the hclk in the tutorial video (50MHz). I’ve checked data sheet of the DHT22 and everything in the code looks just fine accordingly. I’ve been working on this for an entire week now and have purchased several new DHT22 sensors in case the sensor is busted, but still have no clue what’s going on.. I’d greatly appreciate it if you can offer any help!
Those who are having problems with the temperature value, here are few things you should do to diagnose
1. In the set_gpio_input() function, try using GPIO_PULLUP instead of NOPULL.
2. Check the microsecond delay. This is the most vital part and 90% chances are that you have problem here. You can blink some LED every 1 second using us delay.
Try the below code
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_1);
for (int i=0; i
what external source shoold we use could you tell us please ?
What an excellent response, I'm wish I saw this earlier, you do a great job!!
instablaster...
HOW DO I CONFIGURE LM016L LCD SCREEN IF IM USING PROTEUS TO RUN THE SIMULATION
I have repeated your code with DHT11. At the first time it did not work at all, only DHT11_Start () function did properly and i could clearly see the response from sensor with help of osciloscope. Actually i had to extend HAL_Delay(1000) after all readings up to 1200 ms and it started working continuosly . Thank you so much for helping.
I followed with DHT11 and STM32F103C8T6.
After a few trials and reading the comments, it works perfectly!
Hola, espero lo entiendan en español.
El problema de que no arranque el DHT11 es por el comienzo de la señal enviada por el MCU.
El sensor espera una señal en alto y luego los 18 mS en bajo. Se ve claramente en los diagramas del datasheet.
Lo solucioné agregando unas líneas en el código de DHT11_Start de la siguiente manera:
void DHT11_Start (void)
{
Set_Pin_Output(DHT11_PORT, DHT11_PIN);
HAL_GPIO_WritePin(DHT11_PORT, DHT11_PIN, 1);
/* Nivel de comienzo de comunicación */
delay(1000);
HAL_GPIO_WritePin(DHT11_PORT, DHT11_PIN, 0);
delay (18000);
HAL_GPIO_WritePin(DHT11_PORT, DHT11_PIN, 1);
delay(20);
Set_Pin_Input(DHT11_PORT, DHT11_PIN);
}
Espero les sirva. Muy bueno el posteo y gracias, me fue de muchísima ayuda.
Yes! Actually the problem is there for me. Thanks for sharing both of you Controllers Tech and
mateaguero
@@truongpham7279 Thank you so much!!!
Sensor response doesn't work at all for me, doesnt matter if you connect data pin or not, program never enters if statement in DTH11_Response, and at the end of function the code is stuck on this while loop if you dont connect the data pin I dont know what I'm doinf wrong.
Hi sir! Could you consider making a video using these sensors without stopping the machine? I mean, it has a lot of delay that will affect the operation of the most sensitive systems. It would be interesting if you combined it with Rtos. Greetings, I've been following you for years!
You need to give delay even if you use freeRTOS. The sensor won't work if ypu try to read faster.
Try considering some other sensor if you need faster readings.
i tried a pull up resistor (around 4.7K) and giving power from an external source, it works perfectly
1st The program goes to the response waiting function if (!(HAL_GPIO_ReadPin (DHT_PORT, DHT_PIN))) then it skips because at this time GPIOA_PIN_1 is SET and it runs to the while function while((HAL_GPIO_ReadPin (DHT_PORT, DHT_PIN))); // wait for the pin to go low
and it's stuck in this loop because GPIO_PIN_1 is still SET without RESET. Even though in theory it should be low. I don't understand why it works like that but when I try to unplug the power to put the GPIO pin down low level and plug the power back in, the program works normally. It only crashes the first time the code is loaded. Do you know why?🙂🙂🙂
it ran on me, but need to start timer6 with "HAL_TIM_Base_Start(&htim6);" and need pull up resistor. two sides of setup have open drain or not. i used 3.3k resistor for 3.3volt setup and ds18b20 worked 3.3v.
Thanks for video, but I think I need to add timeouts everywhere to not stuck somewhere in loop.
Thank you! Everything works great on a Nucleo32-L432KC w/o any pullup resistor and with the DHT22 powered directly from Nucleo's 3.3V VCC pin. Great explanations! Subbed! :D
Hello, I am using the same nucleo, but my values remain at 0, could you guide me how you achieved it please?
@@gisselrosariveranavarro84 did u find a solution?
If u are gonna make the clock frequency 100 MHz, the DS18B20 is working correctly. The 100MHz is required for creating nanoseconds delay and please dont forget to add 4.7 K (pull up) resister to data pin.
does the delays have to be super precise? to test it out, i tried a 10 microsecond delay with a toggle pin and i get a pwm with 51.5 kHz frequency. Sometimes for highest delay like, 200 us, i get 2.488 khz.
Thanks for the helpful video. I had the problem of receiving the correct temperature in the L476RG-stm32 board. But I solved it by setting "80-1" instead of "50-1" in the prescaler in the TIMER stetting of the board scheme.
It worked ? You got the temperature values please .? I have stm32l476RG to but it doesn t work
@@katiaihaddadene7457 Hi good evening, yes I put it in my channel too : ruclips.net/channel/UCZpfJjgR5zA-XrB26IhOzkA
@@katiaihaddadene7457 Hi thanks for your watching and comment, yes it worked, afte you programmed the board, reset the board by pushing reset bottom or disconnect power once.
@@amintayebi thanks for replying , i did it but i have 0 temperature
@@katiaihaddadene7457 you have to play with the parameters, PULL DOWN,.. or prescaler, reset several times then it will work.
I had a problem, but I fixed it. I was using 8 MHz HCLK, but once I increased it to 48 MHz (plus increased prescaler on timer) everything started working fine
@vandal sir,
Which sensor are you using?
@@anirudhpattar5374 I think I was using DS18B20 with STM32F0DISCOVERY board
thanks for the tutorial, however I cant get the DS18B20 working, I get the presence pulse, I check the data line with my scope, timing looks right, I tried all your alternative solution, the only is issue I can see is the transition from output to input is about 17us so when writing a "1" im a bit over the 15us limit, could you confirm that on your end ? thanks
Increase the sysclock. Make it highest possible
@@ControllersTech yap that worked, thanks
Hay, this is a very interesting video. thank's for the detailed explanation.
Can u show me how to access ds18b20 in parasitic mode.
Thank You
I'm getting stuck in the infinite loop.. I've checked the timer delay, the pull up resistor. But still the same response. Do you have a solution for that?
*UPDATE*
I've connected an external power source after reading the comments. Now I'm out of the infinity loop. But the value of my response variable is -1 or 255. Still suffering with the sensor. Would appreciate if anyone helps.
@@nafiurrahman1504 did u find a solution?
Code doesn't work with DS18B20; using STM32F103C8T6 (Bluepill)
Why the program does not work when i use extra delay or delay included functions? example lcd_init(). because lcd_init include extra HAL_delay(). how can i solve it?
Where are u putting the LCD init ?
Regarding the hal delay, you should test the led blinking if you have doubt about that
What would be the prescaler and counter period for STM32F3030k8 tim 6 configuration? With the ioc configuration you suggested its counting 10 seconds in 60 seconds.
It's not some fixed value.
It changes based on the clock setup, timer connection, input frequency etc.
Watch that delay video to understand it.
Do i necessary must have an lcd to view the results?
No. You can view then in the debugger also
i'm trying to configure my sensor but not with the library HAL but i have some problem to configure my pin to LOW, HIGHT and READ mode, how can i do?
I want to display temperature by 7 segment. what should i do on this code?
Temp_byte1 = DS18B20_Read();
Temp_byte2 = DS18B20_Read();
TEMP = (Temp_byte2
Hi I am trying to interface dht22 with stm32l476rg. I followed all your steps. But I cant get the readings to display in my lcd. It shows some funny characters all the time. In my debugger its showing error as well. Cant seem to find the exact problem. Please help….
What should be the clock configurations for stm32f072rb discovery (48MHZ) ?? Because code doesnt work, there is no error, but when i open the live expression it only gives 0. So i taught the problem could be the clock congifuration.
BTW this is my project for embedded system design so please answer
Read comments under the video and try those solutions
THankyou for this video!DS18B20 works perfect.
Can you tell how to change the resolution of sensor and will the code work for negative temperature values?
how it works ?it doesnt work for me any idea please
Double check the code with the video. I noticed that the code was a bit different from the one in the link
How have you connected the LCD with MCU? Can you explain the breadboard connections of LCD and DS18B20 ?
The ds18b20 connection is shown on the webpage. Link is in the description.
Lcd is connected via i2c. Scl with scl and sda with sda.
Hello I am trying to do this project on a STM32L476 board and it doesnt have the SET_Pin_output and SET_PIN_INPUt functions. what would i do instead?
These function are not present by default. I wrote them in the code.
@@ControllersTech I managed to figure it out. Do you know what I can use to output on putty instead of a display
i have problem when i try to read ds18b20 temperature with stm32 L0 series. The result always is 4095, do you have any advise
There could be many reasons for this. Try this video it explains how it actually works. If you have a logi analyzer or an oscilloscope, it will be easier to debug this.
ruclips.net/video/9RmLBkyb_Gw/видео.html
did u find a solution?
It worked for me but I have to add something more. My timer was not incrementing, in function MX_TIM2_Init i added "HAL_TIM_Base_Start(&htim2);" :)
But why there is that division by 16 with DS18B20 (25:36 - line 401)? How did you know you have to divide by exactly 16? It is from documentation or what (i can't find it there and i don't understand) :(
Check the temperature examples provided in the datasheet
@@ControllersTech okay, thank you :)
Kind of a newbie with STM32 boards LCDs so how do I connect the LCD to the board without using an i2c module? I use an STM32F411RE
Search for lcd in this channel. There is a video on parallel mode.
does the code need to be changed at all or is it just the connections?
The lcd library file is going to be different. The main code will remain the same.
what exactly would the changes be?
hello chef,
thank you so much for this video
ı want to one question. I must use five sensör same time can ı do it
What 5 sensors ?
@@ControllersTech I must use 5 piece DS18B20 temperature sensör on same MCU this is possible?
hi dude!
Tell me boss, how to use dht11 with usart on timer input capture mode with dma without using delay function? have any magic trick for this?
I'm using the STM32WB55 nucleo board and DS18B20 as the temperature sensor. Is there any change needed to be done in the code?
No changes need in the code but See the setup part carefully
@@ControllersTech Thank you
In the response cycle, when we read the pin it should be 0. But im getting 1. What could be the reason ?
How can I convert result of DHT11 from 2 byte temperature to float like DS18B20. I try do it like you code with DS18B20, but it's wrong value.
Temp_byte1 = DS18B20_Read();
Temp_byte2 = DS18B20_Read();
TEMP = (Temp_byte2
Dht11 doesn't give float values in decimal
@@ControllersTech oh, DHT22 can?
Yes
@@ControllersTech so what different 8 bit integral and 8 bit decimal :( and what the effect of 8 bit decimal because i dont see u use it to display in LCD
Thank you!! It works!!!
thanks for sharing. If you don't mind, Can you make a video about max31855 for temperature measurement?
Thanks for tutorials !!!!
Hi. I am using STM32L476RG Nucleo board. I am getting the values of Temperature and Humidity variables but they seem to be coming in 255-1024 range. E.g my temp is showing 331 and Humidity is showing 665. These values changes when parameters changes . when I put a lighter in front of dht22 the temperature values starts going up.
Kindly help.
I think you need to divide by 10. So 33.1 and 66.5
@@ControllersTech wow you're absolutely right!!!!! Dividing by 10 shows the values correctly now.
P.S this is me running the compiled code in which both DHT11 and 22 are included. Analogue pin 1 and DHT22 sensor with 3 pins. Also I didn't have to power the DHT22 separately or use a pull up resistor.
Thanks a lot for this video. Amazing stuff :)
Hi,
I am using STM32-f031k6 and DHT22 sensor. Max clk frequency of the STM is 48MHz. Do I need any modifications to the code that it will work?
Dht22 related functions will remain same for everyone. You just need to modify the timer according to your setup. Watch the video properly.
@@ControllersTech ok, I think that I solved my problem with timers but I got another problem. In function DHT22_Check_Response you need to wait for the pin to go low, but my pin does not go to low state. What could be the problem?
It's related to timing only.
Check the connection also..
Why did u put PA1(the sensor data) as output and not as input ? the sensor is supposed to send data to the MC not the opposite right ? i'm new so don't laugh at my questions xD
You are right.
Actually in this one wire communication, we need to send the command to sensor and receive data from sensor using the same pin.
Setting input and output based on the Requirements is taken care inside the code itself.
So here it really doesn't matter if u choose input or output.
@@ControllersTech oh i see thanks ! however i have a little issue that i need ur help with ! i managed to adapt the code to my f407VG however ,the sensor seems to give the first mesure and then stops ! i'm not getting a refresh unless i restart it manually ! here's my code ! i really wish u could take a look and tell me what could be wrong !
www.mediafire.com/file/2gcatlkl1v4dh8g/dht11.txt/file
Give at least 3 seconds delay before measuring again..
@@ControllersTech Damn ... u're a a genius ... Thanks man ! you videos are sooo interesting and nicely done ! Keep it up man
i used lib and viewed the temp&hum of DHT11 in debug successfully but when I also add i2c-lcd lib, LCD cannot show the temp and hum value. Then i try to send simple string to LCD like Hello and it also doesn't work.
why? Maybe error when I add 2 different lib file in project ( DHT.c and i2c-lcd.c)
lỗi ở thư viện thôi
What would be the clock frequency for STM32F3030k8? I cant choose 50Mhz
It can work at any frequency, higher than 1 MHz
Muchas gracias por su ayuda, lo probé con el DS18B20 en el programa STM32cubeIDE, al principio no me funcionó, y por alguna razón no corre el programa general cuando uso el HAL_delay, así que solo usé el delay() de la función creada, en este caso al ser solo para datos de 16bits, para los los retardos mas grandes usé la estructura for.
hi,
I am using stm32f401re for dht11
and in the function Check_Response it stuck in the
while ((HAL_GPIO_ReadPin (DHT11_PORT, DHT11_PIN)));// gpio port A, pin 0 , timer 2
and the responce variable is 0
can you tell me how to try to fix it?
change the pin mode in the .ioc window, set to input instead of output
@@louislienart1093thanks this worked for me.
if i follow you is it possible to simulate it on proteus?(I use stm32f103c6 in proteus)
Probably.. I never tried
why i have error:
conflicting types for ‘DS18B20_Start’
Hello, I have a problem with displaying data to LCD, when I debug, it works well, but when I try to put it to LCD, it doesn't display the value. I use LCD with I2C. Can you check it, please? Many thanks
Lcd display only ascii values so make sure you convert the data to the ascii format first. Use sprintf to do so.
If it's still not displaying, check if the lcd works separately or not.
@@ControllersTech Many thanks, sir. I will try it
@@ControllersTech It seems like the problem occurs when I use LCD_Init(), when i use that it seems the DHT stops working. Can you tell where is the problem? Thanks
@@truongtrongnhan8808 I had the exact same problem as you. Have you fixed it yet?
define:
char line1[32]=" ";
char line2[32]=" ";
then add begin2 to:
lcd_init();
and put this codes in while loop:
sprintf(line2,"%.2f ",Humidity);
lcd_put_cur(0,1);
lcd_send_string(line2);
HAL_Delay(500);
sprintf(line1,"%.2f ",Temperature);
lcd_put_cur(1,1);
lcd_send_string(line1);
HAL_Delay(500);
what should i do if the LCD display -255, Please
Hello, I get an error that _HAL_TIM_SET_COUNTER is undifined and implicit declaration of function "_HAL_TIM_SET_COUNTER" is invalid. Can you help me ?
2 underscores before HAL
@@ControllersTech yeah, dumb mistake xd thank you very much
I already try the coding LCD just display 0 degree and 0%. Is there anything need to change from coding
same...
Read the comments which i have given the heart (❤️) to
@@ControllersTech mateaguero's solution works :))))
Hi,
I use your code and setting in STM32CubeIDE. (I use DS18B20 with stm32f767zi)
and I want it to return temp in Teraterm.
but it return nothing. Tempurature is always 0 *c.
What should I do?
Hi! Did you fix that? Because i have the same problem... Please, let me know if you fixed it
did you fix it?
Oh, Hi ☺
I finally fixed it, but it's long time ago and i forgot it already ...
I just repeat this video and follow each step carefully and then it works ...
Hi
This video was very interesting, however my sensor DHT11 only read the first value, then this stop the activity. What can do to solve this? I´m working in a STM32f303K8.
Thanks.
Make sure you give enough delay between 2 reads.
Also check the comments with ❤️. They might help you
@@ControllersTech Hi
I was checking the code with debug, I see that the function "DHT11_Check_Response" stop when it's arrived at " while ((HAL_GPIO_ReadPin (DHT11_PORT, DHT11_PIN)));", because, the pin never get "low", I'm not sure that can be, can you help me?
can we speak in Discord?
Thanks.
@@jorgeluislampreabarragan3528 did you find the problem, i got the same error as you, please help me
@@jorgeluislampreabarragan3528 try to give 3 second delay between 2 readings
I have a question. I did everything from the DHT11 sensor tutorial with LCD and it doesn't work for me. Just introduce me
TEMP: 0.00 C
RH: 0.00%
My DHT11 sensor works but I don't see anything change on the LCD. Please help.
i'm using STM32F401
Declare the variables globally (before main function) and directly update the value into them.
@@ControllersTech What variables?
Those variables where you want to store the temp and humidity values.
I passed them as the parameters to function right.. don't do that. just declare new variables and save the temp and hum values into them
@@ControllersTech I don't know if I'm doing it correctly, but it doesn't work for me. :(
Take a look at the pinned comment and comment with ❤️
Hi,
I have tried your code on the stm32F4 disc board, and the STM32L0 for the DHT11 chip. It gets stuck in the while loop: while ((HAL_GPIO_ReadPin (DHT11_PORT, DHT11_PIN))) in the response function. Any ideas why?
Based on all the requests I get on all these sensors, I think you are doing something wrong in the following sections
1. you made some mistake with the microsecond delay.
2. Sensor itself is not connected properly.
@@ControllersTech that's a shame, I checked the timer on the oscilloscope and its perfect, as for the wiring it's almost impossible to mess up. I wonder if there's different types of DHT11 sensors. I will work it out and let you know!
You can try using the pull up resistor on the data pin. That might help
@@ControllersTech I have found the issue is STMCubeIDE, turns out if you put a break-point on DHT11_Start() and jump to the next line the IDE hangs. A glitch to report to ST at some point. Thanks for your help !
You should not stop the execution after starting the DHT11... This sensor works on precise timing. When you stop the execution, the mcu stops but the sensor will keep working. So when you read the data in next instruction, you will get some unexpected behaviour
Hello, I have a problem that my temperature gets read initialy and it never updates again no matter of what i put on the sensor value, like the while loop breaks or something, do you know what could be the cause? Thanks
Try giving atleast 3second delay between successive reads.
Also DEBUG... i don't know how you guys write codes without debugging.
When it stop updating, pause the debugger and see where the control is.
I am facing the same problem. I'm using stm32f401re + dht22 and I'm running a simulation on proteus.
When I run the simulation the values of temperature and humidity are read correctly. However when I vary either value while the simulation is still running the new values are not being updated on my lcd.
The only way I can display those new values is by stopping and running the simulation again.
BTW I used the unified DHT library provided in the description link.
I've tried many solutions and I'm lost and i don't know what to do
is there anything need change on line where have uint8_t and uint16_t
How to get dark theme on STM32CubeIDE ????
Goto help-> eclipse marketplace and download darkest dark theme
@@ControllersTech Under CubeIDE 'Help' tab, about two thirds of the way down the help list.
Kindly make videos on how to add CMSIS DSP Library (FFT or filters) support to stm32.Thanks
hi, what software would you recommend to run this project in simulation mode?
Why simulation mode?
@@ControllersTech i dont really need the hardware, simulation is enough for me
I don't know if there is any simulation software for stm32..
@@ControllersTech ok, thanks for your amazingly detailed video anyway
hello I have a f401re board which timer do i connect it to ?
Timer is not used for connection. It just provides the timing for microsecond delay
Hi friend, may you make tutorial for sensor INA219 current, please
What about not positive??
Sorry how to declare the pin of the DHT11 im using STM32F446RE
Use cubemx to set the pin output.. see the video
1 st time only my code is executing 2 nd time not executed every time I am going to reset the controller in dht11 sensor
Give delay of 2-3 seconds before reading again.
Superb !
hi i am trying to run the code but i get an error in this line of code
__HAL_TIM_SET_COUNTER (& htim6,0);
I am using a stm32l051c8t6
I still can't find the problem.
Why is there space after '&'
it's like I made the comment but normally it's
__HAL_TIM_SET_COUNTER (&htim6,0);
even so the code generates an error in that line code
Have you set timer 6 in the cubemx ?
Also it would be easier if you tell what's the error
@@ControllersTech if I have configured timer 6 as is the tutorial
my problem is that in the debugger I see values of 4095.9375 for the temperature
NOTE: I have a pull UP resistor of 4k7
OHM
Does it influence when reading the DS18B20?
according to the tutorial, said resistance should not be
@@ControllersTech What about not positive measurments?? it will work with ur code? idts
hi i dont know why but when a i use dht22 , i get wrong values, humidity seems to be right but i get 102.4 as temperature which is obviously wrong any ideas?
and i need to say that im using internal clock not crystal
Are u getting consistent 102.4 ? Are the values fluctuating a little ?
You can try putting your sensor in the refrigerator for a while and then test. Check the values for both humidity and temperature..
@@mohammadrahimpoor513 Do you interpret the values right in terms of temperature measuring units?
I have problem with Temp_byte2 reading, it is constantly 0, and consequently i have incorrect temperature value. How can I fix this problem?
That will be 0 for dht11 as it doesn't give result in decimal values
code for AHT25 temp sensor using stm32f411re ????
why didnt use temp_byte2 and rh_byte2 ?
They are used in DHT22, as it gives temp and pressure in decimals.
DHT11's accuracy is upto integral values only.
Hi, how have i connect the pull up resistor to the data pin ?
Connect a 4 or 5K Resistor between the data line and VCC
@@ControllersTech Thanks for the answer
@@ControllersTech When you said "between" , do you mean a series connection ? (Sorry for the question)
images.app.goo.gl/WzuRRgL6FhTaXRMF9
@@ControllersTech Thanks
hello, i have problem with viewing the temperature and humidity after starting program lcd views initializing and then i dont se anything, i changed your timer from 6 to 1. Can u help what can i do?
The steps to debug issue are listed in the pinned comment.
If they don't work out, then i don't know
@@ControllersTech So are they ok when I use USART to replace fo LCD???
Yeah. It have nothing to do with LCD.
Hi and good job! How can I make the temperature sensor show me the data every 30 minutes or every estimated period of time... IS IT POSSIBLE? that so that I do not consume a lot of energy
You can use low power mode and set an alarm to wake the mcu after 30 min. Then perform the data read and go back to sleep/standby.
@@ControllersTech THANK YOU VERY MUCH, I WILL SEE IF I GET TO IMPLEMENT IT, SINCE THE TIMER IS NOT VERY WELL CONFIGURED IN A PERIOD OF A CERTAIN TIME
It's not the timer. You have to use RTC. Once the mcu goes into standby, timers don't work anymore. We can wake the mcu only using certain things and RTC alarm is one of them.
@@ControllersTech
AGAIN I SAY THANK YOU AND KNOW THAT WE LEARN A LOT WITH YOU
my temperature value is 0 what can i do
Excellent 👍🔥
Hey firstly thank u for your every tutorial videos. These are really useful. But i confused about this part of code
i&= ~(1
can this be used on stm32f401re?
If it has a gpio pin and a timer, then yes.
@@ControllersTech alright thank you
Thanks sir!
/Core/Src/main.c:313:9: error: conflicting types for 'DS18B20_Start'
313 | uint8_t DS18B20_Start(void)
My problem is solved( I use STM32F103C8, Timer 4). My solutions:
1. In DHT11_Start(), I change the code by:
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, 1); //Initialize with Data pin HIGH
HAL_Delay(1000);
Set_Pin_Output (DHT11_PORT, DHT11_PIN); // set the pin as output
HAL_GPIO_WritePin (DHT11_PORT, DHT11_PIN, 0); // pull the pin low
HAL_Delay(18); //wait for 18ms
HAL_GPIO_WritePin (DHT11_PORT, DHT11_PIN, 1); // pull the pin high
delay(20); //20us
Set_Pin_Input(DHT11_PORT, DHT11_PIN); // set as input
}
2. In main(), I add function HAL_TIM_Base_Start(&htim4);
{
.....
MX_GPIO_Init();
MX_I2C1_Init();
MX_TIM4_Init();
HAL_TIM_Base_Start(&htim4);
....
}
thanks for sharing
hello bạn. Bạn có thư viện i2c như trên k gửi mình vs.
gmail: laikhanhluong99@gmail.com
can you give the link for i2c.lcd .c & .h file link for stm32f103c8t6 interface with ds18b20
Link is in the description
My timer is not working. Can't you help?
What you mean by "not working" ?
debug temperature 25 Humidity 61 '=' ASCI TABLE
= how can I prevent this or why is it coming
What you want to prevent exactly ?
@@ControllersTech Why does the humidity ASCII equivalent write ?
It doesn't write anything. That's how the debugger shows the result. It shows ascii equivalent of the value
@@ControllersTech sorry my bad
Can you give me library of i2c-lcd?Thanks
Everything is on the website..
All of those who has been having trouble because of the infinite loop: With this modification it works on my case.
void MODO_SALIDA(){
RCC->AHB2ENR|=(RCC_AHB2ENR_GPIOAEN);
GPIOA->MODER |= (0
your code about ds18b20 is not working, i'm not asking you something, just tell you it's not working
controllerstech.com/wp-content/uploads/2021/06/dsbProof.jpeg
what about stm32f103c8t6 ?
What about it ?
Controllers Tech i have stm32f103c8t6 mcu i see some differences for coding operetion
No there is no difference. It works for every controller.
bro for my mcu (stm32f103c8t6) i can not see TIM6 i see only tım1,tım2,tım3,tım4 what can i do instead of that ? could you help me please ?
You can use any timer you want. Just make sure that you use the prescalar and ARR values according to your setup
can u give me the main.c
?
Link to download the project is in the description.
i had a problem that i wasn't able to solve, but then i just changed gpio_output, to gpio_input and everything works!!! In this case is the same because is one wire communication
thanks
can you give me library i2c_lcd
go to the link the description, and download from there
@@ControllersTech i'm trying add file.c in src but can't. Can you tell me about it... thanks
What ide are u using ?
@@ControllersTech thanks, i got it
But i not use #include "i2c-lcd.h" in function main. I use sm32f411VET
bạn ơi bạn có thư viện i2c cho mình ms.
gmail : laikhanhluong99@gmail.com
cám ơn bạn rất nhiều.
I tried change mode of Pin A0 from GPIO_MODE_OUTPUT_PP to GPIO_MODE_OUTPUT_OD and in DHT11_Start() function you guys can remove Set_Pin_Output and Set_Pin_Input funcion (must set PA0 to high first).
void DHT11_Start (void)
{
HAL_GPIO_WritePin (DHT11_PORT, DHT11_PIN, 0); // pull the pin low
delay (20000); // wait for >18ms
HAL_GPIO_WritePin (DHT11_PORT, DHT11_PIN, 1); // pull the pin high
delay (45); // wait for about 40us, đợi DHT11 respone
}
In DHT11_Check_Response() function remove 'delay (40)' after 'uint8_t Response = 0'. Let's try it, it works fine
Hi, have you ever try to control PT100 sensor by using stm32f103c8t6?
bạn làm theo video có chạy không
I 100% followed the video and the code but still doesn't work
then after >10 Hours of debugging, I found out it magically works well if I turned the data pin back to Reset_State
Still can't figure out why, but it works so whatever lolll
can you just fuckn share the sketch so that we can download the damn thing and see if the shit is working or not?
Goto the link in the description.
Dennis Yildirim dude chill out and be grateful and polite
I watched the video and followed all the steps properly and DHT11 sensor worked for me in 1st attempt (I am using stm32f407 discovery board), later for one project I needed to use the temp sensor with HC-SR04 sensor and 16x2 lcd without i2c driver but it was not working I checked and found out the program was getting struck, I scrolled thru the comments and saw one guy giving some suggestion @electrolabs337 (Electro Labs) was his name, His solution no 1 worked flawlessly (big thanks to him) but can anyone explain why is his solution working, I would really really like to know
the check response dos'ent work the dht22 dosnt give a low voltage so the loop continus forever any help ?
I think I have the same problem. Using DHT22 as well, but it gets stuck at the response check
Plz check the pinned comment
same problem for dht11. The code is stuch at last while which is in response function. Actually it's working only once. Can someone help ?
Is the us delay working properly ?
What's the hlck u have ?
Controllers Tech ya I tried to light up the led every single second using the us delay and it seemed to work just fine. However, it looped inside the while loop infinitely waiting for the pin to go low in check response function. I’m using an stm32f407 board and have the same setting for the hclk in the tutorial video (50MHz). I’ve checked data sheet of the DHT22 and everything in the code looks just fine accordingly. I’ve been working on this for an entire week now and have purchased several new DHT22 sensors in case the sensor is busted, but still have no clue what’s going on.. I’d greatly appreciate it if you can offer any help!