I needed to measure water height in a tank then send the results 6 miles, simple task but:
HTCC-ABO2S has two UARTS, RX1/TX1 - RX2/TX2 - Heltec used non-zero based numbering instead of RX0/TX0 - RX1/TX1. When I tried Serial2.begin(9600); it dies but Serial1.begin(9600) works fine.
Next issue:
US-100 has Trig/TX and Echo/RX instead of using the ‘STANDARD’ you MUST connect TX2 to Trig/TX and RX2 to Echo/RX
Simple sketch:
// RX2 to Echo/rx
// TX2 to Trig/tx
unsigned int HighLen = 0;
unsigned int LowLen = 0;
unsigned int Len_mm = 0;
void VextON(void)
{
pinMode(Vext,OUTPUT);
digitalWrite(Vext, LOW);
}
void VextOFF(void) //Vext default OFF
{
pinMode(Vext,OUTPUT);
digitalWrite(Vext, HIGH);
}
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println();
VextON();
delay(100);
Serial1.begin(9600);
delay(100);
}
void loop()
{
Serial1.flush();
Serial1.write(0X55); // trig US-100 begin to measure the distance
delay(500);
if(Serial1.available() >= 2) // receive 2 bytes
{
HighLen = Serial1.read(); // High byte of distance
LowLen = Serial1.read(); // Low byte of distance
Len_mm = HighLen*256 + LowLen; // Calculate the distance
if((Len_mm > 1) && (Len_mm < 10000)) // normal distance should between 1mm and 10000mm (1mm, 10m)
{
Serial.print("Present Length is: ");
Serial.print(Len_mm, DEC);
Serial.println("mm");
}
}else Serial.println("Nothing in buffer");
delay(1000);
}