esphome / esphome-core

🚨 No longer used 🚨 - The C++ framework behind ESPHome
https://esphome.io/
GNU General Public License v3.0
545 stars 113 forks source link

Pulse counter GPIO as pull-up input #171

Closed voicevon closed 5 years ago

voicevon commented 5 years ago

In my case. The pulse counter is working very well. But I have to connect a pull up resistor. I tried to find out where to setup the pin enable the internal pull-up. But I can't find it. Please help.

TheJulianJES commented 5 years ago

I'm not sure if you're also using esphomeyaml to generate esphomelib code, so you could look at this article in the docs: https://esphomelib.com/esphomeyaml/guides/configuration-types.html#config-pin-schema It describes what you would add to the "mode" option in the pulse counter.

voicevon commented 5 years ago

Thanks for the link. I am not using esphomeYaml, Sorry, I don't know how to use it right now. I want to modify the source code at application code level.(Means I don't want to modify the code in /Lib and sub folder). For example, I expect I can do the configuration like:

  auto water = App.make_pulse_counter_sensor("water2",D8);
    water.pcnt->set_pin_mode(INPUT_PULLUP);   //There is no set_pin_mode();
voicevon commented 5 years ago

I am really sorry, This is a so stupid question.The answer is:

App.make_pulse_counter_sensor("water2",D8);
pinMode(D8,INPUT_PULLUP);
TheJulianJES commented 5 years ago

Haha, wasn't a stupid question. Glad you found it. ^^

OttoWinter commented 5 years ago

@voicevon I don't think that'll work (the pulse counter will override the pin mode). Almost all pin options in the esphomelib API take a GPIOPin instance.

App.make_pulse_counter_sensor("water2", GPIOInputPin(D8, INPUT_PULLUP));
voicevon commented 5 years ago

App.make_pulse_counter_sensor("water2",D8);
App.setup();
pinMode(D8,INPUT_PULLUP);     //This line must be after App.setup.Then it works fine. 

//Anyway,  GPIOPin instance is much much better than above.

App.make_pulse_counter_sensor("water2", GPIOInputPin(D8, INPUT_PULLUP));`