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

Dependencies:   SRF05 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 
00002 /*
00003 
00004  By: www.emcu.eu
00005  Date: Jan 2018
00006  Simple program to read the distance from an SRF04 using the SRF05 library,
00007  the results are send to the PC.
00008  On PC I suggest to use TeraTerm and the configuration is: 
00009  9600 bauds, 8-bit data, no parity
00010  
00011  NOTE: more info are here: http://www.emcu.eu/understand-the-way-to-use-hc-srf04-on-stm32-nucleo-board-and-mbed/
00012  
00013  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00014  BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00015  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00016  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00017  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00018 
00019 */
00020 
00021 
00022 #include "mbed.h"
00023 #include "SRF05.h"
00024 
00025 SRF05 srf04_F(PC_7, PB_6); // ECHO (pin.9), TRIG (pin.10)
00026 // SRF05 srf04_D(PA_8, PA_8); // ECHO (pin.7), TRIG (pin.10)
00027 
00028 //------------------------------------
00029 // Hyperterminal configuration
00030 // 9600 bauds, 8-bit data, no parity
00031 //------------------------------------
00032 Serial pc(SERIAL_TX, SERIAL_RX);
00033  
00034 int main() 
00035 { 
00036 pc.printf("\n\r\n\r By www.emcu.eu \n\r");
00037      while(1) 
00038      { 
00039         pc.printf("\n\r\n\r Distance_F = %.1f \n\r", srf04_F.read());
00040         // pc.printf("\n\r\n\r Distance_F = %.1f - Distance_D = %.1f\n\r", srf04_F.read(), srf04_D.read());              
00041         wait(0.2); 
00042      } 
00043  }