mrtoy-me / esphome-my-components

esphome components by me
3 stars 3 forks source link

After the update it gives me a result in mm when the result is in cm #6

Open Serrallonga25 opened 2 months ago

Serrallonga25 commented 2 months ago

Hi @mrtoy-me,

But after the update vl53l1x I get an incorrect result.

It gives me 67,000mm instead of 670mm

Could it be my fault or some bad configuration?

Thanks for your work.

mrtoy-me commented 2 months ago

@Serrallonga25 Not sure why you would see a change because the update I made does not change units and I still have correct number on my sensor in mm. Note: units of distance sensor are mm. Can you share your esphome yaml and any sensor setup changes in ha - then I might be able to suggest something

Serrallonga25 commented 2 months ago

Maybe the sensor is broken?

I use it in a diesel tank to measure the liters I have left

#https://github.com/mrtoy-me/esphome-my-components/tree/main/components/vl53l1x
external_components:
  #- source: components
  source:
    type: git
    url: https://github.com/mrtoy-me/esphome-my-components
    ref: main
  components: [vl53l1x]

#example configure I2C
i2c:
  - id: bus_a 
    sda: GPIO14
    scl: GPIO15
    scan: true

#I commented on this part after the update
#vl53l1x:
#  distance_mode: long
#  update_interval: 10s

sensor:
  - platform: vl53l1x
    i2c_id: bus_a
    distance_mode: long
    update_interval: 10s
    distance:
      name: "VL53L1X Time Of Flight Distance Sensor"
      id: caldera_mag_nivell_m_optic
      entity_category: 'diagnostic'

      #Add filter to convert to mm after update
      filters:
        - lambda: |-
            ESP_LOGE("VL53L1X Time Of Flight Distance Sensor", "%f", x);
            return x * 10;
    range_status:
      name: Range Status
      entity_category: 'diagnostic'
[12:39:19][I][i2c.arduino:096]: Results from i2c bus scan:
[12:39:19][I][i2c.arduino:102]: Found i2c device at address 0x29
[12:39:19][C][gpio.output:010]: GPIO Binary Output:
[12:39:19][C][gpio.output:011]:   Pin: GPIO4
[12:39:20][C][light:103]: Light 'Llum Camara Magatzem'
[12:39:20][C][wifi_info:014]: WifiInfo Mac Address 'Nivell Gasoil Mac Wifi Address'
[12:39:20][C][vl53l1x.sensor:333]: VL53L1X:
[12:39:20][D][vl53l1x.sensor:374]:   Setup successful - all versions
[12:39:20][I][vl53l1x.sensor:378]:   Found sensor: VL53L1X
[12:39:20][C][vl53l1x.sensor:392]:   Distance Mode: LONG
[12:39:20][D][vl53l1x.sensor:395]:   Timing Budget: 500ms
[12:39:20][D][vl53l1x.sensor:396]:   Intermediate Period: 500ms
[12:39:20][C][vl53l1x.sensor:398]:   Address: 0x29
[12:39:20][C][vl53l1x.sensor:399]:   Update Interval: 10.0s
[12:39:20][C][vl53l1x.sensor:402]:   Distance Sensor: 'VL53L1X Time Of Flight Distance Sensor'
[12:39:20][C][vl53l1x.sensor:402]:     Device Class: 'distance'
[12:39:20][C][vl53l1x.sensor:402]:     State Class: 'measurement'
[12:39:20][C][vl53l1x.sensor:402]:     Unit of Measurement: 'mm'
[12:39:20][C][vl53l1x.sensor:402]:     Accuracy Decimals: 0
[12:39:20][C][vl53l1x.sensor:405]:   Range Status Sensor: 'Range Status'
[12:39:20][C][vl53l1x.sensor:405]:     State Class: 'measurement'
[12:39:20][C][vl53l1x.sensor:405]:     Unit of Measurement: ''
[12:39:20][C][vl53l1x.sensor:405]:     Accuracy Decimals: 0
[12:39:26][E][VL53L1X Time Of Flight Distance Sensor:180]: 97.000000
[12:39:26][D][sensor:094]: 'VL53L1X Time Of Flight Distance Sensor': Sending state 970.00000 mm with 0 decimals of accuracy

