Looking for new ideas on what to explore to debug a distance sensor

OK - yes and the Arduino doe not even send data it's just Sensor's Tx to Arduino Rx.
I was wondering may be if the power line next to the data line could have become a problem

not sure it matters over 7 meters... does it ?
(but to the question no, in the lab I mainly tested with the wires South to North and in the field they are borth East to South West :slight_smile: )

Did you test the sensor and the cable in the lab and in the field with exact the same connectors installed?

yes I tested the exact same config in the lab - fully wired kinda like this

with the cable extended over ~8 m

still raining, so no testing this morning. Will see this afternoon if I can go back on site.

If an AC mains power line, the most probably that is a problem and something to be avoided like the plague!

2 Likes

Were the connectors installed when you pulled the cable or after?

No, I meant just the 5V/GND line next to Rx and Tx.

I had to remove the connectors to get them into the pipe sleeve but I tested continuity


Just a quick updateβ€”I've just returned from the field in the midst of two rain showers and I was able to test the loopback . I kept the connector at the end of my underground wire and added a wire on the other side to join Rx and Tx

I had written a small loopback test for the M5Stick (sending millis when you press the button) and the test worked flawlessly...

So Tx and Rx seems to work fine, the round trip was no issue whatsoever. I also tested the voltage again on the two other pins and I had a steady 5V...

the plot thickens :slight_smile:

As it started to rain heavily again I closed the tank and left..

I guess the next trial is to power the distance sensor directly with 5V not from the M5STick C (and join GNDs) and see if it's a power issue....


just for reference - the loopback code
#include <M5StickCPlus.h>

const uint16_t lcdWidth = 240;
const uint16_t lcdHeight = 135;

// M5StickCPlus PORT pins below (GND Vout 32 33)
const byte rxPin = 33;
const byte txPin = 32;

const byte maxMessageLength = 30;
char message[maxMessageLength + 1]; // + 1 for the null character at the end of the string

bool isMessageReceived() {
  enum State : byte {WAITING, IN_PROGRESS};
  static State state = WAITING;
  static byte index = 0;
  bool messageReady = false;
  int r = Serial2.read();

  if (r != -1) { // -1 means nothing to read
    switch (state) {
      case WAITING:
        if (r == '<') { // new reception
          index = 0;
          message[0] = '\0';
          state = IN_PROGRESS;
        }
        break;

      case IN_PROGRESS:
        if (r == '>') { // new reception
          message[index] = '\0';
          state = WAITING;
          messageReady = true;
        } else {
          if (index < maxMessageLength) {
            message[index++] = r;
          }
        }
        break;
    }
  }
  return messageReady;
}

void setup() {
  Serial2.begin(9600, SERIAL_8N1, rxPin, txPin);  // wired in loopback
  M5.begin();
  M5.Lcd.setRotation(3);
  M5.Lcd.setTextSize(4);
  M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
  M5.Lcd.setTextDatum(MC_DATUM); // Middle Center
  M5.Lcd.fillScreen(TFT_GREEN);
  Serial.println("Ready. Press the main button.");
}

void loop() {
  M5.update();
  if (M5.BtnA.wasReleased()) {
    M5.Lcd.fillScreen(TFT_RED);
    Serial.println("sending <millis()>");
    Serial2.write('<'); Serial2.print(millis()); Serial2.write('>');
  }

  if (isMessageReceived()) {
    M5.Lcd.fillScreen(TFT_BLACK);
    M5.Lcd.drawString(message, lcdWidth / 2, lcdHeight / 2);
    Serial.print("Received: "); Serial.println(message);
  }
}

quick update on this (kindof) for those wondering what's going on.

I could not find the issue with the existing ethernet cable so I got a new cable β€” 20 metres of 24 AWG with 6 strands of 0.2mm2 of supposedly good quality ( multiple strands of oxygen free tinned copper wire) that's given for 94.2Ξ© per Km.

I connected the full 20m in my lab and all is working well... So I'll go try to install this new cable later this week - weather allowing and report back.

(I've 2 extra strands in the cable that I won't use for the moment but could be useful if I want other sensors in the tank).

so the sun was there this afternoon so I went and replaced the wire and all worked out from the first try!

(the cable was long enough so that I could bring the M5 close to the tank. I then cut the cable to the right length and installed the M5 in the shed.)

thanks for all the ideas! (not sure what was wrong with the other cable)

1 Like

I might have left well enough alone :expressionless:

Thanks for the update, glad it's working.

a7

2 Likes

Thx

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.