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 with an internal pull-up resistor through the
machine library call
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://iotworkshop.africa/pub/AFNOG/PushbuttonSwitch/button.py.txt
Please rename this file to button.py after download. Then upload it to the WeMos D1 flash and execute it in uPyCraft.
Once the hardware is tested we add the code WiFi and the connection to the myDevices MQTT broker.
https://iotworkshop.africa/pub/AFNOG/PushbuttonSwitch/cayenneButton.py.txt
This is what you should see in Cayenne:
The push button is connect to channel 1 in Cayenne and shows a state of 1 if pushed and 0 if released
--
Uli Raich - 2019-03-22
Comments