Our Python libraries are designed to work seamlessly with our development boards available from AB Electronics UK, providing a robust and efficient way to interface with your Raspberry Pi. These libraries offer a comprehensive suite of functions, making it easier than ever to develop and prototype your projects.
Our Python library is available on our Python Library GitHub Repository
Setting Up Your Environment:
Connect your Raspberry Pi to a monitor, keyboard, and mouse. Power it up and ensure it's running the latest version of Raspberry Pi OS.
Ensure Python is installed on your Raspberry Pi. Python normally comes pre-installed on Raspberry Pi OS. You can check by typing python --version or python3 --version in the terminal. Current versions of Raspberry Pi OS will only have Python 3 installed, and it is recommended to use Python 3 with any new projects.
If your computer does not have Python 3 installed, you can use the following commands in a terminal to install it.
sudo apt update sudo apt install python3
Most of our development boards use the I2C bus on the Raspberry Pi, some use the SPI bus. You will need to enable these data buses before you can use the Python library. Check the documentation for your development board to find out which data bus is needed.
For I2C-based development boards please follow our tutorial I2C Part 2 - Enabling I2C on the Raspberry Pi to enable the I2C bus.
For SPI-based development boards please use the tutorial SPI and Python on Raspberry Pi OS.
Downloading the Library
To install the AB Electronics UK Python library on your Raspberry Pi, start by updating your system and installing the necessary Python build and installer packages by running the following commands in a terminal.
sudo apt sudo apt install python3-build python3-installer git
Next, download the AB Electronics UK Python Libraries to your computer by running:
git clone https://github.com/abelectronicsuk/ABElectronics_Python_Libraries.git
There are two common methods for using Python library modules. You can install them on your computer so they can be referenced from any Python program, or you can copy the module into your project directory and reference it directly.
Installing the Python library
After downloading, navigate to the ABElectronics_Python_Libraries folder and run the following commands in a terminal to build the library, and install it.
python3 -m build sudo python3 -m installer dist/*.whl
This will install the library in the system Python library directory where it can be referenced from Python programs.
Using classes without installing the library
To use a specific part of our Python library in your project without installing the entire library, you can simply copy the needed class file into your project's directory. For example, to use the IO Pi Plus, copy the IOPi.py file from the IOPi directory to where your project files are located. After doing this, you can use the class in your program by adding an import statement at the beginning of your Python code. This allows you to directly utilize the class's functionality in your project.
from IOPi import IOPi
Exploring the Library
The folder for the AB Electronics UK Python Library has a structured directory, each corresponding to a specific development board.
The main directories include ADCDACPi, ADCPi, ADCDifferentialPi, ExpanderPi, I2CSwitch, IOPi, IOZero32, RTCPi, and ServoPi.
Each of these contains the Python module and a demo directory containing demonstration files relevant to the respective board.
Additionally, each directory has a README.md file that contains the documentation for the Python module including a list of available classes and functions.
Running Your First Script
To run a Python script using Python 3, open your command terminal and navigate to the directory where your script is located. Once there, you can run your script by typing python3 scriptname.py into the CLI, replacing scriptname.py with the actual name of your script.
For example, to run the demo_ioread.py demonstration script for the IO Pi Plus navigate to the ABElectronics_Python_Libraries/IOPi/demos/ directory and run the following command.
python3 demo_ioread.py
To exit the Python script use CTRL-C on your keyboard.
If you require support or have any questions regarding our Python libraries and demo code, please do not hesitate to contact us. We have a support forum where you can post your questions and engage with other users. Additionally, you can use the contact form on our website to reach out directly. Our support team is dedicated to helping you get the most out of your Raspberry Pi development boards. We welcome your feedback and are committed to continually enhancing our products and services to better meet your needs.