Distance Sensor A02YYUW
Moderators: grovkillen, Stuntteam, TD-er
Distance Sensor A02YYUW
Hi all,
I'm new, so please forgive me the probably bad question.
I would like to use this Sensor (https://wiki.dfrobot.com/A02YYUW%20Wate ... 1#target_0) (waterresistant and short minimal range) with ESP Easy on a WEMOS D1 Mini.
Since I have not found a similar sensor in the list of supported devices, is there an other possibility to connect this sensor?
Thanks
I'm new, so please forgive me the probably bad question.
I would like to use this Sensor (https://wiki.dfrobot.com/A02YYUW%20Wate ... 1#target_0) (waterresistant and short minimal range) with ESP Easy on a WEMOS D1 Mini.
Since I have not found a similar sensor in the list of supported devices, is there an other possibility to connect this sensor?
Thanks
Re: Distance Sensor A02YYUW
Nobody can help me?
No one got experience with this sensor?
No one got experience with this sensor?
Re: Distance Sensor A02YYUW
I haven't seen that sensor before, but it doesn't look like a very complicated one to support in ESPEasy.
Right now there is no plugin supporting that sensor.
Right now there is no plugin supporting that sensor.
Re: Distance Sensor A02YYUW
Thanks for the reply,
but what can I do now?
Since I'm new to this...
Wait until somebody create a plugin...
or
do it myself... but how?
but what can I do now?
Since I'm new to this...
Wait until somebody create a plugin...
or
do it myself... but how?
Re: Distance Sensor A02YYUW
Reading of that sensor is quite simple.
So you may want to start by looking into a very simple plugin like this one: https://github.com/letscontrolit/ESPEas ... 8_Dust.ino
It is about the most simple plugin I could find.
Only you need to read from the serial port.
So first you need to add code to read it from Serial as described on the dfRobot site.
Then later on we can make it more generic by using the ESPEasySerial wrapper, so it can work on any serial port for ESP8266 or ESP32.
For a first attempt, you can use the reading code listed on the dfRobot site and run it in the PLUGIN_READ case of the switch statement.
So you may want to start by looking into a very simple plugin like this one: https://github.com/letscontrolit/ESPEas ... 8_Dust.ino
It is about the most simple plugin I could find.
Only you need to read from the serial port.
So first you need to add code to read it from Serial as described on the dfRobot site.
Then later on we can make it more generic by using the ESPEasySerial wrapper, so it can work on any serial port for ESP8266 or ESP32.
For a first attempt, you can use the reading code listed on the dfRobot site and run it in the PLUGIN_READ case of the switch statement.
Re: Distance Sensor A02YYUW
Great!
Let's see if I get it...
I'm learning with every project and new idea...
Thanks!
Let's see if I get it...
I'm learning with every project and new idea...
Thanks!
Re: Distance Sensor A02YYUW
Hey Wolvie, did you have any success with the A02YYUW and wemos.
Because I also have a wemos and A02YYUW over here and would love to play with it.
Looking forward to your reply.
Because I also have a wemos and A02YYUW over here and would love to play with it.
Looking forward to your reply.
Re: Distance Sensor A02YYUW
With inspiration from this this library, I managed to write a plugin for this device that seems to work fine.
All in all, this device appears to be quite good with a good range and accuracy.
Below is the code :
All in all, this device appears to be quite good with a good range and accuracy.
Below is the code :
Code: Select all
#include "_Plugin_Helper.h"
#ifdef USES_P251
//#######################################################################################################
//#################################### Plugin 251: A02YYUW ##############################################
//#######################################################################################################
#define PLUGIN_251
#define PLUGIN_ID_251 251
#define PLUGIN_NAME_251 "Distance - A02YYUW"
#define PLUGIN_VALUENAME1_251 "Distance"
#define MIN_DISTANCE 30
#define MAX_DISTANCE 4500
#define SERIAL_BAUD_RATE 9600
#define SERIAL_HEAD_DATA 0xff
#define SERIAL_AVAILABLE_CHECK_DELAY 50
#define SERIAL_AVAILABLE_CHECK_CICLES 10 // SERIAL_AVAILABLE_CHECK_DELAY * SERIAL_AVAILABLE_CHECK_CICLES = 500ms
enum {
DistanceSensor_A02YYUW_MEASSUREMENT_STATUS_OK = 0,
DistanceSensor_A02YYUW_MEASSUREMENT_STATUS_ERROR_CHECK_SUM = -1,
DistanceSensor_A02YYUW_MEASSUREMENT_STATUS_ERROR_MAX_LIMIT = -2,
DistanceSensor_A02YYUW_MEASSUREMENT_STATUS_ERROR_MIN_LIMIT = -3,
DistanceSensor_A02YYUW_MEASSUREMENT_STATUS_ERROR_SERIAL = -4
};
#include <ESPeasySerial.h>
ESPeasySerial *P251_Serial = nullptr;
boolean Plugin_251_init = false;
boolean Plugin_251(uint8_t function, struct EventStruct *event, String& string)
{
boolean success = false;
switch (function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_251;
Device[deviceCount].Type = DEVICE_TYPE_SERIAL;
Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_SINGLE;
Device[deviceCount].Ports = 0;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = true;
Device[deviceCount].ValueCount = 1;
Device[deviceCount].SendDataOption = true;
Device[deviceCount].TimerOption = true;
Device[deviceCount].GlobalSyncOption = true;
break;
}
case PLUGIN_GET_DEVICENAME:
{
string = F(PLUGIN_NAME_251);
break;
}
case PLUGIN_GET_DEVICEVALUENAMES:
{
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_251));
break;
}
case PLUGIN_GET_DEVICEGPIONAMES:
{
event->String1 = formatGpioName_output(F("RX PIN"));
event->String2 = formatGpioName_output(F("TX PIN"));
break;
}
case PLUGIN_INIT:
{
int rxPin = CONFIG_PIN1;
int txPin = CONFIG_PIN2;
const ESPEasySerialPort port = static_cast<ESPEasySerialPort>(CONFIG_PORT);
if (P251_Serial != nullptr) {
delete P251_Serial;
P251_Serial = nullptr;
}
P251_Serial = new ESPeasySerial(port, rxPin, txPin);
if (P251_Serial == nullptr) {
break;
}
P251_Serial->begin(9600);
P251_Serial->flush();
addLog(LOG_LEVEL_INFO, F("A02YYUW: Initialization OK"));
Plugin_251_init = true;
success = true;
break;
}
case PLUGIN_READ:
{
unsigned char data[4] = {};
int i = 0;
unsigned int meassuredDistance = MIN_DISTANCE;
int meassurementStatus;
P251_Serial->flush();
while (!P251_Serial->available() && i < SERIAL_AVAILABLE_CHECK_CICLES) {
i++;
delay(SERIAL_AVAILABLE_CHECK_DELAY);
}
i = 0;
while(P251_Serial->available() && i < 4) {
data[i] = P251_Serial->read();
i++;
if (data[0] != SERIAL_HEAD_DATA) {
i = 0;
}
}
if (i != 4) {
meassurementStatus = DistanceSensor_A02YYUW_MEASSUREMENT_STATUS_ERROR_SERIAL;
} else {
if (!(((data[0] + data[1] + data[2])& 0x00FF) == data[3])) {
meassurementStatus = DistanceSensor_A02YYUW_MEASSUREMENT_STATUS_ERROR_CHECK_SUM;
} else {
meassuredDistance = ((data[1] << 8) + data[2]);
if (meassuredDistance < MIN_DISTANCE) {
meassurementStatus = DistanceSensor_A02YYUW_MEASSUREMENT_STATUS_ERROR_MIN_LIMIT;
}
else if (meassuredDistance > MAX_DISTANCE) {
meassurementStatus = DistanceSensor_A02YYUW_MEASSUREMENT_STATUS_ERROR_MAX_LIMIT;
} else {
meassurementStatus = DistanceSensor_A02YYUW_MEASSUREMENT_STATUS_OK;
}
}
}
if (meassurementStatus == DistanceSensor_A02YYUW_MEASSUREMENT_STATUS_OK) {
UserVar[event->BaseVarIndex] = (float)meassuredDistance;
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
String log = F("A02YYUW: Distance value = ");
log += meassuredDistance;
addLog(LOG_LEVEL_INFO, log);
}
success = true;
} else {
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
String log = F("A02YYUW: Error status = ");
log += meassurementStatus;
addLog(LOG_LEVEL_INFO, log);
}
success = false;
}
break;
}
}
return success;
}
#endif // USES_P251
Sébastien - espRFLinkMQTT gateway RFLink MQTT on esp
Re: Distance Sensor A02YYUW
Hi seb82
Would you mind sharing the bin file for the A02YYUW?
Would you mind sharing the bin file for the A02YYUW?
Re: Distance Sensor A02YYUW
I have reserved Plugin ID P134 in the mega branch of ESPEasy repository for this plugin, and will soon start moving this code to the regular ESPEasy builds.
it will take some effort, as it isn't yet multi-instance compatible, and has some delay-related issues that probably need to be addressed.
it will take some effort, as it isn't yet multi-instance compatible, and has some delay-related issues that probably need to be addressed.
/Ton (PayPal.me)
Re: Distance Sensor A02YYUW
Thank you Ath
I am trying to do a build with A02YYUW included, but i have not done a custom build for some time now, a few years, so i need to get into Platformio as i have not used it before.
I am trying to do a build with A02YYUW included, but i have not done a custom build for some time now, a few years, so i need to get into Platformio as i have not used it before.
Re: Distance Sensor A02YYUW
Then this will help in setting stuff up: https://espeasy.readthedocs.io/en/lates ... ormIO.html
Especially the Starters guide, just scroll a bit down that page
Especially the Starters guide, just scroll a bit down that page
/Ton (PayPal.me)
Re: Distance Sensor A02YYUW
I've adjusted the above code to current ESPEasy coding standards, and adapted to multi-instance use, so multiple sensors can be connected to a single ESPEasy device, only limited by the number of serial ports (each device requires its own serial port)
This is the PR #4168, and I'd need some help in testing, as I don't own this sensor. It is in the Collection A builds (previous name Test A, that has been changed very recently).
This is the PR #4168, and I'd need some help in testing, as I don't own this sensor. It is in the Collection A builds (previous name Test A, that has been changed very recently).
/Ton (PayPal.me)
Re: Distance Sensor A02YYUW
Yes, and probably more on builds that have the I2C serial support for SC16IS752 based boards included, like by default on ESP32.
/Ton (PayPal.me)
Re: Distance Sensor A02YYUW
Hi! I just flashed the ESP_Easy_mega_20220809_collection_A_ESP8266_4M1M.bin file into my Wemos D1 Mini, and I can't find this device in the list. I have two pieces of dfrobot A02YYUW which I would like to use with this single ESP8266 board. Which bin file could I use? Thank you very much.
Ath wrote: ↑01 Aug 2022, 15:50 I've adjusted the above code to current ESPEasy coding standards, and adapted to multi-instance use, so multiple sensors can be connected to a single ESPEasy device, only limited by the number of serial ports (each device requires its own serial port)
This is the PR #4168, and I'd need some help in testing, as I don't own this sensor. It is in the Collection A builds (previous name Test A, that has been changed very recently).
Re: Distance Sensor A02YYUW
This plugin is not merged into the regular release yet.
You will have to download a build from the PR, latest build is here, that does include that plugin. You will need to be logged in to Github to be able to download the Binaries zip file that contains a zip file for each build, select the one that has collection_A_ESP8266_4M1M in the name, and you should be good to go.
/Ton (PayPal.me)
Re: Distance Sensor A02YYUW
Thank you, got it!
Ath wrote: ↑31 Aug 2022, 13:25This plugin is not merged into the regular release yet.
You will have to download a build from the PR, latest build is here, that does include that plugin. You will need to be logged in to Github to be able to download the Binaries zip file that contains a zip file for each build, select the one that has collection_A_ESP8266_4M1M in the name, and you should be good to go.
Re: Distance Sensor A02YYUW
Any feedback is appreciated. You can also, instead of here, write that as a comment in Github, just choose what feels most appropriate to you.
/Ton (PayPal.me)
Re: Distance Sensor A02YYUW
Re: Distance Sensor A02YYUW
I just finished soldering them together. Both sensor works! At least they send the data, I didn't measure yet how accurate they are. I didn't use any pullup resitors or anything else, just wired directly to the Wemos D1 Mini board like this:
SENSOR1
Port: SoftwareSerial
Red wire: VCC 5V
Black wire: GND
White wire (TX): D1 (GPIO5)
Yellow wire (RX): not connected
SENSOR2
Port: HW Serial0 swap
Red wire: VCC 5V
Black wire: GND
White wire (TX): D7 (GPIO13)
Yellow wire (RX): D8 (GPIO15)
I used shielded 4x0.22 alarm cable, shield is connected to GND. Both cable is about 3m long, the signal seems stable.
Thanks for your great work!
Re: Distance Sensor A02YYUW
The accuracy isn't determined by the plugin, that's just providing the data that is received
Usually, serial connections don't use pull-up resistors, so that should be fine.
Not sure if the sensors will work (reliably) with 3.3V, not all ESP boards handle 5V on the GPIO's nicely (they could produce magic smoke...), but most D1 mini clones seem to handle it fine.
/Ton (PayPal.me)
Re: Distance Sensor A02YYUW
Still... if the TX from the ESP is only 3V3 and the device expects a slightly higher level then it also may work "flaky"
What may be useful however is to add a 500 Ohm resistor (or 470 Ohm, as the actual resistance value isn't that critical) in series with the TX line and/or RX.
This may prevent "ringing" in the signal where a pulse may "bounce" over and over on the cable between device and ESP causing noise.
Such a resistor in series will dampen these ringing effects.
Do this if you experience strange behavior and/or using relatively long cables.
What may be useful however is to add a 500 Ohm resistor (or 470 Ohm, as the actual resistance value isn't that critical) in series with the TX line and/or RX.
This may prevent "ringing" in the signal where a pulse may "bounce" over and over on the cable between device and ESP causing noise.
Such a resistor in series will dampen these ringing effects.
Do this if you experience strange behavior and/or using relatively long cables.
Re: Distance Sensor A02YYUW
Thanks, noted. They are both in a water tank now, measuring the water level. When the water surface is flat, the measurment seems rock stable. I'll be smarter after a week of operation.TD-er wrote: ↑31 Aug 2022, 23:14 Still... if the TX from the ESP is only 3V3 and the device expects a slightly higher level then it also may work "flaky"
What may be useful however is to add a 500 Ohm resistor (or 470 Ohm, as the actual resistance value isn't that critical) in series with the TX line and/or RX.
This may prevent "ringing" in the signal where a pulse may "bounce" over and over on the cable between device and ESP causing noise.
Such a resistor in series will dampen these ringing effects.
Do this if you experience strange behavior and/or using relatively long cables.
Re: Distance Sensor A02YYUW
Maybe you measure reflections?
A ripple on water may tilt the surface causing a longer path before it returns.
Perhaps taking the shortest sampled distance of a few measurements may give a more stable value?
A ripple on water may tilt the surface causing a longer path before it returns.
Perhaps taking the shortest sampled distance of a few measurements may give a more stable value?
Re: Distance Sensor A02YYUW
Yes, when I load the tank with fresh water, the surface ripples. Therefore the measurments are jumping, but only +- 20-40mm. Whis is correct, the size of the wave. Let's see in the coming days, if there will be any weird stuff.
Re: Distance Sensor A02YYUW
I can't imagine it is "only 20 - 40 mm"
Since the surface is tilted, you will reflect your signal in a different direction, which may bounce off the wall of the container, back to the ripple and back to your sensor.
So it will be causing some "echo" or "reverb" regardless whether you're measuring distance using ultrasonic sensor or laser.
Since the surface is tilted, you will reflect your signal in a different direction, which may bounce off the wall of the container, back to the ripple and back to your sensor.
So it will be causing some "echo" or "reverb" regardless whether you're measuring distance using ultrasonic sensor or laser.
Re: Distance Sensor A02YYUW
Using it since then, rock solid, very accurate. You right, when the water ripples, it's more than 20-40 mm, my bad. But not crazy numbers. I measure the water level every hour, except when filling up the tank, therefore I have no false measurement.
TD-er wrote: ↑01 Sep 2022, 21:36 I can't imagine it is "only 20 - 40 mm"
Since the surface is tilted, you will reflect your signal in a different direction, which may bounce off the wall of the container, back to the ripple and back to your sensor.
So it will be causing some "echo" or "reverb" regardless whether you're measuring distance using ultrasonic sensor or laser.
Re: Distance Sensor A02YYUW
Great!
Thanks for reporting back.
I just merged the PR into the main branch, so it will be included in the next build.
Thanks for reporting back.
I just merged the PR into the main branch, so it will be included in the next build.
Who is online
Users browsing this forum: No registered users and 0 guests