create new tag
view all tags

A simple push button switch

The simplest WeMosD1 shield is just features a single push button. It uses the WeMos' ESP8266 D3 pin which corresponds to GPIO 0.


Testing the switch

Before trying to integrate the switch into out IoT network and reading it's state through Cayenne we first write a simple test program to see if it works the way we expect.

The test program is very simple:


We define GPIO pin 0 to be an input pin (or pin 17 when running on an ESP32) with an internal pull-up resistor through the machine library class Pin. Then we read the pin value which tells us if the button is pressed or not. The switch connects GPIO 0 to ground if pressed.

Here is the source of this test program:


Upload it to the WeMos D1 flash and execute it in uPyCraft or thonny.

Once the hardware is tested we add the WiFi code and the connection to the myDevices MQTT broker.


This is what you should see in Cayenne:


The push button is connected to channel 1 in Cayenne and shows a state of 1 if pushed and 0 if released

-- Uli Raich - 2019-03-22


Topic attachments
I Attachment History Action Size Date Who Comment
PNGpng buttonCayenne.png r1 manage 164.4 K 2019-03-22 - 09:32 UliRaich  
PNGpng buttonTest.png r1 manage 36.0 K 2019-03-22 - 09:10 UliRaich  
PNGpng buttonuPyCraft.png r1 manage 184.2 K 2019-03-22 - 09:22 UliRaich  
PNGpng wemosPushbutton.png r1 manage 42.5 K 2019-03-22 - 09:02 UliRaich  
Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2019-05-17 - UliRaich
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback