Difference: SolutionsToTheExerciseOnSwitches (1 vs. 4)

Revision 42021-11-26 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="Solutions"

Solutions to the Exercise 3: Switches

Exercise 1:

Line: 46 to 46
 
META FILEATTACHMENT attachment="pbInterrupt.py.txt" attr="" comment="" date="1592213970" name="pbInterrupt.py.txt" path="pbInterrupt.py.txt" size="829" user="UliRaich" version="1"
META FILEATTACHMENT attachment="pbIntLED.py.txt" attr="" comment="" date="1592213970" name="pbIntLED.py.txt" path="pbIntLED.py.txt" size="876" user="UliRaich" version="1"
META FILEATTACHMENT attachment="pbPoll.py.txt" attr="" comment="" date="1592213970" name="pbPoll.py.txt" path="pbPoll.py.txt" size="973" user="UliRaich" version="1"
Changed:
<
<
META FILEATTACHMENT attachment="pirPoll.py.txt" attr="" comment="" date="1592213970" name="pirPoll.py.txt" path="pirPoll.py.txt" size="976" user="UliRaich" version="1"
>
>
META FILEATTACHMENT attachment="pirPoll.py.txt" attr="" comment="" date="1637961218" name="pirPoll.py.txt" path="pirPoll.py.txt" size="976" user="UliRaich" version="2"

Revision 32021-01-27 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="Solutions"

Solutions to the Exercise 3: Switches

Exercise 1:

This is very similar to switching a LED on or off. Again a single GPIO line is used. This time however the pin in programmed as input and we can add a pullup or pulldown resistor:

Changed:
<
<
_PB_PIN = 17
pushButton = Pin(_PB_PIN,Pin.IN,Pin.PULL_UP)  
>
>
_PB_PIN = 22
pushButton = Pin(_PB_PIN,Pin.IN,Pin.PULL_UP)  
  Once the pushButton pin is defined we can get its current state with:
Added:
>
>
 state = pushButton.value()

https://afnog.iotworkshop.africa/pub/IoT_Course_English/SolutionsToTheExerciseOnSwitches/pbPoll.py.txt

Revision 22020-06-15 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="Solutions"
Changed:
<
<

Solutions to the Exercises on Switches

Introductory remarks:

>
>

Solutions to the Exercise 3: Switches

 

Exercise 1:

Added:
>
>
This is very similar to switching a LED on or off. Again a single GPIO line is used. This time however the pin in programmed as input and we can add a pullup or pulldown resistor: _PB_PIN = 17
pushButton = Pin(_PB_PIN,Pin.IN,Pin.PULL_UP)  

Once the pushButton pin is defined we can get its current state with: state = pushButton.value()

https://afnog.iotworkshop.africa/pub/IoT_Course_English/SolutionsToTheExerciseOnSwitches/pbPoll.py.txt

Exercise 2:

The MicroPython documentation includes a chapter on writing interrupt service routines

http://docs.micropython.org/en/latest/reference/isr_rules.html

How to do this with GPIO lines is described in

http://docs.micropython.org/en/latest/esp8266/tutorial/pins.html

When using interrupts you may run into problems with bouncing of mechanical switches. The transition is not a single clear cut step function but may flip back and forth. Have a look at http://docs.micropython.org/en/latest/pyboard/tutorial/debounce.html for an explanation on how to eliminate this problem (software debounce algorithm).

https://afnog.iotworkshop.africa/pub/IoT_Course_English/SolutionsToTheExerciseOnSwitches/pbInterrupt.py.txt

Exercise 3:

Nothing much to be said here. Have a look at the solution:

https://afnog.iotworkshop.africa/pub/IoT_Course_English/SolutionsToTheExerciseOnSwitches/pbIntLED.py.txt

Exercise 4:

There is no difference in programming between a mechanical and a PIR switch. Just the GPIO line on which the switch is connected must be adapted.

https://afnog.iotworkshop.africa/pub/IoT_Course_English/SolutionsToTheExerciseOnSwitches/pirPoll.py.txt

 -- Uli Raich - 2020-05-06

Comments

Line: 12 to 41
 
<--/commentPlugin-->

META FILEATTACHMENT attachment="builtinLED.png" attr="" comment="" date="1588757539" name="builtinLED.png" path="builtinLED.png" size="18252" user="UliRaich" version="1"
Added:
>
>
META FILEATTACHMENT attachment="pbInterrupt.py.txt" attr="" comment="" date="1592213970" name="pbInterrupt.py.txt" path="pbInterrupt.py.txt" size="829" user="UliRaich" version="1"
META FILEATTACHMENT attachment="pbIntLED.py.txt" attr="" comment="" date="1592213970" name="pbIntLED.py.txt" path="pbIntLED.py.txt" size="876" user="UliRaich" version="1"
META FILEATTACHMENT attachment="pbPoll.py.txt" attr="" comment="" date="1592213970" name="pbPoll.py.txt" path="pbPoll.py.txt" size="973" user="UliRaich" version="1"
META FILEATTACHMENT attachment="pirPoll.py.txt" attr="" comment="" date="1592213970" name="pirPoll.py.txt" path="pirPoll.py.txt" size="976" user="UliRaich" version="1"

Revision 12020-05-06 - UliRaich

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="Solutions"

Solutions to the Exercises on Switches

Introductory remarks:

Exercise 1:

-- Uli Raich - 2020-05-06

Comments

<--/commentPlugin-->

META FILEATTACHMENT attachment="builtinLED.png" attr="" comment="" date="1588757539" name="builtinLED.png" path="builtinLED.png" size="18252" user="UliRaich" version="1"
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback