projekt:python
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
| projekt:python [2026/02/08 15:36] – [6) main.py] torsten.roehl | projekt:python [2026/02/14 11:49] (aktuell) – torsten.roehl | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| - | ====== Python ====== | + | ======= Python |
| - | [[raspberry_pi: | ||
| + | [[raspberry_pi: | ||
| - | ====== | + | // |
| - | * erst reines Python | ||
| - | * dann Dauerprozess | ||
| - | * dann Web-API | ||
| - | * dann Apache davor | ||
| - | * EIN Projekt, keine Neuentwicklung | ||
| - | **ENV:** gpio_projects | ||
| - | **Projektpfad: | ||
| - | ---- | ||
| - | ===== PHASE 1 – Reines | + | {{ : |
| + | Von den vielen Möglichkeiten, | ||
| - | ---- | ||
| - | ==== 0) System vorbereiten ==== | ||
| - | <code bash> | ||
| - | sudo apt update | ||
| - | sudo apt install -y python3 python3-pip python3-venv | ||
| - | </ | ||
| - | ---- | + | ===== Überblick ===== |
| - | ==== 1) Projektordner anlegen ==== | ||
| - | <code bash> | ||
| - | mkdir -p ~/ | ||
| - | cd ~/ | ||
| - | </ | ||
| - | ---- | + | * Python „Erste Schritte“ auf der interaktiven Konsole |
| + | * [[Python „Python-Umgebung (env) einrichten“ – Vorbereitungen für Projekte schaffen]] | ||
| + | * [[Python „Erste Skripte“]] | ||
| + | * [[Python „Projekt GPIO“]] | ||
| - | ==== 2) Virtuelle Umgebung anlegen (NAME: gpio_projects) ==== | ||
| - | <code bash> | + | ===== Anhang ===== |
| - | python3 -m venv gpio_projects | + | |
| - | source gpio_projects/ | + | |
| - | pip install RPi.GPIO | ||
| - | </ | ||
| - | ---- | ||
| - | ==== 3) Projektstruktur Phase 1 ==== | ||
| - | <code> | + | < |
| - | gpio_projects/ | + | |
| - | | + | |
| - | | + | |
| - | | + | |
| - | | + | |
| - | </code> | + | |
| - | ---- | + | # [python env] |
| - | ==== 4) gpio_hw.py ==== | + | ## env anlegen |
| + | cd ~/ | ||
| + | python3 -m venv gpio_env | ||
| - | <code python> | + | ## aktivieren |
| - | import RPi.GPIO as GPIO | + | source ~/ |
| - | PIN = 17 | + | ## deaktivieren |
| + | deactivate | ||
| - | GPIO.setmode(GPIO.BCM) | + | ## löschen |
| - | GPIO.setup(PIN, | + | cd ~/ |
| + | rm -rf gpio_env | ||
| - | def on(): | ||
| - | GPIO.output(PIN, | ||
| - | def off(): | ||
| - | GPIO.output(PIN, | ||
| - | |||
| - | def status(): | ||
| - | return GPIO.input(PIN) | ||
| - | |||
| - | def cleanup(): | ||
| - | GPIO.cleanup() | ||
| </ | </ | ||
| - | ---- | ||
| - | |||
| - | ==== 5) logic.py ==== | ||
| - | |||
| - | <code python> | ||
| - | import gpio_hw | ||
| - | |||
| - | def turn_on(): | ||
| - | gpio_hw.on() | ||
| - | return " | ||
| - | |||
| - | def turn_off(): | ||
| - | gpio_hw.off() | ||
| - | return " | ||
| - | |||
| - | def get_status(): | ||
| - | return " | ||
| - | </ | ||
| - | |||
| - | ---- | ||
| - | |||
| - | ==== 6) main.py ==== | ||
| - | |||
| - | <code python | main.py> | ||
| - | import logic | ||
| - | import gpio_hw | ||
| - | |||
| - | print(" | ||
| - | |||
| - | try: | ||
| - | while True: | ||
| - | cmd = input(" | ||
| - | if cmd == " | ||
| - | print(logic.turn_on()) | ||
| - | elif cmd == " | ||
| - | print(logic.turn_off()) | ||
| - | elif cmd == " | ||
| - | print(logic.get_status()) | ||
| - | except KeyboardInterrupt: | ||
| - | pass | ||
| - | finally: | ||
| - | gpio_hw.cleanup() | ||
| - | </ | ||
| - | |||
| - | ---- | ||
| - | |||
| - | ==== 7) Start Phase 1 ==== | ||
| - | |||
| - | <code bash> | ||
| - | cd ~/ | ||
| - | source gpio_projects/ | ||
| - | python3 main.py | ||
| - | </ | ||
| - | |||
| - | ---- | ||
| - | |||
| - | ===== PHASE 3 – Web später ===== | ||
| - | |||
| - | <code bash> | ||
| - | pip install fastapi uvicorn | ||
| - | </ | ||
| - | |||
| - | ---- | ||
| - | |||
| - | ===== systemd später mit dieser ENV ===== | ||
| - | |||
| - | < | ||
| - | ExecStart=/ | ||
| - | </ | ||
| - | |||
| - | ---- | ||
| - | |||
| - | ===== Ergebnis ===== | ||
| - | |||
| - | * ENV = gpio_projects | ||
| - | * Projekt = ~/ | ||
| - | * kein raspi_gpio_env mehr | ||
| - | * konsistent für alle Phasen | ||
projekt/python.1770565000.txt.gz · Zuletzt geändert: von torsten.roehl
