capteurs ultrasons bip sonore Stm32F4
Répondre à la discussion
Affichage des résultats 1 à 9 sur 9

capteurs ultrasons bip sonore Stm32F4



  1. #1
    safaben

    capteurs ultrasons bip sonore Stm32F4


    ------

    Bonjour,
    je suis en train de développer un programe avec 2 capteurs ultrasons hs SR04, j'ai reussi à faire fonctionner le 1ere, mais je sais pas comment je pourrai
    connecter mon 2eme capteur sachant que mon j'ai connecté mon 1ere capteur comme suit ?:
    VCC -> 5V
    GND -> GND
    Trigger -> PD3
    Echo -> PA0
    Avec 2 Timers tim2 et tim7
    je veux ansuite que mon programme m'envoie un bip sonore une fois qu'il détecte un obstacle, j'ai reussi a faire fonctiooner un capteur avec les leds mais j'arrive pas a bien recevoir un bip , comment je peux faire svp??
    Code:
    #include "main.h"
    #include "hcsr04.h"
    #include "stm32_ub_led.h"
    #include "stm32_ub_hcsr04.h"
    
    int hcsr04(void)
    {
      float abstand;
    
      SystemInit();
      
      UB_Led_Init();
    
     
      UB_HCSR04_Init();
    
      while(1)
      {
        
        distance=UB_HCSR04_Distance_cm();
    
        if(distance>0) {
          
        	WavePlayBack(I2S_AudioFreq_48k);
        	UB_Led_Off(LED_RED);
        	UB_Led_On(LED_ORANGE);
          if(distance<10.0) UB_Led_On(LED_GREEN); else UB_Led_Off(LED_GREEN);
          if(distance<15.0) UB_Led_On(LED_BLUE); else UB_Led_Off(LED_BLUE);
        }
        else {
         
        	UB_Led_On(LED_RED);
        	UB_Led_Off(LED_GREEN);
        	UB_Led_Off(LED_BLUE );
        	UB_Led_Off(LED_ORANGE);
        }
    
      }

    -----

  2. #2
    futhier9178

    Re : capteurs ultrasons bip sonore Stm32F4

    Bonjour,

    Déjà à quoi sert la variable abstand?
    Tu la déclares mais tu t'en sers pas dans la fonction.

    Et ton sous-programme manque de commentaires donc on peut pas trop t'aider il nous faut plus de précisions.

  3. #3
    safaben

    Re : capteurs ultrasons bip sonore Stm32F4

    abstand c la distance, voila j'ai corrigé mon programme , je vois que tout est c
    Code:
    #include "main.h"
    #include "hcsr04.h"
    #include "stm32_ub_led.h"
    #include "stm32_ub_hcsr04.h"
    
    int hcsr04(void)
    {
      float distance;
    
      SystemInit(); // Activer paramètres quartz
      // init LEDs
      UB_Led_Init();
    
      // init HC-SR04
      UB_HCSR04_Init();
    
      while(1)
      {
        // Mesure de la distance
        distance=UB_HCSR04_Distance_cm();
    
        if(distance>0) {
    // wavePlayBlack c la fonction qui va gerer un bip 
    
              	WavePlayBack(I2S_AudioFreq_48k);
    // LEDs commuter en fonction de la distance
    
        	UB_Led_Off(LED_RED);
        	UB_Led_On(LED_ORANGE);
          if(distance<10.0) UB_Led_On(LED_GREEN); else UB_Led_Off(LED_GREEN);
          if(distance<15.0) UB_Led_On(LED_BLUE); else UB_Led_Off(LED_BLUE);
        }
        else {
          // en dehors de la plage de mesure
        	UB_Led_On(LED_RED);
        	UB_Led_Off(LED_GREEN);
        	UB_Led_Off(LED_BLUE );
        	UB_Led_Off(LED_ORANGE);
        }
    
      }

  4. #4
    futhier9178

    Re : capteurs ultrasons bip sonore Stm32F4

    A mon avis les LEDs bleue verte et orange s'allument.
    Vérifies la valeur de distance au debugger.

  5. A voir en vidéo sur Futura
  6. #5
    safaben

    Re : capteurs ultrasons bip sonore Stm32F4

    oui ils s'allument, mais mon problème c'est pas avec les leds, c avec le bip sonore ne marche pas comme je voudrai,
    je veux au lieu d'allumer les leds, mon programme m'envoie un bip sonore seulement un et il doit s’arrêter, comment je peux integerer la fonction WavePlayBack(uint32_t AudioFreq), j'ai l'a met au lieu de UB_Led_On mais le probleme que le bip ne s'arrete , le programme me donne une longue duée de bip svp aidez moi c pour mon projet d'étude .
    voila le programme de waveplayer:
    Code:
    /**
      
    
    /* Includes ------------------------------------------------------------------*/
    #include "main.h"
    
    /** @addtogroup STM32F4-Discovery_Audio_Player_Recorder
    * @{
    */ 
    
    /* Private define ------------------------------------------------------------*/
    
     /* This is an audio file stored in the Flash memory as a constant table of 16-bit data.
        The audio format should be WAV (raw / PCM) 16-bits, Stereo (sampling rate may be modified) */
    extern uint16_t AUDIO_SAMPLE[];
    /* Audio file size and start address are defined here since the audio file is 
        stored in Flash memory as a constant table of 16-bit data */
    #define AUDIO_FILE_SZE          442156//990000
    #define AUIDO_START_ADDRESS     0//58 /* Offset relative to audio file header size */
    
    
    /* Private macro -------------------------------------------------------------*/
    /* Private variables ---------------------------------------------------------*/
    
    __IO uint8_t volume = 100, AudioPlayStart = 0;
    extern __IO uint8_t RepeatState ;
    //extern __IO uint8_t LED_Toggle;
    extern __IO uint8_t PauseResumeStatus ;
    static __IO uint32_t TimingDelay;
    
    /* Private functions ---------------------------------------------------------*/
    
    /**
      * @brief  Play wave from a mass storge
      * @param  AudioFreq: Audio Sampling Frequency
      * @retval None
    */
    
    void WavePlayBack(uint32_t AudioFreq)
    { 
      /* 
      Normal mode description:
      Start playing the audio file (using DMA stream) .
      Using this mode, the application can run other tasks in parallel since 
      the DMA is handling the Audio Transfer instead of the CPU.
      The only task remaining for the CPU will be the management of the DMA 
      Transfer Complete interrupt or the Half Transfer Complete interrupt in 
      order to load again the buffer and to calculate the remaining data.  
      Circular mode description:
      Start playing the file from a circular buffer, once the DMA is enabled it 
      always run. User has to fill periodically the buffer with the audio data 
      using Transfer complete and/or half transfer complete interrupts callbacks 
      (EVAL_AUDIO_TransferComplete_CallBack() or EVAL_AUDIO_HalfTransfer_CallBack()...
      In this case the audio data file is smaller than the DMA max buffer 
      size 65535 so there is no need to load buffer continuously or manage the 
      transfer complete or Half transfer interrupts callbacks. */  
      
      /* Start playing */
      AudioPlayStart = 1;
      RepeatState = 0;
      
      /* Initialize wave player (Codec, DMA, I2C) */
      WavePlayerInit(AudioFreq);
      
      /* Play on */
      AudioFlashPlay((uint16_t*)(AUDIO_SAMPLE + AUIDO_START_ADDRESS),AUDIO_FILE_SZE,AUIDO_START_ADDRESS);
      
      /* LED Blue Start toggling */
    //  LED_Toggle = 6;
      
      /* Infinite loop */
    
     // while(1)
     // {
        /* check on the repeate status */
        if (RepeatState == 0)
        {
          if (PauseResumeStatus == 0)
          {
            /* LED Blue Stop Toggling */
      //      LED_Toggle = 0;
            /* Pause playing */
            WavePlayerPauseResume(PauseResumeStatus);
            PauseResumeStatus = 2;
          }
          else if (PauseResumeStatus == 1)
          {
            /* LED Blue Toggling */
        //    LED_Toggle = 6;
            /* Resume playing */
            WavePlayerPauseResume(PauseResumeStatus);
            PauseResumeStatus = 2;
         }
        }
        else
        {
          /* Stop playing */
          WavePlayerStop();
          /* Green LED toggling */
      //    LED_Toggle = 4;
        }
      //}
    }
    /**
      * @brief  Pause or Resume a played wave
      * @param  state: if it is equal to 0 pause Playing else resume playing
      * @retval None
      */
    void WavePlayerPauseResume(uint8_t state)
    { 
      EVAL_AUDIO_PauseResume(state);   
    }
    
    /**
      * @brief  Configure the volune
      * @param  vol: volume value
      * @retval None
      */
    uint8_t WaveplayerCtrlVolume(uint8_t vol)
    { 
      EVAL_AUDIO_VolumeCtl(vol);
      return 0;
    }
    /**
      * @brief  Stop playing wave
      * @param  None
      * @retval None
      */
    void WavePlayerStop(void)
    { 
      EVAL_AUDIO_Stop(CODEC_PDWN_SW);
    }
    /**
    * @brief  Initializes the wave player
    * @param  AudioFreq: Audio sampling frequency
    * @retval None
    */
    int WavePlayerInit(uint32_t AudioFreq)
    {
      /* Initialize I2S interface */  
      EVAL_AUDIO_SetAudioInterface(AUDIO_INTERFACE_I2S);
      
      /* Initialize the Audio codec and all related peripherals (I2S, I2C, IOExpander, IOs...) */  
      EVAL_AUDIO_Init(OUTPUT_DEVICE_AUTO, volume, AudioFreq );  
      
      return 0;
    }
    /**
      * @brief  MEMS accelerometre management of the timeout situation.
      * @param  None.
      * @retval None.
      */
    uint32_t LIS302DL_TIMEOUT_UserCallback(void)
    {
      /* MEMS Accelerometer Timeout error occured */
      while (1)
      {   
      }
    }
    /**
    * @brief  Play wave file from internal Flash
    * @param  None
    * @retval None
    */
    uint32_t AudioFlashPlay(uint16_t* pBuffer, uint32_t FullSize, uint32_t StartAdd)
    { 
      EVAL_AUDIO_Play((uint16_t*)pBuffer, (FullSize - StartAdd));
      return 0;
    }
    /*--------------------------------
    Callbacks implementation:
    the callbacks prototypes are defined in the stm324xg_eval_audio_codec.h file
    and their implementation should be done in the user code if they are needed.
    Below some examples of callback implementations.
    --------------------------------------------------------*/
    /**
    * @brief  Calculates the remaining file size and new position of the pointer.
    * @param  None
    * @retval None
    */
    void EVAL_AUDIO_TransferComplete_CallBack(uint32_t pBuffer, uint32_t Size)
    {
      /* Calculate the remaining audio data in the file and the new size 
      for the DMA transfer. If the Audio files size is less than the DMA max 
      data transfer size, so there is no calculation to be done, just restart 
      from the beginning of the file ... */
      /* Check if the end of file has been reached */
      
    #ifdef AUDIO_MAL_MODE_NORMAL  
    
    #if defined PLAY_REPEAT_OFF
      LED_Toggle = 4;
      RepeatState = 1;
      EVAL_AUDIO_Stop(CODEC_PDWN_HW);
    #else
      /* Replay from the beginning */
      AudioFlashPlay((uint16_t*)(AUDIO_SAMPLE + AUIDO_START_ADDRESS),AUDIO_FILE_SZE,AUIDO_START_ADDRESS);
    #endif  
    
      
    #endif /* AUDIO_MAL_MODE_CIRCULAR */
    }
    /**
    * @brief  Manages the DMA Half Transfer complete interrupt.
    * @param  None
    * @retval None
    */
    void EVAL_AUDIO_HalfTransfer_CallBack(uint32_t pBuffer, uint32_t Size)
    {  
    #ifdef AUDIO_MAL_MODE_CIRCULAR
        
    #endif /* AUDIO_MAL_MODE_CIRCULAR */
      
      /* Generally this interrupt routine is used to load the buffer when 
      a streaming scheme is used: When first Half buffer is already transferred load 
      the new data to the first half of buffer while DMA is transferring data from 
      the second half. And when Transfer complete occurs, load the second half of 
      the buffer while the DMA is transferring from the first half ... */
      /* 
      ...........
      */
    }
    /**
    * @brief  Manages the DMA FIFO error interrupt.
    * @param  None
    * @retval None
    */
    void EVAL_AUDIO_Error_CallBack(void* pData)
    {
      /* Stop the program with an infinite loop */
      while (1)
      {}
      
      /* could also generate a system reset to recover from the error */
      /* .... */
    }
    /**
    * @brief  Get next data sample callback
    * @param  None
    * @retval Next data sample to be sent
    */
    uint16_t EVAL_AUDIO_GetSampleCallBack(void)
    {
      return 0;
    }
    
    #ifndef USE_DEFAULT_TIMEOUT_CALLBACK
    /**
      * @brief  Basic management of the timeout situation.
      * @param  None.
      * @retval None.
      */
    uint32_t Codec_TIMEOUT_UserCallback(void)
    {   
      return (0);
    }
    #endif /* USE_DEFAULT_TIMEOUT_CALLBACK */
    
    /*----------------------------------------------------------------------------*/
    /**
      * @brief  Inserts a delay time.
      * @param  nTime: specifies the delay time length, in 10 ms.
      * @retval None
      */
    void Delay(__IO uint32_t nTime)
    {
      TimingDelay = nTime;
      
      while(TimingDelay != 0);
    }
    /**
      * @brief  Decrements the TimingDelay variable.
      * @param  None
      * @retval None
      */
    void TimingDelay_Decrement(void)
    {
      if (TimingDelay != 0x00)
      { 
        TimingDelay--;
      }
    }
    
    #ifdef  USE_FULL_ASSERT
    
    /**
    * @brief  Reports the name of the source file and the source line number
    *   where the assert_param error has occurred.
    * @param  file: pointer to the source file name
    * @param  line: assert_param error line source number
    * @retval None
    */
    void assert_failed(uint8_t* file, uint32_t line)
    { 
      /* User can add his own implementation to report the file name and line number,
      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
      
      /* Infinite loop */
      while (1)
      {
      }
    }
    #endif
    
    /**
    * @}
    */ 
    
    
    /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
    Dernière modification par safaben ; 14/05/2014 à 10h05.

  7. #6
    futhier9178

    Re : capteurs ultrasons bip sonore Stm32F4

    Si tu regardes bien le sous programme du début, tu as mis une boucle infinie dans laquelle tu dis si distance>0 faire un bip. C'est là que tu dois adapter ta fonction pour arrêter le bip.

  8. #7
    safaben

    Re : capteurs ultrasons bip sonore Stm32F4

    Vous pouvez m'expliquer , j'ai pas compris comment ? qu'est je dois changer ?

    Code:
    while(1)
      {
        // Mesure de la distance
        distance=UB_HCSR04_Distance_cm();
    
        if(distance>0) {
    // wavePlayBlack c la fonction qui va gerer un bip 
    
              	WavePlayBack(I2S_AudioFreq_48k);
    // LEDs commuter en fonction de la distance
    
        	UB_Led_Off(LED_RED);
        	UB_Led_On(LED_ORANGE);
          if(distance<10.0) UB_Led_On(LED_GREEN); else UB_Led_Off(LED_GREEN);
          if(distance<15.0) UB_Led_On(LED_BLUE); else UB_Led_Off(LED_BLUE);
        }
        else {
          // en dehors de la plage de mesure
        	UB_Led_On(LED_RED);
        	UB_Led_Off(LED_GREEN);
        	UB_Led_Off(LED_BLUE );
        	UB_Led_Off(LED_ORANGE);
        }
    
      }

  9. #8
    futhier9178

    Re : capteurs ultrasons bip sonore Stm32F4

    distance>0 donc le bip sonnera toujours.
    Et pourtant j'ai pas compilé le programme.

  10. #9
    AminaCH

    Re : capteurs ultrasons bip sonore Stm32F4

    Bonsoir! SVP pouvez -vous m'aider comment t'as utilisé les TIMER ??

Discussions similaires

  1. Capteurs ultrasons
    Par invitee44a6835 dans le forum Électronique
    Réponses: 6
    Dernier message: 22/01/2013, 15h02
  2. Câblage capteurs à ultrasons et capteurs de proximités.
    Par invite2cc824b3 dans le forum Électronique
    Réponses: 6
    Dernier message: 24/11/2011, 19h36
  3. Capteurs inductifs vs capteurs potentiométriques
    Par invite9d252634 dans le forum Électronique
    Réponses: 3
    Dernier message: 09/08/2011, 21h33
  4. Réponses: 4
    Dernier message: 06/06/2010, 20h55
  5. recheche sur les capteurs numériques et les capteurs communicants
    Par invite411fccf2 dans le forum Technologies
    Réponses: 0
    Dernier message: 28/09/2006, 10h29
Dans la rubrique Tech de Futura, découvrez nos comparatifs produits sur l'informatique et les technologies : imprimantes laser couleur, casques audio, chaises gamer...