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
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 75

  • @noweare1
    @noweare1 4 ปีที่แล้ว

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

  • @satishm4635
    @satishm4635 4 ปีที่แล้ว

    Thanks man! Great video

  • @eduardodelarosaferrer2205
    @eduardodelarosaferrer2205 4 ปีที่แล้ว +1

    Perfect again !!

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

  • @Pushpam1995
    @Pushpam1995 3 ปีที่แล้ว

    Keep making these kind of videos

  • @Vinh_EPCB
    @Vinh_EPCB 3 ปีที่แล้ว

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

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

  • @user-jh8uq6jb4v
    @user-jh8uq6jb4v 3 ปีที่แล้ว

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

  • @minayakarimova
    @minayakarimova 3 ปีที่แล้ว

    Huge thanks

  • @kennygomez3291
    @kennygomez3291 4 ปีที่แล้ว +9

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

  • @nsanandkumarak
    @nsanandkumarak 2 ปีที่แล้ว

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

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

  • @theraja011
    @theraja011 4 ปีที่แล้ว +1

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

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

  • @DuyNguyen-ty4uk
    @DuyNguyen-ty4uk 2 ปีที่แล้ว

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

  • @minhcongho3639
    @minhcongho3639 3 ปีที่แล้ว +1

    how to multiple input capture channels

  • @aniketsubudhi2260
    @aniketsubudhi2260 ปีที่แล้ว

    WHERE should i use the file lcd_userConf?

  • @monsieurovni5740
    @monsieurovni5740 3 ปีที่แล้ว

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

  • @viethuynhquoc4049
    @viethuynhquoc4049 3 ปีที่แล้ว

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

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

  • @hanilam3389
    @hanilam3389 2 ปีที่แล้ว +1

    where is PA9 used in the code?

  • @shreyakaria8761
    @shreyakaria8761 ปีที่แล้ว +3

    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?

  • @jay16myv.
    @jay16myv. 3 ปีที่แล้ว

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

  • @akshadawaghmode6550
    @akshadawaghmode6550 หลายเดือนก่อน

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

  • @mateusz809
    @mateusz809 หลายเดือนก่อน

    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!

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

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

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

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

    • @ControllersTech
      @ControllersTech  3 ปีที่แล้ว

      Try changing the data type of distance

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

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

  • @truongho2771
    @truongho2771 ปีที่แล้ว

    TIMX global interrupt consists of TIM capture compare interrupts ?

    • @ControllersTech
      @ControllersTech  ปีที่แล้ว

      If its not given separately, then yes.

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

  • @Levi.6570
    @Levi.6570 หลายเดือนก่อน

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

    • @ControllersTech
      @ControllersTech  22 วันที่ผ่านมา

      That is up to you to decide.

  • @EmbeddedProfile
    @EmbeddedProfile 3 วันที่ผ่านมา

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

    • @ControllersTech
      @ControllersTech  3 วันที่ผ่านมา +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 3 วันที่ผ่านมา

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

  • @anhtaio4128
    @anhtaio4128 3 ปีที่แล้ว

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

    • @ControllersTech
      @ControllersTech  3 ปีที่แล้ว

      You might have a fake mcu. Check the video below and see @johan comment
      th-cam.com/video/e_NSqz5P8Qk/w-d-xo.html

    • @self-studyelectronicengine7294
      @self-studyelectronicengine7294 3 ปีที่แล้ว

      Please instal driver of ST Link on ST website

  • @farhanamin4075
    @farhanamin4075 2 ปีที่แล้ว

    where is the i2c-lcd libraries come from

    • @aniketsubudhi2260
      @aniketsubudhi2260 ปีที่แล้ว

      same question sir, please can you reply

    • @ControllersTech
      @ControllersTech  ปีที่แล้ว

      Check out this, you will understand
      th-cam.com/video/WAGLQOIHEio/w-d-xo.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?

  • @sekoutounkara243
    @sekoutounkara243 3 ปีที่แล้ว +2

    im not getting any value at all ...

    • @Fabio-211
      @Fabio-211 ปีที่แล้ว +1

      me too...

    • @EmbeddedProfile
      @EmbeddedProfile 2 วันที่ผ่านมา

      Try to check the alimentation pin