Any maker who uses the Raspberry Pi will almost certainly be familiar with the Python GPIO module (dubbed RPi.GPIO in code), which is used to program the general purpose input output pins (GPIO) on the Raspberry Pi. Using this module, I’ve implemented my own mini Python module called iopi (for input output pi) to allow for easier and faster pin control especially from within IDLE. Basically, I’ve condensed the standard GPIO functions like GPIO.setup() and GPIO.output() and added additional callable data. Since I hate having to look up the GPIO pin number of a pin like CE0, MOSI, or TXD when building electronics, I’ve added data to allow to call the pin’s ‘lettered’ name without having to look up its number.
My module iopi is geared to more efficient use of IDLE, and not toward writing permanent programs. The module uses only the broadcom pin numberings (GPIO.BCM) and warnings are set to False by default (GPIO.setwarnings(False)), and you can’t change them. But by not having to type them when you open an IDLE session, you can turn pins on and off much faster.
***Note that this is my first attempt at writing modules of any kind. Right now, the module won’t give an error if you pass the wrong type of argument to a function like setup(). In other words, IDLE won’t throw an error if you try to turn on a pin named ‘hello.’ Also note that currently iopi works only with Python 3.***
This is only version 0.0. I’ll be working on adding more functions and data, as well as polishing up the existing functions. Look at the code here. All the functions are listed.
If you want to install this module on your Raspberry Pi to try it out, there’s some steps you’ll have to take.
- Get the code from GitHub by clicking here. Using a USB thumb drive, transfer it to your Raspberry Pi.
- When Python imports a module (such as time, random, or RPi.GPIO) it searches for the module contents in a few specific places on the file system. In order to be able to import iopi.py as a module, you have to place your code in one of those specific places so that IDLE will find it when you enter import iopi.
- In IDLE, you can find out the locations that Python searches by importing the sys module with import sys, then typing sys.path, which spits out the absolute paths of the places where modules can be found.
- Now you need to put the iopi.py file in one those directories so that it can be used as a module.
- Either by opening the File Manager on the desktop or by using the terminal, navigate to the directory /usr/lib/python3/dist-packages. This specific ‘dist-packages’ directory is ideal for placing the iopi module because it’s where all the Raspberry Pi specific modules are located, like (RPi.GPIO, mcpi, and Picamera).
- From there, copy the iopi.py file to that directory either by drag-n-drop or with the mv command in the terminal.
- The module should be good to go! To test it, type ‘sudo python3‘ at the terminal and then type ‘import iopi‘ and try some functions.