If it measures correctly for you, the sensor may be failing, as I have noticed that it gets stuck after a while and says it has failed.

But it seems strange to me that it truncates a digit in the result.

mrtoy-me commented 2 months ago

few questions So what is the correct distance in mm

What is purpose of filters:

So sensor is giving 97mm and you are multiplying by 10 to make it 970mm, so I am guessing you were expecting 970mm is that right. I check the sensor by aiming it at a flat surface at a few different distances.

Is your range stays always 0 if not that is a problem with the conditions the sensor is measuring in

I am interested that it get stuck and fails - can you give me any logs of a fail. There a quite a few error msg depending on cause of fail

mrtoy-me commented 2 months ago

Also are you using IDF or arduino and what esp are you using

Serrallonga25 commented 2 months ago

I have downloaded the old version from 2 months ago and I also get the truncated result but it gives me a different value

[12:55:01][C][i2c.arduino:071]: I2C Bus:
[12:55:01][C][i2c.arduino:072]:   SDA Pin: GPIO14
[12:55:01][C][i2c.arduino:073]:   SCL Pin: GPIO15
[12:55:01][C][i2c.arduino:074]:   Frequency: 50000 Hz
[12:55:01][C][i2c.arduino:086]:   Recovery: bus successfully recovered
[12:55:01][I][i2c.arduino:096]: Results from i2c bus scan:
[12:55:01][I][i2c.arduino:102]: Found i2c device at address 0x29
[12:55:01][C][gpio.output:010]: GPIO Binary Output:
[12:55:01][C][gpio.output:011]:   Pin: GPIO4
[12:55:01][C][light:103]: Light 'Llum Camara Magatzem'
[12:55:02][C][wifi_info:014]: WifiInfo Mac Address 'Nivell Gasoil Mac Wifi Address'
[12:55:02][C][vl53l1x.sensor:338]: VL53L1X:
[12:55:02][D][vl53l1x.sensor:354]:   Setup successful
[12:55:02][I][vl53l1x.sensor:358]:   Found sensor: VL53L1X
[12:55:02][C][vl53l1x.sensor:372]:   Distance Mode: LONG
[12:55:02][D][vl53l1x.sensor:375]:   Timing Budget: 500ms
[12:55:02][D][vl53l1x.sensor:376]:   Intermediate Period: 500ms
[12:55:02][C][vl53l1x.sensor:377]:   Address: 0x29
[12:55:02][C][vl53l1x.sensor:378]:   Update Interval: 10.0s
[12:55:02][C][vl53l1x.sensor:379]:   Distance Sensor: 'VL53L1X Time Of Flight Distance Sensor'
[12:55:02][C][vl53l1x.sensor:379]:     Device Class: 'distance'
[12:55:02][C][vl53l1x.sensor:379]:     State Class: 'measurement'
[12:55:02][C][vl53l1x.sensor:379]:     Unit of Measurement: 'mm'
[12:55:02][C][vl53l1x.sensor:379]:     Accuracy Decimals: 0
[12:55:02][C][vl53l1x.sensor:380]:   Range Status Sensor: 'Range Status'
[12:55:02][C][vl53l1x.sensor:380]:     State Class: 'measurement'
[12:55:02][C][vl53l1x.sensor:380]:     Unit of Measurement: ''
[12:55:02][C][vl53l1x.sensor:380]:     Accuracy Decimals: 0
[12:55:03][E][VL53L1X Time Of Flight Distance Sensor:180]: 80.000000
[12:55:03][D][sensor:094]: 'VL53L1X Time Of Flight Distance Sensor': Sending state 800.00000 mm with 0 decimals of accuracy
Serrallonga25 commented 2 months ago

IDF o Arduino Are you referring to the platform configuration?


esphome:
name: $hostname
platform: ESP32
board: esp32dev
mrtoy-me commented 2 months ago

Framework type - but by logs it is arduino.

The difference between 97 and 80 with old code is not the code, it is accuracy of sensor, so that's ok. So your sensor is reading 79mm (or 80mm)

Serrallonga25 commented 2 months ago

The correct measurement is 780mm, not 78mm

