Hello. Was attempting to create a setup whereas 2 nano ESP32s communicate as clients to a centralized uno wifi server, sharing their sonar readings intermittenly. However, when testing with the ping1d simple example, the obvious error of SoftwareSerial was brought up (due to Nano hardware limitations). I replaced it with HardwareSerial
, specifically using `Serial1’. I then adjusted the Pin layouts to match TX1 and RX0 for communications, but still receive
14:44:57.321 → Ping device failed to initialize!
the sonar is connected to an external 5V and gnd. Any assistance or working code anyone has working with the Nano?
#include "ping1d.h"
static HardwareSerial& pingSerial = Serial1;
static Ping1D ping { pingSerial };
static const uint8_t ledPin = 13;
void setup()
{
pingSerial.begin(9600, SERIAL_8N1, 0, 1); // D0 (RX), D1 (TX)
Serial.begin(115200); // USB serial for monitoring
pinMode(ledPin, OUTPUT);
Serial.println("Blue Robotics ping1d-simple.ino");
while (!ping.initialize()) {
Serial.println("\nPing device failed to initialize!");
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!");
}
digitalWrite(ledPin, !digitalRead(ledPin));
}