Skip to the content.

Home

Python Interface for GPIO Circuits

This package provides two related capabilities. First, it provides a high-level, event-driven Python interface for GPIO circuits running on the Raspberry Pi. Sensors, motors, LEDs, switches, and many other components are covered.

Remote Control of GPIO Circuits via REST/HTML/JavaScript

Second, this package enables remote control of GPIO circuits via REST APIs invoked from HTML/JavaScript front-ends. Want to control your circuit remotely from your phone? Look no further. This package auto-generates HTML/JavaScript for GPIO circuits based on Material Design for Bootstrap. These HTML/JavaScript elements can be embedded in full web pages for remote control of the circuit. The remote control screen for the Freenove Smart Car is shown below:

freenove-smart-car

As another example, consider the 3D-printed robotic arm that I designed for the car:

CAD Parts and 3D Printing

I have designed a range of parts for integration with the Raspberry Pi. See here.

Use and Development

Raspberry Pi now provides a 64-bit Debian-based operating system (OS) via the Raspberry Pi Imager. The OS is quite good, though for some uses Ubuntu seems to work equally well if not better. I’ve written steps for both operating systems here and here, respectively. The following steps use poetry for installation.

The raspberry-py package can be consumed in two ways:

  1. Add raspberry-py to a project as a PyPI dependency. This is the best approach if you only want to use the functionality provided by raspberry-py. The raspberry-py package is available here, and an example of adding the package dependency is provided here.
  2. Fork the present repository and then install it locally. This is the best approach if you want to enhance and/or fix the functionality provided by raspberry-py. In the following, XXXX is the user account into which the repository is forked:
    git clone git@github.com:XXXX/raspberry-py.git
    cd raspberry-py
    poetry env use 3.11
    poetry install
    

    From here, you can push back to your fork and submit a pull request to the original if desired.

Incrementing and Tagging Versions with Poetry

  1. Begin the next prerelease number within the current prerelease phase (e.g., 0.1.0a00.1.0a1):
    OLD_VERSION=$(poetry version --short)
    poetry version prerelease
    VERSION=$(poetry version --short)
    git commit -a -m "Next prerelease number:  ${OLD_VERSION}${VERSION}"
    git push
    
  2. Begin the next prerelease phase (e.g., 0.1.0a10.1.0b0):
    OLD_VERSION=$(poetry version --short)
    poetry version prerelease --next-phase
    VERSION=$(poetry version --short)
    git commit -a -m "Next prerelease phase:  ${OLD_VERSION}${VERSION}"
    git push
    

    The phases progress as alpha (a), beta (b), and release candidate (rc), each time resetting to a prerelease number of 0. After rc, the prerelease suffix (e.g., rc3) is stripped, leaving the major.minor.patch version.

  3. Release the next minor version (e.g., 0.1.0b10.1.0):
    OLD_VERSION=$(poetry version --short)
    poetry version minor
    VERSION=$(poetry version --short)
    git commit -a -m "New minor release:  ${OLD_VERSION}${VERSION}"
    git push
    
  4. Release the next major version (e.g., 0.1.0a02.0.0):
    OLD_VERSION=$(poetry version --short)
    poetry version major
    VERSION=$(poetry version --short)
    git commit -a -m "New major release:  ${OLD_VERSION}${VERSION}"
    git push
    
  5. Tag the current version:
    VERSION=$(poetry version --short)
    git tag -a -m "rlai v${VERSION}" "v${VERSION}"
    git push --follow-tags
    
  6. Begin the next minor prerelease (e.g., 0.1.00.2.0a0):
    OLD_VERSION=$(poetry version --short)
    poetry version preminor
    VERSION=$(poetry version --short)
    git commit -a -m "Next minor prerelease:  ${OLD_VERSION}${VERSION}"
    git push
    

Troubleshooting