[14:15:59][I][i2c.arduino:096]: Results from i2c bus scan:
[14:15:59][I][i2c.arduino:102]: Found i2c device at address 0x29
[14:15:59][C][gpio.output:010]: GPIO Binary Output:
[14:15:59][C][gpio.output:011]:   Pin: GPIO4
[14:15:59][C][light:103]: Light 'Llum Camara Magatzem'
[14:15:59][C][wifi_info:014]: WifiInfo Mac Address 'Nivell Gasoil Mac Wifi Address'
[14:15:59][C][vl53l1x.sensor:333]: VL53L1X:
[14:15:59][E][vl53l1x.sensor:343]:   Data ready communication error
[14:15:59][E][component:082]:   Component vl53l1x.sensor is marked FAILED

[14:06:37][W][component:237]: Component vl53l1x.sensor took a long time for an operation (54 ms).
[14:06:37][W][component:238]: Components should block for at most 30 ms.
[14:07:22][W][vl53l1x.sensor:487]: Error reading Interrupt Polarity
[14:07:22][W][component:157]: Component vl53l1x.sensor set Warning flag: unspecified
[14:07:22][E][component:119]: Component vl53l1x.sensor was marked as failed.
[14:07:22][E][component:164]: Component vl53l1x.sensor set Error flag: unspecified

image

I don't know what happened, but in some update eshome broke or maybe the sensor broke.

I'll try another board that I have to see if it's the esp32cam that has always been a bit of a fool.

Serrallonga25 commented 2 months ago

Now it measures correctly

I think I wasted your time, sorry, all I did was clean the sensor casing.

But since it coincided with the update, I got confused

[14:24:53][I][i2c.arduino:096]: Results from i2c bus scan:
[14:24:53][I][i2c.arduino:102]: Found i2c device at address 0x29
[14:24:53][C][gpio.output:010]: GPIO Binary Output:
[14:24:53][C][gpio.output:011]:   Pin: GPIO4
[14:24:53][C][light:103]: Light 'Llum Camara Magatzem'
[14:24:53][C][wifi_info:014]: WifiInfo Mac Address 'Nivell Gasoil Mac Wifi Address'
[14:24:53][C][vl53l1x.sensor:333]: VL53L1X:
[14:24:53][D][vl53l1x.sensor:374]:   Setup successful - all versions
[14:24:53][I][vl53l1x.sensor:378]:   Found sensor: VL53L1X
[14:24:53][C][vl53l1x.sensor:392]:   Distance Mode: LONG
[14:24:53][D][vl53l1x.sensor:395]:   Timing Budget: 500ms
[14:24:53][D][vl53l1x.sensor:396]:   Intermediate Period: 500ms
[14:24:53][C][vl53l1x.sensor:398]:   Address: 0x29
[14:24:53][C][vl53l1x.sensor:399]:   Update Interval: 60.0s
[14:24:53][C][vl53l1x.sensor:402]:   Distance Sensor: 'VL53L1X Time Of Flight Distance Sensor'
[14:24:53][C][vl53l1x.sensor:402]:     Device Class: 'distance'
[14:24:53][C][vl53l1x.sensor:402]:     State Class: 'measurement'
[14:24:53][C][vl53l1x.sensor:402]:     Unit of Measurement: 'mm'
[14:24:53][C][vl53l1x.sensor:402]:     Accuracy Decimals: 0
[14:24:53][C][vl53l1x.sensor:405]:   Range Status Sensor: 'Range Status'
[14:24:53][C][vl53l1x.sensor:405]:     State Class: 'measurement'
[14:24:53][C][vl53l1x.sensor:405]:     Unit of Measurement: ''
[14:24:53][C][vl53l1x.sensor:405]:     Accuracy Decimals: 0
[14:25:35][E][VL53L1X Time Of Flight Distance Sensor:180]: 781.000000
[14:25:35][D][sensor:094]: 'VL53L1X Time Of Flight Distance Sensor': Sending state 7810.00000 mm with 0 decimals of accuracy

Output without filter:

[14:30:48][E][VL53L1X Time Of Flight Distance Sensor:180]: 776.000000
[14:30:48][D][sensor:094]: 'VL53L1X Time Of Flight Distance Sensor': Sending state 776.00000 mm with 0 decimals of accuracy

Let's see if the blocks disappear too. Thanks and sorry again

Serrallonga25 commented 2 months ago

Good morning, now it takes the correct measurement but it continues to block

