HCSR04 and STM32 using Input Capture || Pulse width || CubeIDE
ฝัง
- เผยแพร่เมื่อ 23 ก.ค. 2024
- Purchase the Products shown in this video from :: controllerstech.store
________________________________________________________________________________________
Interface HCSR04 with STM32 using the Timer Input Capture Mode.
This method overcomes the errors that you were getting with the older method
Create delay in microseconds STM32 ====} • How to create delay in...
Input Capture in STM32 ====} • STM32 TIMERS #4. INPUT...
To DOWNLAOD the code goto controllerstech.com/hcsr04-ul...
Check out more VIDEOS on MODULES/SENSORS with STM32 • STM32 and SENSORS/MODULES
________________________________________________________________________________________
****** SUPPORT US BY DONATING*****
paypal.me/controllertech
******Join the Membership******
/ @controllerstech
Join the Discord Server / discord
Join the Telegram Group t.me/controllerstechdiscuss
Follow me on Instagram / controllerstech
For more info, visit www.controllerstech.com - วิทยาศาสตร์และเทคโนโลยี
Excellent as always. I like the way you converted decimal to ascii. Thank you.
Thanks man! Great video
Perfect again !!
Hello! I like this video, to easy for learn. I make universal lib for any STM microcontroller. Big thanks!
Keep making these kind of videos
why can't I display the distance value on lcd16x2.
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?
is the header file of i2c is same for STM32F466RE? and i can't find your i2c header file. please help me...
Huge thanks
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...
Hi Sir,
Can you please make video on Timer Tigger source and usage of it
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
Hi, Grt. Pls share tutorial on EEPROM Emulation on STM32F103C8T6 flash memory (Ref cd00165693) HAL Lib is there. thx
thank you! I did it with stm32f4
hi there, can i know how you do it with stm32f4?
I dont use lcd, how can i show distance on watch1
how to multiple input capture channels
WHERE should i use the file lcd_userConf?
Great job! But why would it not be possible to use HAL_delay() instead of delay() in HCSR04_Read() ?
01:40
Hello, i have some problem with TCS3200, can you make a project about it. Thanks very much. I'm from Vietnam
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
where is PA9 used in the code?
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
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
Can you send i2c-lcd .h and .c files?
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!
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
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 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.
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
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
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
TIMX global interrupt consists of TIM capture compare interrupts ?
If its not given separately, then yes.
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
I have a question, if we apply to real life, what is the purpose of this project/
That is up to you to decide.
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
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
th-cam.com/video/e_NSqz5P8Qk/w-d-xo.html
Please instal driver of ST Link on ST website
where is the i2c-lcd libraries come from
same question sir, please can you reply
Check out this, you will understand
th-cam.com/video/WAGLQOIHEio/w-d-xo.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?
im not getting any value at all ...
me too...
Try to check the alimentation pin