Project tutorial
Interrupts Debouncing with Zerynth (Python for IoT)

Interrupts Debouncing with Zerynth (Python for IoT) © GPL3+

In this tutorial, we'll see the advanced feature of interrupt debouncing using Zerynth.

  • 874 views
  • 0 comments
  • 4 respects

Components and supplies

Apps and online services

About this project

https://www.youtube.com/watch?v=iX2AlezDPVE&feature=youtu.be

In this tutorial, we'll use PWM to show the advanced feature of interrupt debouncing. PWM triggers fall and rise events at different speeds, but interrupts are triggered only if the debounce time (the stable time after and event) is in the correct range.

We’ll use Zerynth Studio to program the microcontroller-based board in Python.

Zerynth simplifies and speeds up IoT development allowing programming in Python or hybrid C/Python the most popular 32-bit microcontrollers and connecting them to the leading Cloud Infrastructures like AWS, Google Cloud, Microsoft Azure, IBM Watson, Ubidots, and many more.

Required Material

You need a board. You can select one of the 32-bit microcontroller devices supported by Zerynth. We’ve chosen the Arduino/Genuino MKR1000 (read Zerynth documentation here).

You also need:

Zerynth Studio, a powerful IDE for embedded programming in Python that enables the IoT. You can download it here.

Assembling

Connect pin D2 to D3 with a jumper. See the schematics.

Programming

Once you have installed Zerynth Studio and created a Zerynth user, you have to register and virtualize the board.

Clone and uplink the Zerynth example "Interrupts Debounce" as shown in the video. Open the Serial Monitor to see the interrupts printouts.

onPinRise and onPinFall are defined as follows

onPinFall(pin, fun, *args, debounce=0, time_unit=MILLIS)

onPinFall(pin, fun, *args, debounce=0, time_unit=MILLIS)

debounce and time_unit are used to define a timeout such that fun is called only if pin stays high for all the duration of the timeout.

Code

main.pyPython
################################################################################
# Interrupt Debounce
#
# Created by Zerynth Team 2015 CC
# Authors: G. Baldi, D. Mazzei
################################################################################

# import streams
import streams
# import pwm for testing
import pwm


# CONNECT pin D3 to PIN D2 for this example to work!

streams.serial()

def on_touch_up():
    print("touched UP")

def on_touch_dn():
    print("touched DN")
    

    
try:    
    # D2 will call touch_up on rise and touch_dn on fall with different debounce times
    onPinRise(D2,on_touch_up,debounce=500)
    onPinFall(D2,on_touch_dn,debounce=300)
except Exception as e:
    print(e)




while True:
    for x in [100,200,300,400,500,600,700,800,900]:
        print("--->",x, 1000-x)
        # start pwm on D3 with the current period
        pwm.write(D3.PWM,1000,x)
        # now wait and check if debounce is working
        sleep(5000)

Schematics

Schematics
Schematics flqyc3dfdz

Comments

Similar projects you might like

IoT Ambient Light: Zerynth Lamp

Project tutorial by Luigi Francesco Cerfeda

  • 7,344 views
  • 6 comments
  • 31 respects

Using Python and Arduino MKR1000 for Secure IoT

Project tutorial by Luigi Francesco Cerfeda

  • 9,162 views
  • 1 comment
  • 27 respects

IoT Thermometer Using Python

Project tutorial by Luigi Francesco Cerfeda

  • 7,717 views
  • 6 comments
  • 22 respects

IoT Blink - Getting started with IoT

Project showcase by AppShed Support

  • 2,026 views
  • 0 comments
  • 11 respects
Add projectSign up / Login