[00:38:55][D][sensor:094]: 'VL53L1X Time Of Flight Distance Sensor': Sending state 763.00000 mm with 0 decimals of accuracy
[00:38:55][D][sensor:094]: 'Range Status': Sending state 0.00000  with 0 decimals of accuracy
[00:39:55][D][sensor:094]: 'VL53L1X Time Of Flight Distance Sensor': Sending state 769.00000 mm with 0 decimals of accuracy
[00:39:55][D][sensor:094]: 'Range Status': Sending state 0.00000  with 0 decimals of accuracy
[00:40:37][W][vl53l1x.sensor:495]: Error reading Data Ready
[00:40:37][W][component:157]: Component vl53l1x.sensor set Warning flag: unspecified
[00:40:37][E][component:119]: Component vl53l1x.sensor was marked as failed.
[00:40:37][E][component:164]: Component vl53l1x.sensor set Error flag: unspecified
mrtoy-me commented 2 months ago

The issue seems to be that there is an error reading a register ( for data ready) which creates a warning but then the it fails. You were getting a similar issue before you cleaned the sensor. I have not seem that issue on my sensor, let me have a look at the code and see if I can make a change that might help not cause the sensor to fail. The blocking issue is not really an issue, but a symptom of reads or writes taking longer than they should. Busy tonight but I will get back to you in the next day or so and let you know what I have changed. Thanks for all the info on how your sensor is performing with my component

mrtoy-me commented 2 months ago

@Serrallonga25 I have made a new branch in VL54L1X called "allow-some-fails-warnings" - I have given it a quick try and it seems to be working for me with no warnings or errors. If you want to try this version, I have stopped it failing immediately there is a data ready error or any warnings - you will see the error or warning message but it will not fail immediately. If the errors or warnings persistent for a few iterations without a valid reading then it will fail. Also if there is an update and there is not a new value from the sensor then you get NaN (not a number). Look forward to your feedback.

Serrallonga25 commented 2 months ago

Thanks @mrtoy-me , I'll try it and let you know.

Serrallonga25 commented 2 months ago

Hi @mrtoy-me , I've had it working without any problems for 3 days now, it seems to be resolved.

I only get the following warning from time to time (but it happens to me on other sensors)

[14:42:44][W][component:237]: Component vl53l1x.sensor took a long time for an operation (52 ms).
[14:42:44][W][component:238]: Components should block for at most 30 ms.

Thanks

Serrallonga25 commented 2 months ago

It seems like he was waiting for me to say there was no problem.

[15:42:44][W][component:237]: Component vl53l1x.sensor took a long time for an operation (51 ms).
[15:42:44][W][component:238]: Components should block for at most 30 ms.
[15:43:44][D][sensor:094]: 'VL53L1X Time Of Flight Distance Sensor': Sending state 726.00000 mm with 0 decimals of accuracy
[15:43:44][D][sensor:094]: 'VL53L1X kalman': Sending state 721.21735 mm with 0 decimals of accuracy
[15:43:44][D][sensor:094]: 'Diposit 1000L': Sending state 259.97620 L with 0 decimals of accuracy
[15:43:44][D][sensor:094]: 'Range Status': Sending state 0.00000  with 0 decimals of accuracy
[15:44:20][W][vl53l1x.sensor:524]: Error reading Data Ready
[15:44:20][W][component:157]: Component vl53l1x.sensor set Warning flag: unspecified
[15:44:21][E][vl53l1x.sensor:418]: Multiple consecutive attempts to read sensor without clearing warning
[15:44:21][E][component:119]: Component vl53l1x.sensor was marked as failed.
[15:44:21][E][component:164]: Component vl53l1x.sensor set Error flag: unspecified
mrtoy-me commented 2 months ago

Thanks so much for doing the testing and providing the error codes. Was the component failing after a day or two prior to the recent update removing the vl53l0x hub setup ?

Serrallonga25 commented 2 months ago

Maybe it had failed before but I hadn't detected it or because I wasn't looking at it so closely I hadn't noticed.

But what surprises me is that you tell me that it doesn't fail for you.

It could be the fault of my sensor from AliExpress and it doesn't have enough quality.

https://es.aliexpress.com/item/1005003091941068.html?spm=a2g0o.order_list.order_list_main.66.5df0194dyICWSn&gatewayAdapt=glo2esp

At the moment it is working again after restarting.

Thanks

mrtoy-me commented 2 months ago

I have got it to fail not sure if it is same cause as you yet - so I am doing more testing and will make some changes when finished - will let you know

Serrallonga25 commented 2 months ago

Thanks

Today I found the error again and had to restart.

[01:53:14][D][sensor:094]: 'VL53L1X Time Of Flight Distance Sensor': Sending state 725.00000 mm with 0 decimals of accuracy
[01:53:14][D][sensor:094]: 'Diposit 1000L Quantile': Sending state 257.53421 L with 0 decimals of accuracy
[01:53:14][D][sensor:094]: 'VL53L1X kalman': Sending state 725.88647 mm with 0 decimals of accuracy
[01:53:14][D][sensor:094]: 'Diposit 1000L': Sending state 253.58014 L with 0 decimals of accuracy
[01:53:14][D][sensor:094]: 'Range Status': Sending state 0.00000  with 0 decimals of accuracy
[01:53:14][W][component:237]: Component vl53l1x.sensor took a long time for an operation (56 ms).
[01:53:14][W][component:238]: Components should block for at most 30 ms.
[01:54:09][W][vl53l1x.sensor:515]: Error reading Interrupt Polarity
[01:54:09][W][component:157]: Component vl53l1x.sensor set Warning flag: unspecified
[01:54:10][E][vl53l1x.sensor:418]: Multiple consecutive attempts to read sensor without clearing warning
[01:54:10][E][component:119]: Component vl53l1x.sensor was marked as failed.
[01:54:10][E][component:164]: Component vl53l1x.sensor set Error flag: unspecified
mrtoy-me commented 2 months ago

Have not forgotten - I have been making incremental changes and testing along the way but it takes a few days to test each time to see if it fails - I am not on my usual test system and I am getting some fails after a while so still working on it. Will let you know when I have something.

Serrallonga25 commented 2 months ago

Thank you for your effort

mrtoy-me commented 1 month ago

@Serrallonga25 OK so I have changed quite a few things internally but what seems to have fixed the issue with the sensor stopping after a few days is running at a higher i2c frequency (default arduino is 50khz) - I have had a sensor running for nearly 5 days now at i2c frequency: 200khz also I have set timeout: 1ms which removes the component taking too long warnings.

i2c:
  - id: bus_a 
    sda: xx
    scl: yy
    frequency: 200kHz
    scan: true
    timeout: 1ms

So try above with the updated component and let me know how it goes. I will keep testing and cleanup the code when I am have done some more testing.

Serrallonga25 commented 1 month ago

Hi, when downloading the latest version it gets stuck on startup and does not initialize any type of connection, I can't even see the logs.

I'll try to compile it on another board that I have to see if I can see the exact error via USB.

I have now configured the frequency and timeout with the latest version that worked, let's see how it goes.

I'll keep you informed and thanks.

mrtoy-me commented 1 month ago

Apologies, I have been offline - my sensor failed after just over 6 days on 200khz - I am trying 400khz now. So you might want your hold off testing for a while until I do more. Starting to think it is a hardware issue because the i2c seems to stop working but I will persist. I am thinking of converting the polulo library to esphome and see how that goes.

Serrallonga25 commented 1 month ago

Hi, I have reinstalled the previous version from February before updating and I have had two days without errors, now I have compiled it by mistake and I have restarted the device but it seems to be the most stable one, I do not get errors or crashes.

This is the configuration.

[09:26:33][C][i2c.arduino:071]: I2C Bus:
[09:26:33][C][i2c.arduino:072]:   SDA Pin: GPIO14
[09:26:33][C][i2c.arduino:073]:   SCL Pin: GPIO15
[09:26:33][C][i2c.arduino:074]:   Frequency: 50000 Hz
[09:26:33][C][i2c.arduino:077]:   Timeout: 1 ms
[09:26:33][C][i2c.arduino:086]:   Recovery: bus successfully recovered
[09:26:33][I][i2c.arduino:096]: Results from i2c bus scan:
[09:26:33][I][i2c.arduino:102]: Found i2c device at address 0x29

