Forum >i have a problem with this sensor:Does it need to be peeled or opened or anything? because i dipped it underwater and received no reading. Double checked the UART 2 pins, rx to 16,...
FAQ

i have a problem with this sensor:Does it need to be peeled or opened or anything? because i dipped it underwater and received no reading. Double checked the UART 2 pins, rx to 16,...

userHead Tonny12138 2024-02-20 22:16:29 30 Views1 Replies

i have a problem with this sensor:
Does it need to be peeled or opened or anything? because i dipped it underwater and received no reading. Double checked the UART 2 pins, rx to 16, tx to 17. power supply to 5V and grounded. BTW im using ESP32. I used Hardware Serial library, the code:

#include <hardwareserial.h>

unsigned char buffer_RTT[4] = {0};
uint8_t CS;
#define COM 0x55

HardwareSerial mySerial(2); // Use hardware serial port 2 (pins 16 and 17)

void setup() {
Serial.begin(115200);
mySerial.begin(115200);
}

void loop() {
mySerial.write(COM); //0101 0101
delay(100);
Serial.println("Checking for reading from UWUsensor...");
delay(1000);

if (mySerial.available() > 0) {
delay(4);
if (mySerial.read() == 0xff) { // 1111 1111
buffer_RTT[0] = 0xff;
for (int i = 1; i < 4; i++) {
buffer_RTT[i] = mySerial.read();
}
CS = buffer_RTT[0] + buffer_RTT[1] + buffer_RTT[2];
if (buffer_RTT[3] == CS) {
int Distance = (buffer_RTT[1] << 8) + buffer_RTT[2];
Serial.print("Distance: ");
Serial.print(Distance);
Serial.println("mm");
}
}
}
else
Serial.println("No reading");
delay(1000);
}

2024-02-22 18:01:19

Hello,
If you are using ESP32, you can use the following code. Because Serial2 would have represented IO16 and IO17.
We recommend that you use a controller such as the Ardunio UNO/Mega with a 5V operating voltage. And upload the sample code from our wiki for testing.

unsigned char buffer_RTT[4] = {0};
uint8_t CS;
#define COM 0x55

void setup() {
Serial.begin(115200);
Serial2.begin(115200);
}

void loop() {
Serial2.write(COM); //0101 0101
delay(100);
Serial.println("Checking for reading from UWUsensor...");
delay(1000);

if (Serial2.available() > 0) {
delay(4);
if (Serial2.read() == 0xff) { // 1111 1111
buffer_RTT[0] = 0xff;
for (int i = 1; i < 4; i++) {
buffer_RTT[i] = Serial2.read();
}
CS = buffer_RTT[0] + buffer_RTT[1] + buffer_RTT[2];
if (buffer_RTT[3] == CS) {
int Distance = (buffer_RTT[1] << 8) + buffer_RTT[2];
Serial.print("Distance: ");
Serial.print(Distance);
Serial.println("mm");
}
}
}
else
Serial.println("No reading");
delay(1000);
}

userHeadPic Tonny12138