Hello! I have STM32 Nucleo L476RG. If you have problem like me that sensor doesn't measure anything or LCD is bombarded by random numbers here is solution, which worked for me. 1. Change these lines in your code to this: #define TRIG_PIN GPIO_PIN_9 #define TRIG_PORT GPIOA According to this video, TRIG should be connected do PA9 and ECHO to PA8. Remember that TRIG should be as GPIO_Output. On pin PA8 (to which is connected ECHO) you should make TIMER and enable option Input Capture mode. 2. Make sure that sensor is connected to 5 V DC. 3. Add this function to properly display values on your LCD: void lcd_display_distance(uint8_t distance) { char buffer[16]; sprintf(buffer, "Distance: %d cm", distance); lcd_clear(); lcd_put_cur(0, 0); lcd_send_string(buffer); } 4. Make sure you add these lines in main: MX_TIM1_Init(); MX_I2C1_Init(); /* USER CODE BEGIN 2 */ lcd_init(); HAL_TIM_IC_Start_IT(&htim1, TIM_CHANNEL_1); lcd_send_string ("Dist= "); 5. In while make sure you have: HCSR04_Read(); HAL_Delay(200); And add this line too: lcd_display_distance(Distance); That's all worked for me. I hope that this comment will help you. Greetings!
hey, there are two problems: 1. When the LCD reaches number more than 9 it shows A, how can I fix it? 2. The ultrasonic sensor fakes the distance measurement by 3 or 4 centimeters, do you have a solution for this?
@@ControllersTech Thanks, it worked. However, I have one more question. What is the maximum speed of reading the sensor? It seems that if I reduce HAL Delay to less than 15 miliseconds, callback does not return correct values.
@@ControllersTech Also, when I'm using the other timer for PWM signal, it somehow interferes with sensor and the results fluctuate depending on pwm signal
hi, thanks for this code But I think this code has problem you define PA8 as trig pin but put it on wrong way to use I try this code on my micro and change PA8 to PA9 as trig and coxe work it as well
if i want to set a random number of the lcd, like push a button and save that value to calculate other values... You have a video to do that thing? PD: Great video :3
Good video. I have a question. If I have a signal coming at 65 Hz, at what speed should I set the timer2 to read that signal in input capture mode. Thanks.
hello may i ask what will be the distance value,i mean if the actual distance was 100cm ,the distacne variable value will be (int)100 or something else?
Hi, I followed your instruction but got this error message"CM4 Failed to read all registers FAILED to REGISTER Values from the target Debugger connection lost. Shutting down..." Do you know any way to solve this? I've tried every method I could come up with...
Use another timer for it. In the Input capture callback function, perform the check which timer called the interrupt. If (htim->Instance == TIM1) { write the entire code here} else if (htim->Instance == TIM2) {Write entire code here again} Also define new set of variables( IC_VAL, difference etc..) for second sensor.
@@ControllersTech ok done...I had integrated your data logger video and had build it with 0 error but when debug, failed to start GDB server...reason (4) no device found on target appeared
Here ultrasound module produces the output pulse, which we read using the mcu and calculate the distance. We are not producing the ultrasound here. Ultrasound is being used by the sensor to calculate the distance of the object in front of it.
The pin A9 is connected to the Trig but in the main you define the A8 as Trig pin, I think it was a little confusion.
Great video!!
I wonder how it work...
Hello!
I have STM32 Nucleo L476RG. If you have problem like me that sensor doesn't measure anything or LCD is bombarded by random numbers here is solution, which worked for me.
1. Change these lines in your code to this:
#define TRIG_PIN GPIO_PIN_9
#define TRIG_PORT GPIOA
According to this video, TRIG should be connected do PA9 and ECHO to PA8. Remember that TRIG should be as GPIO_Output. On pin PA8 (to which is connected ECHO) you should make TIMER and enable option Input Capture mode.
2. Make sure that sensor is connected to 5 V DC.
3. Add this function to properly display values on your LCD:
void lcd_display_distance(uint8_t distance) {
char buffer[16];
sprintf(buffer, "Distance: %d cm", distance);
lcd_clear();
lcd_put_cur(0, 0);
lcd_send_string(buffer);
}
4. Make sure you add these lines in main:
MX_TIM1_Init();
MX_I2C1_Init();
/* USER CODE BEGIN 2 */
lcd_init();
HAL_TIM_IC_Start_IT(&htim1, TIM_CHANNEL_1);
lcd_send_string ("Dist= ");
5. In while make sure you have:
HCSR04_Read();
HAL_Delay(200);
And add this line too:
lcd_display_distance(Distance);
That's all worked for me. I hope that this comment will help you.
Greetings!
Excellent as always. I like the way you converted decimal to ascii. Thank you.
Excellent video!! I tried this with my STM, the data is captured once and can only be updated when reset button is pressed, what to do?
the same
hey, there are two problems:
1. When the LCD reaches number more than 9 it shows A, how can I fix it?
2. The ultrasonic sensor fakes the distance measurement by 3 or 4 centimeters, do you have a solution for this?
Hello! I like this video, to easy for learn. I make universal lib for any STM microcontroller. Big thanks!
If the distance if greater than 127 it Distance variable becomes negative number. How should I fix this?
Try changing the data type of distance
@@ControllersTech Thanks, it worked. However, I have one more question. What is the maximum speed of reading the sensor? It seems that if I reduce HAL Delay to less than 15 miliseconds, callback does not return correct values.
@@ControllersTech Also, when I'm using the other timer for PWM signal, it somehow interferes with sensor and the results fluctuate depending on pwm signal
where is PA9 used in the code?
thank you! I did it with stm32f4
hi there, can i know how you do it with stm32f4?
For me we did not get the output can you please tell me the problem once
hi, thanks for this code
But I think this code has problem
you define PA8 as trig pin but put it on wrong way to use I try this code on my micro and change PA8 to PA9 as trig and coxe work it as well
I'll see it. Maybe i have used the pin name directly somewhere..
@@ControllersTech thanks for mention
why can't I display the distance value on lcd16x2.
if i want to set a random number of the lcd, like push a button and save that value to calculate other values... You have a video to do that thing?
PD: Great video :3
is the header file of i2c is same for STM32F466RE? and i can't find your i2c header file. please help me...
Thanks man! Great video
can you explain for me ?
else if (IC_Val2
It's to compensate the overflow. Ic val2 can only be less than icval1, only if there is overflow
Distance is jumping rarely. I take an object 2 m away from the sensor, but it shows rarely bad value. What is the mistake?
Try changing the data type of distance
Good video. I have a question. If I have a signal coming at 65 Hz, at what speed should I set the timer2 to read that signal in input capture mode. Thanks.
Somewhat in kilohertz would work
how to multiple input capture channels
I have a question, if we apply to real life, what is the purpose of this project/
That is up to you to decide.
hello may i ask what will be the distance value,i mean if the actual distance was 100cm ,the distacne variable value will be (int)100 or something else?
It should be 100.
Great job! But why would it not be possible to use HAL_delay() instead of delay() in HCSR04_Read() ?
01:40
Keep making these kind of videos
Hi, I followed your instruction but got this error message"CM4 Failed to read all registers
FAILED to REGISTER Values from the target
Debugger connection lost.
Shutting down..." Do you know any way to solve this? I've tried every method I could come up with...
What does this have to do with the instructions ?
This is your hardware issue...
Hello, is there a tutorial for LCD communication? I don't know how to connect the LCD to STM32. Thank you.
Look in the stm32 playlist
I dont use lcd, how can i show distance on watch1
Hi, Grt. Pls share tutorial on EEPROM Emulation on STM32F103C8T6 flash memory (Ref cd00165693) HAL Lib is there. thx
TIMX global interrupt consists of TIM capture compare interrupts ?
If its not given separately, then yes.
Perfect again !!
WHERE should i use the file lcd_userConf?
Hello, i have some problem with TCS3200, can you make a project about it. Thanks very much. I'm from Vietnam
Hi Sir,
Can you please make video on Timer Tigger source and usage of it
How to add a second ultrasonic sensor to this work please ?
Use another timer for it.
In the Input capture callback function, perform the check which timer called the interrupt.
If (htim->Instance == TIM1)
{ write the entire code here}
else if (htim->Instance == TIM2)
{Write entire code here again}
Also define new set of variables( IC_VAL, difference etc..) for second sensor.
@@ControllersTechI did this but one sensor works fine but the second one give juste one correct value and stop working
Huge thanks
how to edit the coding by not using lcd monitor? i'm using teamspeak to display the distance
just remove the LCD part
@@ControllersTech ok done...I had integrated your data logger video and had build it with 0 error but when debug, failed to start GDB server...reason (4) no device found on target appeared
Can you send i2c-lcd .h and .c files?
Error in initializing ST-LINK device.
Reason: ST-LINK: Could not verify ST device! Abort connection.
Help me pro?
You might have a fake mcu. Check the video below and see @johan comment
ruclips.net/video/e_NSqz5P8Qk/видео.html
Please instal driver of ST Link on ST website
im not getting any value at all ...
me too...
Try to check the alimentation pin
where is the i2c-lcd libraries come from
same question sir, please can you reply
Check out this, you will understand
ruclips.net/video/WAGLQOIHEio/видео.html
What is the input frequency ??? Plz reply
Input frequency of what ?
Input frequency of Ultrasonic sensor
And btw can u tell me how much frequency we need to give to produce 25khz ultrasonic sound??
Here ultrasound module produces the output pulse, which we read using the mcu and calculate the distance.
We are not producing the ultrasound here. Ultrasound is being used by the sensor to calculate the distance of the object in front of it.
@@ControllersTech yeah but if u don't mind can u tell me about what frequency i can give to generate 25khz ultrasonic sound in transducer?