[09:26:33][C][vl53l1x.sensor:338]: VL53L1X:
[09:26:33][D][vl53l1x.sensor:354]:   Setup successful
[09:26:33][I][vl53l1x.sensor:358]:   Found sensor: VL53L1X
[09:26:33][C][vl53l1x.sensor:372]:   Distance Mode: LONG
[09:26:33][D][vl53l1x.sensor:375]:   Timing Budget: 500ms
[09:26:33][D][vl53l1x.sensor:376]:   Intermediate Period: 500ms
[09:26:33][C][vl53l1x.sensor:377]:   Address: 0x29
[09:26:33][C][vl53l1x.sensor:378]:   Update Interval: 10.0s
[09:26:33][C][vl53l1x.sensor:379]:   Distance Sensor: 'VL53L1X Time Of Flight Distance Sensor'
[09:26:33][C][vl53l1x.sensor:379]:     Device Class: 'distance'
[09:26:33][C][vl53l1x.sensor:379]:     State Class: 'measurement'
[09:26:33][C][vl53l1x.sensor:379]:     Unit of Measurement: 'mm'
[09:26:33][C][vl53l1x.sensor:379]:     Accuracy Decimals: 0
[09:26:33][C][vl53l1x.sensor:380]:   Range Status Sensor: 'Range Status'
[09:26:33][C][vl53l1x.sensor:380]:     State Class: 'measurement'
[09:26:33][C][vl53l1x.sensor:380]:     Unit of Measurement: ''
[09:26:33][C][vl53l1x.sensor:380]:     Accuracy Decimals: 0
i2c:
  - id: bus_a 
    sda: GPIO14
    scl: GPIO15
    scan: true
    timeout: 1ms

vl53l1x:
  distance_mode: long
  update_interval: 10s

sensor:
  - platform: vl53l1x
    i2c_id: bus_a
    distance:
      name: "VL53L1X Time Of Flight Distance Sensor"
      id: caldera_mag_nivell_m_optic
      entity_category: 'diagnostic'
    range_status:
      name: Range Status
      entity_category: 'diagnostic'

If you need me to do any testing, let me know. Thanks for your work and time

mrtoy-me commented 1 month ago

Thankyou - just so I confirm that I understand, you are running a version from February and it is ok so far?

Thanks for the offer to test, I will get you a version which uses February code but I will leave it a few weeks probably. Let me know if what you are you are running now has any issues- Thanks.

mrtoy-me commented 1 month ago

What version of esphome are you using to compile?

Serrallonga25 commented 1 month ago

Today I got the latest version, so I compiled it without realizing it. It had been working fine for 2 or 3 days. [10:05:07][I][app:100]: ESPHome version 2024.10.2 compiled on Oct 24 2024, 08:38:30

[10:11:10][D][sensor:094]: 'VL53L1X Time Of Flight Distance Sensor': Sending state 814.00000 mm with 0 decimals of accuracy
[10:11:10][D][sensor:094]: 'Range Status': Sending state 0.00000  with 0 decimals of accuracy
[10:11:10][W][component:237]: Component vl53l1x took a long time for an operation (51 ms).
[10:11:10][W][component:238]: Components should block for at most 30 ms.
[10:11:20][D][sensor:094]: 'VL53L1X Time Of Flight Distance Sensor': Sending state 818.00000 mm with 0 decimals of accuracy
[10:11:20][D][sensor:094]: 'Range Status': Sending state 0.00000  with 0 decimals of accuracy

202402 esphome-my-components-54ed55e0349bec50aa7321a0243073705745ec24.zip

I get some warnings but it seems to work fine, I am attaching the version I compiled now. I will keep you informed

mrtoy-me commented 1 month ago

@Serrallonga25 In your zip file which one are you using vl53l1x or vl53l1x_allversions_esphome - I assume the vl53l1x directory. If that is the case, definitely let me know if it ever stops working.

Serrallonga25 commented 1 month ago

Yes, the vl53l1x is correct. I'll keep you informed

Serrallonga25 commented 1 month ago

Hi, @mrtoy-me Yesterday I had a power outage and it restarted but it worked correctly without any errors after 6 days

mrtoy-me commented 1 month ago

Thank you for the feedback, appreciate it. I have one running about 4.5 days now with same underlying i2c read/write as you are running but idf with 400mhz i2c.