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.8.tar.gz (5.5 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.8-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: raspi_tools-1.0.8.tar.gz
  • Upload date:
  • Size: 5.5 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.8.tar.gz
Algorithm Hash digest
SHA256 dc156ce0f187cfdbf234797057eeee727e2da7dad64af3ec38f8be4b10d1c7be
MD5 c9c5825682bfd06835bcac528014a810
BLAKE2b-256 7631abdf3c273f44f4b23bfc2b34a102b1e3bdbd7c3895f43d2d7ae0e651f0f7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: raspi_tools-1.0.8-py3-none-any.whl
  • Upload date:
  • Size: 6.0 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.8-py3-none-any.whl
Algorithm Hash digest
SHA256 95491ab45ffc1b0d8216c400fd88529caff1882b0394ac8e9e7e9000c0f721b5
MD5 58f5cc72ae38a20dc184114310c6a8cb
BLAKE2b-256 f7736b07a93ddff583be366078f7ef10ca584538d6d7538e9b026099750f5811

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