Hi ~!
like above title, I want to use dual ping sonar with arduino leonardo .
We are making source codes using Arduino’s two serial ports at the same time and Arduino codes provided by Blue Robotics.
However, as in the code below, the value of serial 1 appears to be only 0.
Since data values appear when you connect to tx and rx alone, I don’t think it’s a problem with board pins, and I think there’s a problem with source code, can you help me?
/**
* 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"
#include "SoftwareSerial.h"
// This serial port is used to communicate with the Ping device
// If you are using and Arduino UNO or Nano, this must be software serial, and you must use
// 9600 baud communication
// Here, we use pin 9 as arduino rx (Ping tx, white), 10 as arduino tx (Ping rx, green)
static const uint8_t arduinoRxPin1 = 10;
static const uint8_t arduinoTxPin1 = 11;
static const uint8_t arduinoRxPin2 = 8;
static const uint8_t arduinoTxPin2 = 9;
SoftwareSerial pingSerial1 = SoftwareSerial(arduinoRxPin1, arduinoTxPin2);
SoftwareSerial pingSerial2 = SoftwareSerial(arduinoRxPin2, arduinoTxPin2);
static Ping1D ping1 { pingSerial1 };
static Ping1D ping2 { pingSerial2 };
static const uint8_t ledPin = 13;
void setup()
{
pingSerial1.begin(115200);
pingSerial2.begin(115200);
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
Serial.println("Blue Robotics ping1d-simple.ino");
/*while (!ping1.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(arduinoTxPin1);
Serial.println(" (Arduino tx)");
Serial.print("Ping tx is the white wire, and should be connected to Arduino pin ");
Serial.print(arduinoRxPin1);
Serial.println(" (Arduino rx)");
delay(2000);
}*/
}
void loop()
{
if (ping1.update()) {
pingSerial1.listen();
Serial.print("Distance1: ");
Serial.print(ping1.distance());
Serial.print("\tConfidence1: ");
Serial.println(ping1.confidence());
} else {
Serial.println("No update received!");
}
if(ping2.update()){
pingSerial2.listen();
Serial.print("Distance2: ");
Serial.print(ping2.distance());
Serial.print("\tConfidence2: ");
Serial.println(ping2.confidence());
}
// Toggle the LED to show that the program is running
digitalWrite(ledPin, !digitalRead(ledPin));
}