Skip to main content

A Python library for Raspberry Pi tools including GPS and board LED utilities.

Project description

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

  1. GPS Module (GPSManager)

    • Fetch GPS data using gpsd.
    • Save GPS data to a database (TinyDB).
    • Retrieve the last known GPS location.
  2. 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 gpsd and related tools:
    sudo apt update
    sudo apt install gpsd gpsd-clients python3-gps -y
    

Configure gpsd:

  1. Open the gpsd configuration file:
    sudo nano /etc/default/gpsd
    
  2. Update the following fields:
    DEVICES="/dev/serial0"
    GPSD_OPTIONS="-n"
    
  3. Restart gpsd:
    sudo systemctl restart gpsd
    

Verify GPS Functionality:

  1. Test with cgps:
    cgps -s
    
  2. Check the gpsd service status:
    sudo systemctl status gpsd
    

2. Library Installation

Install from PyPI:

pip install raspi-tools

Install from Source:

  1. Clone the repository:
    git clone <repository_url>
    cd raspi-tools
    
  2. 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 gpsd is 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

  1. GPIO Errors:

    • If you encounter GPIO not allocated, ensure proper cleanup:
      import RPi.GPIO as GPIO
      GPIO.cleanup()
      
  2. GPS Fix Timeout:

    • Increase the timeout when fetching GPS data:
      gps_manager = GPSManager(timeout=600)
      gps_manager.run()
      
  3. Permissions Issues:

    • Ensure the script is run with appropriate permissions:
      sudo python3 your_script.py
      

Contributing

  1. Fork the repository.
  2. Create a new feature branch:
    git checkout -b feature-name
    
  3. Make your changes and commit:
    git commit -m "Description of changes"
    
  4. Push to the branch and open a pull request.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

raspi_tools-1.0.19.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

raspi_tools-1.0.19-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file raspi_tools-1.0.19.tar.gz.

File metadata

  • Download URL: raspi_tools-1.0.19.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for raspi_tools-1.0.19.tar.gz
Algorithm Hash digest
SHA256 724b45aa1a8e548b22d5a98d8be9ab4871e6b34a905ce068b247c49da7a1ba01
MD5 8e1b37d840e0befe526f8a73a6a28e12
BLAKE2b-256 e677a4f45628831525ae2cbaa5adf9d32c28259be2cb5c60f982c63c1f05559e

See more details on using hashes here.

File details

Details for the file raspi_tools-1.0.19-py3-none-any.whl.

File metadata

  • Download URL: raspi_tools-1.0.19-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for raspi_tools-1.0.19-py3-none-any.whl
Algorithm Hash digest
SHA256 4e8524c44efbf2c8ca8a91412e57b3cd5749f08874f8cb13afa4504bbfe0a041
MD5 ffabcab6134ef0c7ade9945355dd24d5
BLAKE2b-256 53a053639f60012b1174a6afb1cbf6c05c2b2a03676338b7c9c71e1f5aebbe5f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page