Understand the way to use HC-SRF04 on STM32 (Nucleo board)

Dependencies:   SRF05 mbed

main.cpp

Committer:
emcu
Date:
2018-01-02
Revision:
0:99c5f79155a6

File content as of revision 0:99c5f79155a6:


/*

 By: www.emcu.eu
 Date: Jan 2018
 Simple program to read the distance from an SRF04 using the SRF05 library,
 the results are send to the PC.
 On PC I suggest to use TeraTerm and the configuration is: 
 9600 bauds, 8-bit data, no parity
 
 NOTE: more info are here: http://www.emcu.eu/understand-the-way-to-use-hc-srf04-on-stm32-nucleo-board-and-mbed/
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/


#include "mbed.h"
#include "SRF05.h"

SRF05 srf04_F(PC_7, PB_6); // ECHO (pin.9), TRIG (pin.10)
// SRF05 srf04_D(PA_8, PA_8); // ECHO (pin.7), TRIG (pin.10)

//------------------------------------
// Hyperterminal configuration
// 9600 bauds, 8-bit data, no parity
//------------------------------------
Serial pc(SERIAL_TX, SERIAL_RX);
 
int main() 
{ 
pc.printf("\n\r\n\r By www.emcu.eu \n\r");
     while(1) 
     { 
        pc.printf("\n\r\n\r Distance_F = %.1f \n\r", srf04_F.read());
        // pc.printf("\n\r\n\r Distance_F = %.1f - Distance_D = %.1f\n\r", srf04_F.read(), srf04_D.read());              
        wait(0.2); 
     } 
 }