|
| 1 | +# Raspberry Pi 5 GPIO Setup for Desk Lifter Control |
| 2 | + |
| 3 | +This document describes the setup required to run the desk lifter control scripts on a Raspberry Pi 5 running Debian Trixie. |
| 4 | + |
| 5 | +## Hardware Requirements |
| 6 | + |
| 7 | +- Raspberry Pi 5 (with BCM2712 SoC) |
| 8 | +- GPIO pins connected to the desk lifter motor controller: |
| 9 | + - UP_PIN: GPIO 18 (physical pin 12) |
| 10 | + - DOWN_PIN: GPIO 17 (physical pin 11) |
| 11 | +- Power supply: 5V USB-C (at least 3A, preferably 5A for high-power peripherals) |
| 12 | + |
| 13 | +## Software Requirements |
| 14 | + |
| 15 | +- Debian Trixie (13.x) |
| 16 | +- Python 3.11 or later |
| 17 | +- Virtual environment (`venv`) |
| 18 | + |
| 19 | +## GPIO Library Compatibility |
| 20 | + |
| 21 | +The standard `RPi.GPIO` library does not support Raspberry Pi 5 due to changes in the BCM2712 SoC. Instead, use `rpi-lgpio`, a drop-in replacement that provides the same API but uses the `lgpio` library for GPIO access. |
| 22 | + |
| 23 | +## Installation Steps |
| 24 | + |
| 25 | +1. **Clone the repository** (if not already done): |
| 26 | + ```bash |
| 27 | + git clone https://github.com/AccelerationConsortium/progressive-automations-python.git |
| 28 | + cd progressive-automations-python |
| 29 | + ``` |
| 30 | + |
| 31 | +2. **Create and activate a virtual environment**: |
| 32 | + ```bash |
| 33 | + python3 -m venv venv |
| 34 | + source venv/bin/activate |
| 35 | + ``` |
| 36 | + |
| 37 | +3. **Install dependencies**: |
| 38 | + ```bash |
| 39 | + pip install -r requirements.txt |
| 40 | + ``` |
| 41 | + |
| 42 | +4. **Remove incompatible RPi.GPIO package** (if installed): |
| 43 | + ```bash |
| 44 | + sudo apt remove -y python3-rpi.gpio |
| 45 | + ``` |
| 46 | + |
| 47 | +5. **Ensure user is in the gpio group** (for GPIO access without sudo): |
| 48 | + ```bash |
| 49 | + sudo usermod -a -G gpio $USER |
| 50 | + ``` |
| 51 | + Reboot after adding the user to the group. |
| 52 | + |
| 53 | +## Running the Scripts |
| 54 | + |
| 55 | +Activate the virtual environment and run the scripts from the `scripts/` directory: |
| 56 | + |
| 57 | +```bash |
| 58 | +source venv/bin/activate |
| 59 | +cd scripts |
| 60 | +python move_to_height_no_reset.py |
| 61 | +``` |
| 62 | + |
| 63 | +Available scripts: |
| 64 | +- `move_to_height_no_reset.py`: Move the desk to a target height |
| 65 | +- `move_to_height.py`: Alternative height control script |
| 66 | +- `desk_control_prefect.py`: Prefect-based workflow orchestration |
| 67 | +- `test_up.py`: Test upward movement |
| 68 | +- `test_down.py`: Test downward movement |
| 69 | +- `reset_to_lowest.py`: Reset to lowest position |
| 70 | + |
| 71 | +## Calibration |
| 72 | + |
| 73 | +The scripts use calibration data: |
| 74 | +- Lowest height: 23.7 inches |
| 75 | +- Highest height: 54.5 inches |
| 76 | +- Up rate: 0.54 inches/second |
| 77 | +- Down rate: 0.55 inches/second |
| 78 | + |
| 79 | +Adjust these values in the script if your setup differs. |
| 80 | + |
| 81 | +State is saved in `lifter_state.json` in the scripts directory. |
| 82 | + |
| 83 | +## Troubleshooting |
| 84 | + |
| 85 | +### RuntimeError: Cannot determine SOC peripheral base address |
| 86 | + |
| 87 | +This error occurs when using the old `RPi.GPIO` library on Raspberry Pi 5. Ensure you have installed `rpi-lgpio` and removed `python3-rpi.gpio`. |
| 88 | + |
| 89 | +### Permission denied on GPIO access |
| 90 | + |
| 91 | +- Ensure your user is in the `gpio` group: `groups $USER` should include `gpio`. |
| 92 | +- If not, run `sudo usermod -a -G gpio $USER` and reboot. |
| 93 | + |
| 94 | +### Script runs but motor doesn't move |
| 95 | + |
| 96 | +- Check GPIO pin connections. |
| 97 | +- Verify the motor controller is powered and connected correctly. |
| 98 | +- Test with `test_up.py` and `test_down.py` to isolate issues. |
| 99 | + |
| 100 | +### Virtual environment issues |
| 101 | + |
| 102 | +- Always activate the venv before running scripts: `source venv/bin/activate` |
| 103 | +- If pip installs fail with "externally-managed-environment", you're trying to install system-wide. Use the venv. |
| 104 | + |
| 105 | +## Notes |
| 106 | + |
| 107 | +- The scripts use BCM pin numbering. |
| 108 | +- GPIO access requires root permissions or membership in the `gpio` group. |
| 109 | +- On Raspberry Pi 5, USB peripherals may be limited to 600mA if using a 3A power supply. Use a 5A supply for high-power devices. |
| 110 | +- This setup is tested on Debian Trixie with Raspberry Pi 5. |
0 commit comments