PushbuttonSwitch

Page Actions

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.

wemosPushbutton.png

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:

buttonuPyCraft.png

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:

https://github.com/uraich/MicroPython_IoTDemos/blob/master/drivers/button/button.py

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.

https://github.com/uraich/MicroPython_IoTDemos/blob/master/cayenne/button/cayenneButton.py

This is what you should see in Cayenne:

buttonCayenne.png

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

-- %USERSIG{UliRaich - 2019-03-22}%

Comments

 
I Attachment Action Size Date Who Comment
buttonCayenne.pngpng buttonCayenne.png manage 164 K 22 Mar 2019 - 09:32 UnknownUser  
buttonTest.pngpng buttonTest.png manage 35 K 22 Mar 2019 - 09:10 UnknownUser  
buttonuPyCraft.pngpng buttonuPyCraft.png manage 184 K 22 Mar 2019 - 09:22 UnknownUser  
wemosPushbutton.pngpng wemosPushbutton.png manage 42 K 22 Mar 2019 - 09:02 UnknownUser  
Topic revision: r3 - 17 May 2019, UliRaich