I connected
red : 5V
black :GND
green :~10
white :~9
as per the github manual.
However, it is displayed on the serial screen as follows.
Ping device failed to initialize!
Are the Ping rx/tx wired correctly?
Ping rx is the green wire, and should be connected to Arduino pin 10 (Arduino tx)
Ping tx is the white wire, and should be connected to Arduino pin 9 (Arduino rx)
I do not know why tx and rx are not recognized.
Please teach me.
The examples use the SoftwareSerial library to communicate with the Ping device, which allows flexibility for the rx/tx pin assignments on the Arduino. The examples use pins 10 and 9. The SoftwareSerial library can only communicate with the Ping device at 9600 baud. If you are using a board with more than one HardwareSerial port, like the Arduino MEGA, you may use the second serial port to communicate with a Ping device at 115200 baud.
/////////////////////////////////////////////////////////
#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 arduinoRxPin = 9;
static const uint8_t arduinoTxPin = 10;
SoftwareSerial pingSerial = SoftwareSerial(arduinoRxPin, arduinoTxPin);
static Ping1D ping { pingSerial };
void setup()
{
pingSerial.begin(9600);
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));
}
/////////////////////////////////////////////////////////
Sorry for not being explicit about my previous answer, you should flash Ping with a 9600 baud rate version. Ping comes with a 115200 baud rate from factory and it’s necessary to flash a 9600 baud rate firmware to allow it to communicate with your Arduino via SoftwareSerial interface. If you are working with an Arduino that provides more than one hardware serial interface, you can use Ping with the factory firmware of 115200 baud rate.
BLUART is not necessary if you are aiming to use it with your Arduino.
If you want to connect Ping with your computer, check the product learn tab. If you are running Ping-Viewer and want to flash the 9600 baud rate firmware to use Ping with your Arduino, check the Firmware Update documentation page.
Please, connect Ping directly in a FTDI or any serial/USB adapter. Ping-Viewer will automatically connect and stream the data, after the connection is done and the communication between Ping-Viewer and Ping is accomplished, the available firmwares will be available for you in the flash menu.
You can brick Ping if you are going to use an Arduino to do the firmware update, I highly advice to use a BLUEART or any other serial/USB adapter.
I don’t have any serial/USB adapter but I have arduinoMEGA.
If I change Arduino UNO for Arduino MEGA,can I connect ping directly without serial/USB adapter.
Yes, it’s possible to use an Arduino uno or Arduino Mega but it’s not recommended if you aiming to use with Ping-Viewer as a serial/USB adapter. Be advice that flashing a new firmware while doing so it can brick your sensor and recovery methods will be necessary.
The easier an safer way is to use a simple and normal serial/USB adapter if you are aiming to update Ping firmware.
If you are aiming to integrate Arduino and Ping, you should use Arduino Mega and a second hardware serial port, doing so will not require to change the Ping baud rate from 115200 to 9600, and you can use our Arduino examples.
I want to catch data of distance.
So I think I don’t need use Ping-Viewer.
I wrote “ping1d-simple.ino” using arduino MEGA.
But like ArduinoUNO,I got an error.
"Ping device failed to initialize!
Are the Ping rx / tx wired correctly?
Ping rx is the green wire and should be connected to Arduino pin 10 (Arduino tx)
Ping tx is the white wire, and should be connected to Arduino pin 9 (Arduino rx) "
It appears that in your previous flash attempts using an Arduino as a USB/Serial adapter bricked the sensor. Please follow the Device Recovery instructions with a real USB/Serial adapter (BLUART, FTDI, CH341) and not an Arduino board.