/Mock.GPIO

Mock Library for RPI.GPIO python Library

Primary LanguagePython

Mock.GPIO

Mock Library for RPI.GPIO python Library

The easiest way to use this package is to install using pip for python 2.7

$ sudo pip install Mock.GPIO

using pip3 for python 3

$ sudo pip3 install Mock.GPIO

To use the emulator just type the following at the beginning of your script.

from Mock.GPIO import GPIO

Works with

Simulation

This library simulates the following functions which are used in the RPi.GPIO library.

  • GPIO.setmode()
  • GPIO.getmode()
  • GPIO.setwarnings()
  • GPIO.setup()
  • GPIO.output()
  • GPIO.input()
  • GPIO.wait_for_edge()
  • GPIO.add_event_detect()
  • GPIO.event_detected()
  • GPIO.add_event_callback()
  • GPIO.remove_event_detect()
  • GPIO.gpio_function()
  • GPIO.start()
  • GPIO.ChangeFrequency()
  • GPIO.ChangeDutyCycle()
  • GPIO.stop()
  • GPIO.cleanup()

Usage:

import Mock.GPIO as GPIO

Documentation

Example:

The following python example/test.py

try:
    import RPi.GPIO as GPIO    
except:
    import Mock.GPIO as GPIO

import time

print "set mode"
GPIO.setmode(GPIO.BCM)
print "set warning false"
GPIO.setwarnings(False)
GPIO.setup(15,GPIO.OUT)
GPIO.output(15,GPIO.HIGH)
time.sleep(1)
GPIO.output(15,GPIO.LOW)

generates following output

$ python examples/test.py 
set mode
set warning false
2020-05-07 17:49:23,031:INFO: Set Warings as False
2020-05-07 17:49:23,031:INFO: setup channel : 15 as 0 with intial :0 and pull_up_dowm 20
2020-05-07 17:49:23,032:INFO: output channel : 15 with value : 1
2020-05-07 17:49:24,033:INFO: output channel : 15 with value : 0