raspi-tools: Raspberry Pi Utility Library
raspi-tools is a Python library that simplifies working with GPS modules, GPIO pins, and other Raspberry Pi functionalities. It includes components to manage GPS data, interact with GPIO pins, and more.
Features
-
GPS Module (
GPSManager)- Fetch GPS data using
gpsd. - Save GPS data to a database (
TinyDB). - Retrieve the last known GPS location.
- Fetch GPS data using
-
GPIO Module (
BoardLED)- Control Raspberry Pi’s built-in board LED.
- Flash, turn on, or turn off the LED.
Installation
1. Prerequisites
Hardware Setup:
- A Raspberry Pi with a GPS module (e.g. Neo6 GPS) connected to the UART port.
System Dependencies:
- Install
gpsdand related tools:sudo apt update sudo apt install gpsd gpsd-clients python3-gps -y
Configure gpsd:
- Open the
gpsdconfiguration file:sudo nano /etc/default/gpsd
- Update the following fields:
DEVICES="/dev/serial0" GPSD_OPTIONS="-n"
- Restart
gpsd:sudo systemctl restart gpsd
Verify GPS Functionality:
- Test with
cgps:cgps -s - Check the
gpsdservice status:sudo systemctl status gpsd
2. Library Installation
Install from PyPI:
pip install raspi-tools
Install from Source:
- Clone the repository:
git clone <repository_url> cd raspi-tools
- Build and install:
python3 -m build pip install dist/raspi_tools-1.0.0.tar.gz
Usage
1. GPSManager
Fetch and Save GPS Data
from raspi_tools import GPSManager
# Initialize GPSManager
gps_manager = GPSManager()
# Fetch and save GPS data
gps_manager.run()
Retrieve Last Known Location
# Get the last saved GPS data
last_data = gps_manager.get_last_gps_data()
if last_data:
print(f"Latitude: {last_data.latitude}")
print(f"Longitude: {last_data.longitude}")
else:
print("No GPS data available.")
2. BoardLED
Control Raspberry Pi Board LED
from raspi_tools import BoardLED
# Initialize the LED manager
led = BoardLED()
# Turn the LED on
led.on()
# Turn the LED off
led.off()
# Flash the LED 5 times
led.flash(times=5, interval=0.2)
Advanced Configuration
GPSManager Initialization
You can specify custom paths or configurations for GPS data storage:
gps_manager = GPSManager(db_path="/custom/path/gps_data.json", gpio_pin=20, timeout=300)
BoardLED Initialization
Customize LED operations for different GPIO pins or external LEDs:
led = BoardLED(pin=21)
led.flash(times=3, interval=1.0)
FAQs
1. Why is my GPS not providing data?
- Ensure the GPS module is properly connected to the UART port.
- Verify
gpsdis running:sudo systemctl status gpsd
- Test GPS functionality with:
cgps -s
2. How do I clear GPS data from the database?
To clear all stored GPS data:
from tinydb import TinyDB
db = TinyDB('/path/to/gps_data.json')
db.truncate()
Troubleshooting
-
GPIO Errors:
- If you encounter
GPIO not allocated, ensure proper cleanup:import RPi.GPIO as GPIO GPIO.cleanup()
- If you encounter
-
GPS Fix Timeout:
- Increase the timeout when fetching GPS data:
gps_manager = GPSManager(timeout=600) gps_manager.run()
- Increase the timeout when fetching GPS data:
-
Permissions Issues:
- Ensure the script is run with appropriate permissions:
sudo python3 your_script.py
- Ensure the script is run with appropriate permissions:
Contributing
- Fork the repository.
- Create a new feature branch:
git checkout -b feature-name
- Make your changes and commit:
git commit -m "Description of changes"
- Push to the branch and open a pull request.
License
This project is licensed under the MIT License.
Metadata
Release files for raspi-tools 1.0.19
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| raspi_tools-1.0.19.tar.gz | 7.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| raspi_tools-1.0.19-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.4 kB
Release files / raspi_tools-1.0.19.tar.gz
| Download URL | raspi_tools-1.0.19.tar.gz |
|---|---|
| Size | 7.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
724b45aa1a8e548b22d5a98d8be9ab4871e6b34a905ce068b247c49da7a1ba01
|
|
BLAKE2b-256 checksum How to use checksums |
e677a4f45628831525ae2cbaa5adf9d32c28259be2cb5c60f982c63c1f05559e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.11.1 readme-renderer/40.0 requests/2.32.3 requests-toolbelt/1.0.0 urllib3/1.26.0 tqdm/4.64.1 importlib-metadata/6.8.0 keyring/24.2.0 rfc3986/1.5.0 colorama/0.4.6 CPython/3.11.10
|
Release files / raspi_tools-1.0.19-py3-none-any.whl
| Download URL | raspi_tools-1.0.19-py3-none-any.whl |
|---|---|
| Size | 7.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4e8524c44efbf2c8ca8a91412e57b3cd5749f08874f8cb13afa4504bbfe0a041
|
|
BLAKE2b-256 checksum How to use checksums |
53a053639f60012b1174a6afb1cbf6c05c2b2a03676338b7c9c71e1f5aebbe5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.11.1 readme-renderer/40.0 requests/2.32.3 requests-toolbelt/1.0.0 urllib3/1.26.0 tqdm/4.64.1 importlib-metadata/6.8.0 keyring/24.2.0 rfc3986/1.5.0 colorama/0.4.6 CPython/3.11.10
|