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 17:24] – torsten.roehl | projekt:python [2026/02/26 09:39] (aktuell) – [Python] torsten.roehl | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| - | ====== Python ====== | + | ======= Python |
| + | [[raspberry_pi: | ||
| - | [[raspberry_pi: | + | // |
| - | + | ||
| - | // | + | |
| {{ : | {{ : | ||
| - | Von den vielen Möglichkeiten, | + | Von den vielen Möglichkeiten, |
| - | ===== Überblick ===== | ||
| + | < | ||
| + | * Hilfe/ | ||
| + | * Offizielle Dokumentation: | ||
| + | * Online Python: https:// | ||
| + | </ | ||
| - | * [[Python „Erste Schritte“ auf der interaktiven Konsole]] | ||
| - | * Python „Python-Umgebung (env) einrichten“ – Vorbereitungen für Projekte schaffen | ||
| - | * Python „Erste Skripte“ | ||
| - | * Python „Projekt GPIO“ | ||
| + | ===== Überblick ===== | ||
| - | ====== Raspberry-Pi-Kursprojekt: GPIO-App mit wachsender Architektur ====== | + | |{{ :raspberry_pi:projects_overview.png? |
| - | + | | Kursüberblick zu den Python-Projekten | |
| - | * erst reines Python | + | |
| - | * dann Dauerprozess | + | |
| - | * dann Web-API | + | |
| - | * dann Apache davor | + | |
| - | * EIN Projekt, keine Neuentwicklung | + | |
| - | + | ||
| - | **ENV:** gpio_projects | + | |
| - | **Projektpfad: | + | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | ===== PHASE 1 – Reines | + | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | ==== 0) System vorbereiten ==== | + | |
| - | + | ||
| - | <code bash> | + | |
| - | sudo apt update | + | |
| - | sudo apt install | + | |
| - | </ | + | |
| - | + | ||
| - | ---- | + | |
| - | + | ||
| - | ==== 1) Projektordner anlegen ==== | + | |
| - | + | ||
| - | <code bash> | + | |
| - | mkdir -p ~/ | + | |
| - | cd ~/ | + | |
| - | </ | + | |
| - | + | ||
| - | ---- | + | |
| - | + | ||
| - | ==== 2) Virtuelle Umgebung anlegen (NAME: gpio_projects) ==== | + | |
| - | + | ||
| - | <code bash> | + | |
| - | python3 -m venv gpio_projects | + | |
| - | source gpio_projects/ | + | |
| - | + | ||
| - | pip install RPi.GPIO | + | |
| - | </ | + | |
| - | + | ||
| - | ---- | + | |
| - | + | ||
| - | ==== 3) Projektstruktur Phase 1 ==== | + | |
| - | + | ||
| - | < | + | |
| - | gpio_projects/ | + | |
| - | | + | |
| - | | + | |
| - | | + | |
| - | | + | |
| - | + | ||
| - | (gpio_env) pi@raspi88: | + | |
| - | . | + | |
| - | ├── gpio_env | + | |
| - | ├── gpio_hw.py | + | |
| - | ├── logic.py | + | |
| - | └── main.py | + | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | </ | + | |
| - | + | ||
| - | ---- | + | |
| - | + | ||
| - | ==== 4) gpio_hw.py ==== | + | |
| - | + | ||
| - | <code python | + | |
| - | import RPi.GPIO as GPIO | + | |
| - | + | ||
| - | PIN = 17 | + | |
| - | + | ||
| - | GPIO.setmode(GPIO.BCM) | + | |
| - | GPIO.setup(PIN, | + | |
| - | + | ||
| - | 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 logic.py> | + | |
| - | 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 | + | |
| - | 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 | + | |
| - | + | ||
| - | + | ||
| - | ===== Anhang ===== | + | |
| - | + | ||
| - | < | + | |
| - | # [python env] | + | |
| - | + | ||
| - | ## env anlegen | + | |
| - | cd ~/ | + | |
| - | python3 -m venv gpio_env | + | |
| - | + | ||
| - | ## aktivieren | + | |
| - | source ~/ | + | |
| - | ## deaktivieren | + | ^ Nr ^ Projekt ^ Projektordner ^ Hauptprogramm ^ |
| - | deactivate | + | |**1**| Python „Erste Schritte“ in der interaktiven Konsole – // |
| + | || | ||
| + | |**2.1**|[[Python "Erste Skripte" | ||
| + | |**2.2**|↳ Erweiterung | **course_reflex_advanced** | '' | ||
| + | || | ||
| + | |**3**|[[Python " | ||
| + | || | ||
| + | |**4.1**|[[Python " | ||
| + | |**4.2**|↳ Erweiterung | **course_led_advanced** | '' | ||
| + | || | ||
| + | |**5**|[[Python " | ||
| + | |**6**|[[python_ds18b20_logger|Python " | ||
| + | || | ||
| + | |**7**|[[Projekt: | ||
| - | ## löschen | ||
| - | cd ~/ | ||
| - | rm -rf gpio_env | ||
| - | </ | ||
projekt/python.1770571486.txt.gz · Zuletzt geändert: von torsten.roehl
