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:37] – [5) logic.py] torsten.roehl | projekt:python [2026/02/26 09:39] (aktuell) – [Python] torsten.roehl | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| - | ====== Python ====== | + | ======= Python |
| - | [[raspberry_pi: | + | [[raspberry_pi: |
| + | // | ||
| - | ====== Raspberry-Pi-Kursprojekt: | ||
| - | * erst reines Python | ||
| - | * dann Dauerprozess | ||
| - | * dann Web-API | ||
| - | * dann Apache davor | ||
| - | * EIN Projekt, keine Neuentwicklung | ||
| - | **ENV:** gpio_projects | + | {{ : |
| - | **Projektpfad: | + | Von den vielen Möglichkeiten, |
| - | ---- | ||
| - | ===== PHASE 1 – Reines Python + GPIO ===== | ||
| - | ---- | ||
| - | ==== 0) System vorbereiten ==== | ||
| - | <code bash> | + | <note>**ONLINE |
| - | sudo apt update | + | * Hilfe/ |
| - | sudo apt install -y python3 python3-pip python3-venv | + | * Offizielle Dokumentation: |
| - | </code> | + | |
| - | ---- | + | * Online Python: https:// |
| + | </ | ||
| - | ==== 1) Projektordner anlegen ==== | ||
| - | <code bash> | + | ===== Überblick ===== |
| - | mkdir -p ~/ | + | |
| - | cd ~/ | + | |
| - | </ | + | |
| - | ---- | + | |{{ : |
| + | | Kursüberblick zu den Python-Projekten | | ||
| - | ==== 2) Virtuelle | + | ^ Nr ^ Projekt ^ Projektordner ^ Hauptprogramm ^ |
| + | |**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: | ||
| - | <code bash> | ||
| - | python3 -m venv gpio_projects | ||
| - | source gpio_projects/ | ||
| - | |||
| - | pip install RPi.GPIO | ||
| - | </ | ||
| - | |||
| - | ---- | ||
| - | |||
| - | ==== 3) Projektstruktur Phase 1 ==== | ||
| - | |||
| - | < | ||
| - | gpio_projects/ | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | </ | ||
| - | |||
| - | ---- | ||
| - | |||
| - | ==== 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 | ||
projekt/python.1770565025.txt.gz · Zuletzt geändert: von torsten.roehl
