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 )
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
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);
}
}
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).