5

I would like to do some simulation of the Raspberry's GPIO pins, e.g. for automated testing and developing the scripts on another host that is not the RPi.

Are there any existing tools/scripts(preferably in Python) available for that task?

4
  • Simulate? With what level of fidelity?
    – joan
    Feb 15, 2015 at 22:02
  • @joan it should at least enable me to run scripts and report written pin states.
    – Izzy
    Feb 16, 2015 at 14:45
  • So none of the special features such as SPI, I2C, hardware clocks, hardware PWM, internal pull-ups/pull-downs, interrupts etc. How do you plan to access the gpio? Through a library, through the file system?
    – joan
    Feb 16, 2015 at 15:08
  • Those features would be nice but not necessary. I am using RPi.GPIO most of time.
    – Izzy
    Feb 16, 2015 at 15:31

2 Answers 2

3

I do not know of any in existence, but implementing a test version of RPi.GPIO should be fairly straightforward, especially if, as @joan's comments are alluding, you don't need special features (or can implement them only as you need them, over time).

If you develop a class called "Test.GPIO" with the same interface as RPi.GPIO, then you could do automated tests by changing "import RPi.GPIO as GPIO" to "import Test.GPIO as GPIO" in all your code.

The implementation of simple pin reads would require some class state variables. For writes you could implement some random number generator. If you ever get to events and edge detection, you'd have to implement some threading just like RPi.GPIO does.

Depending on your testing requirements, you might need to implement some kind of test script that will be used by the Test.GPIO library to ensure consistent behavior across test runs.

This would be a good opportunity for someone who wants sharpen up their python skills.

0

Don't know if this helps, but you can check as well the Python simulator at https://create.withcode.uk/ that includes the RPi.GPIO library and can be pretty helpful when debugging code. It also includes a GPIO pinout board where you can see how the voltage changes on the selected pins.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.