Skip to content

Commit

Permalink
Pullup pulldown (#42)
Browse files Browse the repository at this point in the history
* describing how to connect the button
* links added
* support for pullup
  • Loading branch information
pfichtner authored Jan 5, 2024
1 parent 2f996ad commit ae66f27
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Features
- Configurable via Web-Interface so no need to compile your own firmware, you just need to download and to flash the microcontroller (see https://tasmota.github.io/docs/Getting-Started/#flashing for example for how to flash a D1 mini). Please note: Those values can be changed by anyone having access to your network since there is no authentication/authorization (yet) implemented!
- Acts as normal SIP-Client so it can be used not only with TR064-enabled devices but every SIP-Server/SIP-enabled hardware
- Can can be initiated via 433 MHz signal (e.g. wireless doorbell sender)
- Can can be initiated via button (e.g. a simple push button and/or optocoppler to make an existent doorbell a smart doorbell). The call gets initiated when the pin gets HIGH, so when connecting a button you would have to use pulldown resistor
- Can can be initiated via button/momentary switch (e.g. a simple push button and/or optocoppler to make an existent doorbell a smart doorbell). Supported pin modes are pullup (with and w/o internal resistor, LOW indicates button pressed) and pulldown (HIGH indicates button pressed)
- Can switch GPIO pin on ring (e.g. to visualize via LED and/or do some action on another microcontroller)
- Can publish mqtt messages on ring so other tasks can be done via integration platforms like ioBroker, home assistant, node red, ...

Expand Down
11 changes: 10 additions & 1 deletion configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@
"type": "int16_t",
"value": "-1"
},
{
"name": "button_gpiopin_mode",
"label": "Input mode of the GPIO Pin to connect a push button which triggers a call",
"type": "char",
"length": 20,
"control": "select",
"options": ["", "PULLUP", "PULLUP (internal)", "PULLDOWN"],
"value": ""
},
{
"name": "switch_gpiopin",
"label": "GPIO Pin switched HIGH when button press detected",
Expand Down Expand Up @@ -134,4 +143,4 @@
"value": "Doorbell #1"
}

]
]
27 changes: 25 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ unsigned long dialingStartedAt;
// RCSWITCH
RCSwitch mySwitch = RCSwitch();

// gpio input can be configured pullup and pulldown, so HIGH or LOW could signal a button press
int pin_pressed_is = HIGH;

// Tasks
struct task
{
Expand Down Expand Up @@ -94,9 +97,28 @@ void inputPinBegin(void)
{
if (configManager.data.button_gpiopin > 0)
{
Serial.print(F("GPIO "));
Serial.print(configManager.data.button_gpiopin);
Serial.println(F(" configured for input button"));
Serial.print(F(" configured for input button "));
pinMode(configManager.data.button_gpiopin, INPUT);

if (strcmp("PULLUP", configManager.data.button_gpiopin_mode) == 0)
{
Serial.println(F("pullup"));
pin_pressed_is = LOW;
}
else if (strcmp("PULLUP (internal)", configManager.data.button_gpiopin_mode) == 0)
{
Serial.println(F("pullup (internal)"));
pinMode(configManager.data.button_gpiopin, INPUT_PULLUP);
pin_pressed_is = LOW;
}
else
{
// PULLDOWN
Serial.println(F("pulldown"));
pin_pressed_is = HIGH;
}
}
else
{
Expand Down Expand Up @@ -187,8 +209,9 @@ void dial(void)

void buttonLoop(void)
{
if (digitalRead(configManager.data.button_gpiopin) == HIGH)
if (digitalRead(configManager.data.button_gpiopin) == pin_pressed_is)
{
Serial.print(F("GPIO "));
Serial.print(configManager.data.button_gpiopin);
Serial.println(F(" button press detected"));
dial();
Expand Down

0 comments on commit ae66f27

Please sign in to comment.