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

Dependencies:   SRF05 mbed

Committer:
emcu
Date:
Tue Jan 02 00:00:18 2018 +0000
Revision:
0:99c5f79155a6
Understand the way to use HC-SRF04 on STM32 (Nucleo board)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emcu 0:99c5f79155a6 1
emcu 0:99c5f79155a6 2 /*
emcu 0:99c5f79155a6 3
emcu 0:99c5f79155a6 4 By: www.emcu.eu
emcu 0:99c5f79155a6 5 Date: Jan 2018
emcu 0:99c5f79155a6 6 Simple program to read the distance from an SRF04 using the SRF05 library,
emcu 0:99c5f79155a6 7 the results are send to the PC.
emcu 0:99c5f79155a6 8 On PC I suggest to use TeraTerm and the configuration is:
emcu 0:99c5f79155a6 9 9600 bauds, 8-bit data, no parity
emcu 0:99c5f79155a6 10
emcu 0:99c5f79155a6 11 NOTE: more info are here: http://www.emcu.eu/understand-the-way-to-use-hc-srf04-on-stm32-nucleo-board-and-mbed/
emcu 0:99c5f79155a6 12
emcu 0:99c5f79155a6 13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
emcu 0:99c5f79155a6 14 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
emcu 0:99c5f79155a6 15 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
emcu 0:99c5f79155a6 16 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
emcu 0:99c5f79155a6 17 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
emcu 0:99c5f79155a6 18
emcu 0:99c5f79155a6 19 */
emcu 0:99c5f79155a6 20
emcu 0:99c5f79155a6 21
emcu 0:99c5f79155a6 22 #include "mbed.h"
emcu 0:99c5f79155a6 23 #include "SRF05.h"
emcu 0:99c5f79155a6 24
emcu 0:99c5f79155a6 25 SRF05 srf04_F(PC_7, PB_6); // ECHO (pin.9), TRIG (pin.10)
emcu 0:99c5f79155a6 26 // SRF05 srf04_D(PA_8, PA_8); // ECHO (pin.7), TRIG (pin.10)
emcu 0:99c5f79155a6 27
emcu 0:99c5f79155a6 28 //------------------------------------
emcu 0:99c5f79155a6 29 // Hyperterminal configuration
emcu 0:99c5f79155a6 30 // 9600 bauds, 8-bit data, no parity
emcu 0:99c5f79155a6 31 //------------------------------------
emcu 0:99c5f79155a6 32 Serial pc(SERIAL_TX, SERIAL_RX);
emcu 0:99c5f79155a6 33
emcu 0:99c5f79155a6 34 int main()
emcu 0:99c5f79155a6 35 {
emcu 0:99c5f79155a6 36 pc.printf("\n\r\n\r By www.emcu.eu \n\r");
emcu 0:99c5f79155a6 37 while(1)
emcu 0:99c5f79155a6 38 {
emcu 0:99c5f79155a6 39 pc.printf("\n\r\n\r Distance_F = %.1f \n\r", srf04_F.read());
emcu 0:99c5f79155a6 40 // pc.printf("\n\r\n\r Distance_F = %.1f - Distance_D = %.1f\n\r", srf04_F.read(), srf04_D.read());
emcu 0:99c5f79155a6 41 wait(0.2);
emcu 0:99c5f79155a6 42 }
emcu 0:99c5f79155a6 43 }