Skip to main content
https://raw.githubusercontent.com/walchko/fake_rpi/master/pics/pi-python.jpg Code Health Latest Version License https://travis-ci.org/walchko/fake_rpi.svg?branch=master https://img.shields.io/pypi/pyversions/fake_rpi.svg

Why??

I do a lot of development on my Powerbook and I got tired of constantly creating a fake interface for dev on my laptop and testing on Travis.ci.

  • 2017 Apr 2: Beta Quality

  • 2017 Apr 8: Initial python3 support … this is a pain

So, does this simulate everything on a Raspberry Pi? No! Right now it simulates what I use and need. Over time, more will be added. You are also welcome to submit pull requests for things I haven’t added yet.

Adafruit

LSM303(accelerometer)

GPIO

gpio pins

picamera

camera

RPi

PWM

smbus

i2c

serial

not done yet

Install

The preferred way to install this is:

pip install fake_rpi

Development

To submit pull requests and do development:

git clone
cd fake_rpi
pip install -e .

Usage

To use as is:

from fake_rpi import GPIO as io
from fake_rpi import smbus
from fake_rpi import toggle_print

# by default it prints everything to std.error
toggle_print(False)  # turn on/off printing

io.setmode(io.BCM)
b = io.input(21)

sm = smbus.SMBus(1)
b = sm.read_byte_data(0x21, 0x32)  # read in a byte

But I need smbus to return a specific byte for unit testing! Ok, then create a child of my smbus like below and modify only the methods you need changed:

from fake_rpi import smbus
from fake_rpi import printf

class MyBus(smbus.SMBus):
        @printf
        def read_byte_data(self, i2c_addr, register):
                ret = 0xff
                if i2c_addr == 0x21:
                        ret = 0x55
                elif i2c_addr == 0x25:
                        ret = 0x11
                return ret

sm = MyBus()
b = sm.read_byte_data(0x21, 0x32)  # read in a byte

Printing On or Off

Here is the output from example.py in the git repo when the printing is toggled on or off:

kevin@Logan fake_rpi $ ./example.py
<<< WARNING: using fake raspberry pi interfaces >>>
kevin@Logan fake_rpi $ ./example.py
<<< WARNING: using fake raspberry pi interfaces >>>
fake_rpi.RPi.PWM.__init__()
fake_rpi.RPi.PWM.start(5,)
fake_rpi.smbus.SMBus.__init__(1,)
fake_rpi.smbus.SMBus.write_byte_data(1, 2, 3)
fake_rpi.smbus.SMBus.read_byte_data(1, 2): 21
fake_rpi.smbus.SMBus.close()
__main__.MyBus.__init__()
__main__.MyBus.read_byte_data(1, 2): 72
__main__.MyBus.read_i2c_block_data(1, 2, 3): [90, 90, 90]

ToDo

  • add serial

  • double check interfaces and flush them out better

Change Log

2017-04-08

0.1.0

initial python3 setup and support

2017-04-02

0.0.2

pushed to pypi with landscape.io fixes

2017-04-01

0.0.1

created

MIT License

Copyright (c) 2017 Kevin J. Walchko

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Release files for fake-rpi 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fake-rpi 0.1.1
File Size Uploaded
fake_rpi-0.1.1.tar.gz 5.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for fake-rpi 0.1.1
File Interpreter ABI Platform
fake_rpi-0.1.1-py3-none-any.whl Python 3 none any Details
fake_rpi-0.1.1-py2-none-any.whl Python 2 none any Details

Total release size: 24.6 kB

Release files / fake_rpi-0.1.1.tar.gz

Download URL fake_rpi-0.1.1.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
14b72fa5e3d0d9a5621accf48be508af29387f455a37d0c36c9f236fe30847eb
BLAKE2b-256 checksum
How to use checksums
43c6938dcfe229c89d4023b323bc86d0fd2c525dc20cc4aafa697da1b6aa295b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / fake_rpi-0.1.1-py3-none-any.whl

Download URL fake_rpi-0.1.1-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5e6cbab761db689e6c9572e49929a2fe0ead478d3838e02a1bfc1b3105853429
BLAKE2b-256 checksum
How to use checksums
349bd2349fc12764564052b6a498c211d8e2bf472ad9e17876f1c0df97ce5cea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / fake_rpi-0.1.1-py2-none-any.whl

Download URL fake_rpi-0.1.1-py2-none-any.whl
Size 9.7 kB
Tags Python 2
SHA-256 checksum
How to use checksums
bb65985fbbd43edb882060e1c7e5a45321db9688aa7d61ac66c9a7505b8a6cba
BLAKE2b-256 checksum
How to use checksums
74e68dcff1edb17f8a2e0b68e2927ee08a5f73e61f91671ceaf732edeb8f7125
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.7.1

2 release files

0.7.0

2 release files

0.6.3

2 release files

0.6.2

3 release files

0.6.1

3 release files

0.6.0

3 release files

0.5.4

3 release files

0.5.3

3 release files

0.5.2

3 release files

0.5.1

3 release files

0.5.0

3 release files

0.4.0

3 release files

0.3.1

3 release files

0.1.3

3 release files

0.1.2

3 release files

This release

0.1.1 This release

3 release files

0.1.0

3 release files

0.0.5

3 release files

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page