Mock Library for RPI.GPIO python Library
Mock.GPIO is a python library that supports development of software/program and to debug them outside RPi (eg: ubuntu ). It can be intergrated along with any generic application/program/software.
It helps in making your programm/application run seamlessly, both outside and inside RPi by
The easiest way to use this package is to install using pip3 for python3
$ sudo pip3 install Mock.GPIOTo import the Mock library at the beginning of your script, use
import Mock.GPIO as GPIOTo enable seamless switching between Mock library when you are outside RPi and the actual RPi.GPIO library when you are inside RPi, use
try:
# checks if you have access to RPi.GPIO, which is available inside RPi
import RPi.GPIO as GPIO
except:
# In case of exception, you are executing your script outside of RPi, so import Mock.GPIO
import Mock.GPIO as GPIOThis library simulates the following functions which are used in the RPi.GPIO library.
import Mock.GPIO as GPIOThe 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 the following output
$ export LOG_LEVEL=Info
$ python examples/test.py
set mode
set warning false
2020-05-07 17:49:23,031:INFO: Set warnings as False
2020-05-07 17:49:23,031:INFO: Setup channel : 15 as 0 with initial :0 and pull_up_down 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 : 0make the suitable changes and from the root directory of this repository, install the Mock.GPIO python package using the install.sh script
$ sudo ./scripts/install.shStart contributing !