Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obstruction Sensor Issue #36

Closed
mulcmu opened this issue Aug 13, 2023 · 2 comments
Closed

Obstruction Sensor Issue #36

mulcmu opened this issue Aug 13, 2023 · 2 comments

Comments

@mulcmu
Copy link
Contributor

mulcmu commented Aug 13, 2023

I have a brand new installation, everything is working except for the obstruction sensor feedback. Installation was done using a wemos_d1_mini32 as I plan to consolidate some other ESPhome devices currently in the garage into one node by the opener. Brand new RATGDO v2 pcb and have tested with two separate ESP boards.

The obstruction sensor still is detected properly by the garage door opener. I measure about 5.8V on the RATGDO terminal for obst/blk. Meter measures frequency of 143 Hz which is right for pulses spaced 7ms apart on this terminal as well. The RATGDO obst/blk terminal feeds the R1/R2 voltage divider into the D7 pin; continuity was confirmed so as far as I can tell the hardware setup should checkout.

I added some diagnostic log statements to the ISR routine and the obstruction loop. obsruction_low_count remains at zero. The log statement in the ISR never shows up in the log.

Any suggestions for additional troubleshooting?

    void IRAM_ATTR HOT RATGDOStore::isr_obstruction(RATGDOStore* arg)
    {
        // if (arg->input_obst.digital_read()) {
        //     arg->last_obstruction_high = millis();
        // } else {
        //     arg->obstruction_low_count++;
        // }

    arg->obstruction_low_count++;
    ESP_LOGD(TAG, "ISR");

    }

---------

    /*************************** OBSTRUCTION DETECTION ***************************/

    void RATGDOComponent::obstruction_loop()
    {
        long current_millis = millis();
        static unsigned long last_millis = 0;

        // the obstruction sensor has 3 states: clear (HIGH with LOW pulse every 7ms), obstructed (HIGH), asleep (LOW)
        // the transitions between awake and asleep are tricky because the voltage drops slowly when falling asleep
        // and is high without pulses when waking up

        // If at least 3 low pulses are counted within 50ms, the door is awake, not obstructed and we don't have to check anything else

        // Every 50ms
        if (current_millis - last_millis > 50) {
            // check to see if we got between 3 and 8 low pulses on the line
            if (this->isr_store_.obstruction_low_count >= 3 && this->isr_store_.obstruction_low_count <= 8) {
                // obstructionCleared();
                this->obstruction_state = ObstructionState::CLEAR;

                // if there have been no pulses the line is steady high or low
            } else if (this->isr_store_.obstruction_low_count == 0) {
                // if the line is high and the last high pulse was more than 70ms ago, then there is an obstruction present
                if (this->input_obst_pin_->digital_read() && current_millis - this->isr_store_.last_obstruction_high > 70) {
                    this->obstruction_state = ObstructionState::OBSTRUCTED;
                    // obstructionDetected();
                } else {
                    // asleep
                }
            }

            last_millis = current_millis;
            ESP_LOGD(TAG, "obstruction_low_count: %d",this->isr_store_.obstruction_low_count);
            this->isr_store_.obstruction_low_count = 0;
        }
    }

HA Install details:

    "installation_type": "Home Assistant OS",
    "version": "2023.8.2",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.11.4",
    "docker": true,
    "arch": "x86_64",
    "timezone": "America/New_York",
    "os_name": "Linux",
    "os_version": "6.1.39",
    "supervisor": "2023.08.1",
    "host_os": "Home Assistant OS 10.4",
    "docker_version": "23.0.6",
    "chassis": "vm",
    "run_as_root": true
    "esphome_version": "2023.7.1",

@mulcmu
Copy link
Contributor Author

mulcmu commented Aug 18, 2023

Errors in the logs during setup() related to gpio_install_isr_service(). The esp32:068 error will return from attach_interrupt() without setting the ISR callback.

[I][app:029]: Running through setup()...
[D][number:012]: 'Rolling code counter': Sending state 627.000000
[D][number:012]: 'Opening duration': Sending state 12.500000
[D][ratgdo:259]: Set opening duration: 12.5s
[D][number:012]: 'Closing duration': Sending state 12.400000
[D][ratgdo:265]: Set closing duration: 12.4s
[C][switch.gpio:011]: Setting up GPIO Switch 'Status door'...
[D][switch:016]: 'Status door' Turning OFF.
[D][switch:055]: 'Status door': Sending state OFF
[D][switch:016]: 'Status door' Turning OFF.
[C][switch.gpio:011]: Setting up GPIO Switch 'Status obstruction'...
[D][switch:016]: 'Status obstruction' Turning OFF.
[D][switch:055]: 'Status obstruction': Sending state OFF
[D][switch:016]: 'Status obstruction' Turning OFF.
[D][binary_sensor:034]: 'Dry contact open': Sending initial state OFF
[D][binary_sensor:034]: 'Dry contact close': Sending initial state OFF
[D][binary_sensor:034]: 'Dry contact light': Sending initial state OFF
[C][light:035]: Setting up light 'Light'...
[D][light:036]: 'Light' Setting:
[D][light:041]:   Color mode:
[D][esp-idf:000]: E (158) gpio: gpio_install_isr_service(449): GPIO isr service already installed
[E][esp32:068]: attach_interrupt(): call to gpio_install_isr_service() failed, error code: 259
[D][esp-idf:000]: E (169) gpio: gpio_install_isr_service(449): GPIO isr servicealready installed
[D][binary_sensor:034]: 'Motion': Sending initial state OFF
[D][binary_sensor:034]: 'Obstruction': Sending initial state OFF
[D][binary_sensor:034]: 'Button': Sending initial state OFF
[C][wifi:038]: Setting up WiFi...
[C][wifi:048]: Starting WiFi...

@mulcmu
Copy link
Contributor Author

mulcmu commented Aug 19, 2023

Fixed in #38

@mulcmu mulcmu closed this as completed Aug 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant