I have had a read through the docs and some examples on esphome.io
the below is what i have come up with so far. I have left the names as is from the exaamples to try and eliminate any naming errors on my behalf.
So far this is giving me an output on the esphome logger of:
nothing is attached to the tx and rx
[10:01:59][E][uart:229]: Reading from UART timed out at byte 0!
This is as I would expect with nothing connected.
When the Tx of the distance sensor is connected to the Rx pin (D2 in this case) on the 8266 the logger ceases to function immediately after initiating. If i disconnect the pin the logger immediately resumes.
Is this a problem with the logger not being able to function with an external UART connected or is my code off track?
You’re calling readString() but never using the result. It’s probably blocking waiting for an end of line, which doesn’t occur in your protocol, and that’s why it seems like nothing happens. You need to copy the first part of the original code too I think, the part that populates the data array.
Hi @chocolatejoe , i am also facing identical trouble here. What device do you use for ESPHome?
I use wemos D1 mini with only 1 UART available and having same problem when nothing is attached to UART.
Reading from UART timed out at byte 0!
But when attach my sensor, ESPHome device will be disconnected. Do you figure something out? Thanks
I used Wemos D1 Mini with UART on GPIO1 and 3. I also read the documentation here and made my_custom_component.h same with the documentation as follow
#include "esphome.h"
class MyCustomComponent : public Component, public UARTDevice {
public:
MyCustomComponent(UARTComponent *parent) : UARTDevice(parent) {}
void setup() override {
// nothing to do here
}
void loop() override {
// Use Arduino API to read data, for example
String line = readString();
int i = parseInt();
while (available()) {
char c = read();
}
// etc
}
};
Here is the configuration yaml file for my ESPHome device
esphome:
name: test_serial
platform: ESP8266
board: d1_mini
includes:
- my_custom_component.h
uart:
id: uart_bus
tx_pin: GPIO1
rx_pin: GPIO3
baud_rate: 9600
custom_component:
- lambda: |-
auto my_custom = new MyCustomComponent(id(uart_bus));
return {my_custom};
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Test Serial Fallback Hotspot"
password: ..
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
When nothing is attached to GPIO1 and 3, it will show error like this
I used Arduino with serial logic level of 3.3V, the same voltage of Wemos D1 logic level, to simply send string from this arduino to Wemos D1 mini. Here is my arduino code. When i attach arduino serial to Wemos D1 mini serial, the connection is cut off. My Wemos D1 mini is not connected to home assistant server anymore. The status become offline.
void setup() {
Serial.begin(9600);
}
void loop() {
// Serial.write(45); // send a byte with the value 45
Serial.write("hello\r\n"); //send the string "hello" and return the length of the string.
}
You need to customise the loop() code. I would start by just keeping the loop that reads characters and printing each one out as it’s received. Then you will know is it timing out on the readString(), or the parseInt() or what.
You definitely don’t want the parseInt, because you’re not sending any ints…
this gives me readings with repeatable accuracy to about 40mm in the tank measured using the A01 on esp8266. (a 12bit ADC would probably increase this)
This is the setup that finally worked for me with the A02YYUW sensor for the record.
note i also have a temperature sensor in my tank.
Hi,
Just saw your old post. I’m trying to get my A02YYUW to work. Having trouble using your pasted code. I see you have commented out:
includes:
- uart_ultrasonic_sensor.h
In the yaml file. I guess it is not on purpose since the compilation will fail.
With it incommented I get 0.0000 values out. Has it been working with correct values for you?
How do I know what pins/GPIO this is referring to (I’m using a Wemos D1 mini):
SoftwareSerial mySerial(RX, TX);
For the record I know the sensor itself is working. I have a setup with a Pi2ZeroW that is working flawlessly.
Just out of curiousity. Are you still happy about the “Throw-in Type Liquid Level Transmitter” I have an idear about avoiding physical object in my watertank. Over the years i think they will corode no matter what the specs say. The condense problem has not been a problem for me and if it will be then I have a backup plan for leading the condensed water away from the sensor.
Thanks in advance. Really appreciate you managed to post you solution even though you ditched the solution for other reasons.
Really interested to hear how you would stop the condensation on the sensor because I have 2 of these sensors sitting unused because of this:)
I assume the uart_ultrasonic_sensor.h you are reffering to is what I have as my_custom_component.h
This is a file which you place in the /config/esphome directory
SoftwareSerial mySerial(RX, TX);
this is defined in the my_custom_component.h file.
#includes:
# - my_custom_component.h
This may be a mistake in my posted code. I believe this will need to be uncommented.
Let me know how you go. It is a while since I have played with this code so if you are still having troubles with it I will make up a board to test it again.
Regarding the throw in type transmitter, it has been working great. I don’t believe there would be any corrosion issues as it is stainless steel. It has been installed for a year now so I will pull it up and check it however and maybe post some photos of its condition if you would like.
Thanks for your reply. I could not get your solution to work so I switched to another and in some way more complex solution, which seems to be working well. I use a Raspberry Pi Zero to sample every 10 seconds calculate the average everty minute and then by using MQTT publishing the values to my HA.
Regarding the condensation, I’m not sure about your problem, but I havent had any showstopping problems so far. Soo far I have only tested it in a cold winter environment (live in Denmark), which does generate condense, but maybee not as much as in a warmer climate. Maybee I get the same problems during summer next year!
If I get problems my plan is to construct a casing that will lead the water away from the sensor somehow. Don’t know if it will work though.
@tech_fr3ak sorry for the delay.
had to pull the throw in up the other day because my esp8266 on top of the tank somehow got water in it and fried.
New board in with conformal coating so hopefully this doesn’t happen again.
Throw in sensor has been in use since March 20 and is still functioning fine.
Sorry for the very late response. I was in here on another issue and saw my notification. Better late than never :-).
My solution has been running for roughly a year now. I have had no issues with condensation at all. I did have some spikes in my data in my early version, which probable was due to some condensation piled into a raindrop poluting the measurement for that particular moment, but it was not often. To eliminate it I create a filter in my sampling on my PiZero (which is doing the data collection). I simply filtered out those values every minute that was to far from the variance of the current population (sample rate 10secs). This seemed to do the trick!
It have HOWEVER experienced another problem with my A02YYUW but it was my own fault. During a period of heavy rain my tank got overloaded with water, flooded the sensor for some hours which ruined the sensor. So I had to bey a new one. Conclusion: The sensor is moistproof but nut water proof. Nothing surprising actually, according to the specs, but now I have testet it
Thanks for your scripts. Somehow when I try to compile in ESPhome, it fails because it can’t find softwareserial.h and other components. How do you make your script work with the .h files in esphome ?