Hi there
Looking for ideas on what else I could test to debug a new water tank monitoring system I was trying to install yesterday in a friend's garden.
Here is the context:
The system is to be installed between a shed in the garden and an underground tank collecting rain water.
The pipe joining both is is about 7 meters / yards
There is an existing blue pipe sleeve joining the shed and the tank through which runs the pipe going from the tank to the shed's pump.
My idea was to use this sleeve to run a cable from the shed to the inside of the water tank where I could fix the sensor pointing towards the water surface
From an MCU perspective:
I'm using a UART based DYP-A02YY waterproof ultrasonic ranging sensor connected to a M5Stack M5StickCPlus using a ~8m long cat 6 ethernet cable with 4 twisted pairs from which I removed the RJ45 plugs to just get the wires.
On the sensor side, as it will be within the tank, I'm using a 5 way waterproof connector to join the sensor to the ethernet cable.
I constructed the system at home and tested it and all was working fine, wether the M5 Stick was powered from its builtin battery or through USB C, I was showing the distance without any faults.
So in theory all seemed ready to roll... but in practice as always it did not work out that way.
Once we managed to get the ethernet cable going through the pipe sleeve from the tank to the shed, I connected the arduino on one end and the sensor on the other end (just like at home) and the distance reading was just 0...
So I started testing a few things.
-
initial idea was that the voltage drop was somehow too high for some reason. I measured the voltage at the sensor, I was getting a clean 5V.
-
I tested continuity for the cable, the 4 wires from one end where correctly connected to the other end.
-
I was wondering if the Rx/Tx UART signal was getting distorted somehow along the way. The good thing about using this UART based sensor is that the protocol is simple : there is a 0xFF start marker, then 2 bytes representing the distance in mm as an uint16_t little endian format and then a checksum over the first 3 bytes. So if something goes wrong, you would not receive the start marker or the CKSUM would be wrong... I checked and I was getting correct messages matching the spec.
-
I was wondering if there could be some issue in transporting enough power (the sensor needs 8mA so nothing really serious) and although I needed only 4 wires (Rx, Tx, 5V, GND) going from the M5SticC to the sensor because I had 8 wires (4 pairs) in the cable, I rewired everything attaching a pair together to get "more copper" between the sensor and the M5 StickC. no luck...
So none of this worked.
I unplugged the sensor from the end of the long cable and connected it directly to the M5Stick C with a short cable and the distance sensor was working fine. so the sensor was not broken...
I'm running a bit out of ideas on what to test next. The system was working fine at home with 10m of Ethernet cables laid on the floor so distance did not seem to be an issue for the UART signal.
that was my code to read the sensor (called repeatedly until I get true - I added some prints to ensure I was not loosing bytes)
bool readOnce(uint16_t &distance) {
const uint8_t startMarker = 0xFF;
static bool waitForMarker = true;
static uint8_t data[3];
static uint8_t dataIndex = 0;
if (Serial2.available() != 0) {
uint8_t receivedByte = Serial2.read();
if (waitForMarker) {
if (receivedByte == startMarker) {
dataIndex = 0;
waitForMarker = false;
}
} else {
data[dataIndex++] = receivedByte;
if (dataIndex >= sizeof data) {
waitForMarker = true;
distance = (((uint16_t)data[0]) << 8) + data[1];
uint8_t checksum = (((uint16_t)data[0]) + ((uint16_t)data[1]) - 1u) & 0x00FFu;
return (data[2] == checksum);
}
}
}
return false;
}
So my question is: if that was your project - what would you be testing next ?
May be something to dig into as a 0mm distance is a message like this "0xFF 0x00 0x00 0xFF" so only 0x00 or 0xFF bytes. The protocol is respected and checksum works and I was not getting any bug in message reception, so it was not like I my code was picking up random noise, I was getting really a stream of 0xFF 0x00 0x00 0xFF
would a steady
0xFF 0x00 0x00 0xFF 0xFF 0x00 0x00 0xFF 0xFF 0x00 0x00 0xFF 0xFF 0x00 0x00 0xFF...
happen by magic? it does not feel random (2 0x00 followed by 2 0xFF)
I'd take any ideas — hey, even conspiration theory ones — on why this is not working.
(if I can't get this to work, I have another version of the distance sensor using RS485 so might be more immune to noise on the line and the "long" distance but would require RS485 adaptation which means extra stuff to pack in a waterproof box inside the tank)