Last active
September 20, 2019 03:20
-
-
Save NickNothom/041bc73b26d1007f1fd06f0574eac3a7 to your computer and use it in GitHub Desktop.
Blue Robotics Ping Arduino Hardware Serial Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
This example is targeted toward the arduino platform | |
This example demonstrates the most simple usage of the Blue Robotics | |
Ping1D c++ API in order to obtain distance and confidence reports from | |
the device. | |
This API exposes the full functionality of the Ping1D Echosounder | |
Communication is performed with a Blue Robotics Ping1D Echosounder | |
*/ | |
#include "ping1d.h" | |
static const uint8_t arduinoRxPin = 19; //Serial1 rx | |
static const uint8_t arduinoTxPin = 18; //Serial1 tx | |
static Ping1D ping { Serial1 }; | |
static const uint8_t ledPin = 13; | |
void setup() | |
{ | |
Serial1.begin(115200); | |
Serial.begin(115200); | |
pinMode(ledPin, OUTPUT); | |
Serial.println("Blue Robotics ping1d-simple.ino"); | |
while (!ping.initialize()) { | |
Serial.println("\nPing device failed to initialize!"); | |
Serial.println("Are the Ping rx/tx wired correctly?"); | |
Serial.print("Ping rx is the green wire, and should be connected to Arduino pin "); | |
Serial.print(arduinoTxPin); | |
Serial.println(" (Arduino tx)"); | |
Serial.print("Ping tx is the white wire, and should be connected to Arduino pin "); | |
Serial.print(arduinoRxPin); | |
Serial.println(" (Arduino rx)"); | |
delay(2000); | |
} | |
} | |
void loop() | |
{ | |
if (ping.update()) { | |
Serial.print("Distance: "); | |
Serial.print(ping.distance()); | |
Serial.print("\tConfidence: "); | |
Serial.println(ping.confidence()); | |
} else { | |
Serial.println("No update received!"); | |
} | |
// Toggle the LED to show that the program is running | |
digitalWrite(ledPin, !digitalRead(ledPin)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment