momsfriendlyrobotcompany / fake_rpi Goto Github PK
View Code? Open in Web Editor NEWfake interface for raspberry pi development and unit testing
Home Page: https://pypi.org/project/fake-rpi/
License: MIT License
fake interface for raspberry pi development and unit testing
Home Page: https://pypi.org/project/fake-rpi/
License: MIT License
importlib_metadata needs to be installed when using Python 3.6 and 3.7
It would be helpful to list that as a dependency or insert $ pip install importlib-metadata as a part of the installation.
Hi
Thanks for providing this helpful module.
Unfortunatly ...
The line GPIO.setmode(io.BCM)
Causes the pyton error ;- name 'io' not defined
( background ...tested using either python 2.7 or python 3.7, in Microsoft Visual Studio Community 2019, Version 16.7.4
using fake_rpi version 0.6.2 )
I got an IndexError
when calling RPi.GPIO.cleanup
without arguments.
int.setmode()
int.setup(1,)
int.setup(0,)
int.output(True,)
int.output(False,)
int.input(): 1
1
Traceback (most recent call last):
File "test.py", line 26, in <module>
GPIO.cleanup()
File "/usr/local/lib/python3.5/dist-packages/fake_rpi/wrappers.py", line 19, in wrapped
c = str(args[0].__class__).split('\'')
IndexError: tuple index out of range
# Replace libraries by fake ones
import sys
import fake_rpi
sys.modules['RPi'] = fake_rpi.RPi # Fake RPi (GPIO)
#sys.modules['smbus'] = fake_rpi.smbus # Fake smbus (I2C)
from RPi import GPIO
import random, time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(1, GPIO.IN)
GPIO.setup(2, GPIO.OUT)
GPIO.output(2, True)
GPIO.output(2, False)
input1 = GPIO.input(1)
print(input1)
GPIO.cleanup()
IC2 bytes have 8 bits, therefore returned values from fake generators shouldn't be greater than 255.
The following example shows the issue when converting potentially generated bytes to integer:
In [1]: int.from_bytes([1, 256], byteorder='big')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-1-724da94e3d44> in <module>
----> 1 int.from_bytes([1, 256], byteorder='big')
ValueError: bytes must be in range(0, 256)
Great project, guys.
Should this also be working with gpiozero or only RPi.GPIO?
I'm trying to set up travis-ci and am having the test fail.
If I´m using gpiozero the error I get is:
gpiozero.exc.PinUnknownPi: unable to locate Pi revision in /proc/device-tree or /proc/cpuinfo
and with RPi.GPIO,
travis doesn't seem to be able to find and install the library in the first place.
Running it locally on a RaspberryPi 2 Model B everything seems to be working well with both gpiozero and RPi.GPIO. (without fake_rpi)
I was hoping that you might have some pointers, since it seems like this was one of the intended uses of the project.
Hi,
I could make it work with fake RPi.GPIO
and smbus
in my application.
But I can't change all the imports (from from RPi.GPIO import GPIO
to from fake_rpi import GPIO
) in my project and all dependencies.
So I found a solution inspired by this stackoverflow answer something that replace the modules by this fake one:
import sys
import fake_rpi
sys.modules['RPi'] = fake_rpi
sys.modules['smbus'] = fake_rpi
# Then everywhere...
import RPi.GPIO as GPIO
import smbus
Then, I don't need to change my project and dependencies imports, I just have to replace modules once in my main file.
It could work if inside the folder fake_rpi
, there were another modules that reflect the RPi
, smbus
... modules
Do you think this way of using fake_rpi
is relevent ?
Function returns wrong type. List of integer instead of an integer. Maybe there are more mismatches.
fake_rpi/fake_rpi/smbus/smbus.py
Lines 29 to 31 in eb2f640
value
[185, 185]
type
<class 'list'>
value
65535
type
<class 'int'>
import sys
import fake_rpi
sys.modules['RPi'] = fake_rpi.RPi # Fake RPi (GPIO)
sys.modules['smbus'] = fake_rpi.smbus # Fake smbus (I2C)
import smbus
if __name__ == "__main__":
bus = smbus.SMBus(1)
value = bus.read_word_data(0x01, 1 << 1)
print("value")
print(value)
print("type")
print(type(value))
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.