Hi everybody,
Iam using 2 of the mentioned A02YYUW ultrasonic distance sensors.
They are currently connected via this I2C to dual UART board attached to an Arduino Mega R3, but I had the same problems with Serial/SoftwareSerial as well.
Iam getting good looking data but then for multiple seconds at a time the sensors will send garbage data. It happens with both of them, sometimes at the same time.
Now my wiring is all positively affixed and it happens when everything is laying still. The sensors are supplied with 5v from the Arduino, which is supplied by a 6s Lipo and a DC to DC Voltage Converter to 5V.
So there is enough current and the correct voltage.
My sketch is slightly changed version of the linked DFRobot-Wiki version.
Here is the part responsible for one of the sensors, the other is of course the same just with the different serial interface.
I already added the extra debug output of the 4 bytes.
Data should look like this:
Header has to have 255, then the measurement, then checksum.
do {
for (int i = 0; i < 4; i++) {
sonarDataLinks[i] = iicSerial1.read();
}
Serial.print("Data Left: ");
Serial.print(sonarDataLinks[0]);
Serial.print(sonarDataLinks[1]);
Serial.print(sonarDataLinks[2]);
Serial.println(sonarDataLinks[3]);
} while (iicSerial1.read() == 0xff);
iicSerial1.flush();
if (sonarDataLinks[0] == 0xff) {
int sum;
sum = (sonarDataLinks[0] + sonarDataLinks[1] + sonarDataLinks[2]) & 0x00FF;
if (sum == sonarDataLinks[3]) {
sonarHeightLinks = (sonarDataLinks[1] << 8) + sonarDataLinks[2];
Serial.println(sonarHeightLinks);
}
Serial.print("error L");
instead of measurements i get multiple seconds of this:
16:43:51.209 -> Data Right: 0000
16:43:51.332 -> Data Left: 0000
16:43:51.332 -> Data Right: 0000
16:43:51.473 -> Data Left: 0000
16:43:51.473 -> Data Right: 0000
16:43:51.552 -> Data Left: 0000
16:43:51.552 -> Data Right: 0000
16:43:51.691 -> Data Left: 0000
16:43:51.691 -> Data Right: 0000
16:43:51.816 -> Data Left: 0000
16:43:51.816 -> Data Right: 0000
and this:
16:43:52.523 -> Data Left: 84653255
16:43:52.565 -> Data Right: 84653255
16:43:52.565 -> Data Right: 84653255
16:43:52.646 -> Data Left: 46532558
16:43:52.690 -> Data Right: 46532558
16:43:52.777 -> Data Left: 5325580
16:43:52.777 -> Data Right: 5325580
16:43:52.895 -> Data Left: 0532558
and then somtimes correct data:
16:45:27.279 -> Data Right: 25585057
16:45:27.279 -> distance - 2098.00
16:45:27.418 -> Data Right: 25585057
16:45:27.418 -> distance - 2098.00
I dont know what my next step is, so Iam looking for ideas to solve this issue, I cant really believe both sensors are broken. I dont see an issue with the software because it even happens with the DFR sketch and the cabling/connection are all solid.
Just to combat the idea that the problem is the rest of my sketch that i didnt post, here is the result with the reference DFRobot sketch:
17:07:51.388 -> distance=209.90cm
17:07:51.495 -> distance=209.90cm
17:07:51.630 -> distance=209.90cm
17:07:51.712 -> distance=209.90cm
17:07:51.849 -> distance=209.90cm
17:07:51.927 -> distance=209.90cm
17:07:57.400 -> distance=209.50cm //
17:08:02.296 -> ERROR // <-- 5 second delay!
17:08:06.162 -> distance=209.50cm //
17:08:06.275 -> distance=209.50cm
17:08:06.400 -> distance=209.50cm
17:08:06.486 -> distance=209.50cm
17:08:06.592 -> distance=209.50cm
the 5 second delay comes because there is no data byte that looks like the expected header for the entire time so its not reaching any Serial.print.
Same result using that on an Arduino Uno with software serial.