HCSR04 and STM32 using Input Capture || Pulse width || CubeIDE

Поделиться
HTML-код
  • Опубликовано: 15 сен 2024

Комментарии • 76

  • @kennygomez3291
    @kennygomez3291 4 года назад +10

    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!!

  • @mateusz809
    @mateusz809 3 месяца назад +1

    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!

  • @noweare1
    @noweare1 4 года назад

    Excellent as always. I like the way you converted decimal to ascii. Thank you.

  • @shreyakaria8761
    @shreyakaria8761 Год назад +4

    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?

  • @dorstern245
    @dorstern245 Год назад

    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?

  • @tupoy_ytub_uberi_psevdonim
    @tupoy_ytub_uberi_psevdonim Год назад

    Hello! I like this video, to easy for learn. I make universal lib for any STM microcontroller. Big thanks!

  • @siurpussiurpuliukas598
    @siurpussiurpuliukas598 3 года назад +2

    If the distance if greater than 127 it Distance variable becomes negative number. How should I fix this?

    • @ControllersTech
      @ControllersTech  3 года назад

      Try changing the data type of distance

    • @siurpussiurpuliukas598
      @siurpussiurpuliukas598 3 года назад

      @@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.

    • @siurpussiurpuliukas598
      @siurpussiurpuliukas598 3 года назад

      @@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

  • @hanilam3389
    @hanilam3389 2 года назад +1

    where is PA9 used in the code?

  • @nguyennguyenvu8212
    @nguyennguyenvu8212 4 года назад +2

    thank you! I did it with stm32f4

    • @haziqizzat3558
      @haziqizzat3558 3 года назад

      hi there, can i know how you do it with stm32f4?

    • @MamidipalliBujji
      @MamidipalliBujji 17 дней назад

      For me we did not get the output can you please tell me the problem once

  • @self-studyelectronicengine7294
    @self-studyelectronicengine7294 3 года назад +2

    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

  • @Vinh_EPCB
    @Vinh_EPCB 3 года назад

    why can't I display the distance value on lcd16x2.

  • @misterjacqwelll
    @misterjacqwelll 3 года назад +1

    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

  • @பொத்தகம்
    @பொத்தகம் 3 года назад

    is the header file of i2c is same for STM32F466RE? and i can't find your i2c header file. please help me...

  • @satishm4635
    @satishm4635 4 года назад

    Thanks man! Great video

  • @thophamngoc7178
    @thophamngoc7178 3 года назад

    can you explain for me ?
    else if (IC_Val2

    • @ControllersTech
      @ControllersTech  3 года назад +1

      It's to compensate the overflow. Ic val2 can only be less than icval1, only if there is overflow

  • @davidbalog1014
    @davidbalog1014 3 года назад

    Distance is jumping rarely. I take an object 2 m away from the sensor, but it shows rarely bad value. What is the mistake?

  • @lorenefields2838
    @lorenefields2838 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.

  • @minhcongho3639
    @minhcongho3639 3 года назад +1

    how to multiple input capture channels

  • @Levi.6570
    @Levi.6570 2 месяца назад

    I have a question, if we apply to real life, what is the purpose of this project/

  • @user-dh1ye1wc3g
    @user-dh1ye1wc3g Год назад

    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?

  • @monsieurovni5740
    @monsieurovni5740 3 года назад

    Great job! But why would it not be possible to use HAL_delay() instead of delay() in HCSR04_Read() ?

  • @Pushpam1995
    @Pushpam1995 4 года назад

    Keep making these kind of videos

  • @jennyshaio463
    @jennyshaio463 3 года назад

    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...

    • @ControllersTech
      @ControllersTech  3 года назад

      What does this have to do with the instructions ?
      This is your hardware issue...

  • @jay16myv.
    @jay16myv. 3 года назад

    Hello, is there a tutorial for LCD communication? I don't know how to connect the LCD to STM32. Thank you.

  • @DuyNguyen-ty4uk
    @DuyNguyen-ty4uk 2 года назад

    I dont use lcd, how can i show distance on watch1

  • @theraja011
    @theraja011 4 года назад +1

    Hi, Grt. Pls share tutorial on EEPROM Emulation on STM32F103C8T6 flash memory (Ref cd00165693) HAL Lib is there. thx

  • @truongho2771
    @truongho2771 2 года назад

    TIMX global interrupt consists of TIM capture compare interrupts ?

  • @eduardodelarosaferrer2205
    @eduardodelarosaferrer2205 4 года назад +1

    Perfect again !!

  • @aniketsubudhi2260
    @aniketsubudhi2260 2 года назад

    WHERE should i use the file lcd_userConf?

  • @viethuynhquoc4049
    @viethuynhquoc4049 3 года назад

    Hello, i have some problem with TCS3200, can you make a project about it. Thanks very much. I'm from Vietnam

  • @nsanandkumarak
    @nsanandkumarak 2 года назад

    Hi Sir,
    Can you please make video on Timer Tigger source and usage of it

  • @EmbeddedProfile
    @EmbeddedProfile Месяц назад

    How to add a second ultrasonic sensor to this work please ?

    • @ControllersTech
      @ControllersTech  Месяц назад +1

      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.

    • @EmbeddedProfile
      @EmbeddedProfile Месяц назад

      ​​@@ControllersTechI did this but one sensor works fine but the second one give juste one correct value and stop working

  • @minayakarimova
    @minayakarimova 3 года назад

    Huge thanks

  • @vikneswaranrajandaran6588
    @vikneswaranrajandaran6588 3 года назад

    how to edit the coding by not using lcd monitor? i'm using teamspeak to display the distance

    • @ControllersTech
      @ControllersTech  3 года назад

      just remove the LCD part

    • @vikneswaranrajandaran6588
      @vikneswaranrajandaran6588 3 года назад

      @@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

  • @akshadawaghmode6550
    @akshadawaghmode6550 3 месяца назад

    Can you send i2c-lcd .h and .c files?

  • @anhtaio4128
    @anhtaio4128 4 года назад

    Error in initializing ST-LINK device.
    Reason: ST-LINK: Could not verify ST device! Abort connection.
    Help me pro?

    • @ControllersTech
      @ControllersTech  4 года назад

      You might have a fake mcu. Check the video below and see @johan comment
      ruclips.net/video/e_NSqz5P8Qk/видео.html

    • @self-studyelectronicengine7294
      @self-studyelectronicengine7294 3 года назад

      Please instal driver of ST Link on ST website

  • @sekoutounkara243
    @sekoutounkara243 3 года назад +2

    im not getting any value at all ...

  • @farhanamin4075
    @farhanamin4075 2 года назад

    where is the i2c-lcd libraries come from

    • @aniketsubudhi2260
      @aniketsubudhi2260 2 года назад

      same question sir, please can you reply

    • @ControllersTech
      @ControllersTech  2 года назад

      Check out this, you will understand
      ruclips.net/video/WAGLQOIHEio/видео.html

  • @therubrat
    @therubrat Год назад

    What is the input frequency ??? Plz reply

    • @ControllersTech
      @ControllersTech  Год назад

      Input frequency of what ?

    • @therubrat
      @therubrat Год назад

      Input frequency of Ultrasonic sensor

    • @therubrat
      @therubrat Год назад

      And btw can u tell me how much frequency we need to give to produce 25khz ultrasonic sound??

    • @ControllersTech
      @ControllersTech  Год назад

      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.

    • @therubrat
      @therubrat Год назад

      @@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?