Skip to content

examples: Add practical examples for mcp23009e driver.#247

Merged
nedseb merged 17 commits intomainfrom
test/mcp23009e-expand-example
Mar 26, 2026
Merged

examples: Add practical examples for mcp23009e driver.#247
nedseb merged 17 commits intomainfrom
test/mcp23009e-expand-example

Conversation

@Charly-sketch
Copy link
Copy Markdown
Contributor

@Charly-sketch Charly-sketch commented Mar 25, 2026

Summary

Replace test scripts in mcp23009e/examples with practical usage examples.

Closes #186

Changes

  • Removed all test_*.py files from the examples directory (these are validation tests, not user examples)

  • Kept existing valid examples: buttons.py, i2c_scan.py

  • Added 9 new practical examples covering real use cases:

    • Games / interactive: reaction_timer.py, simon.py, combination_lock.py
    • State machines / logic: dpad_counter.py, morse_code.py, binary_counter.py
    • Hardware integration: dpad_piano.py, menu_navigation.py, sleep_on_button.py
  • Examples cover: polling and interrupt-based input, GPIO in/out, state machines, timing, buzzer audio, SSD1327 display UI, low-power wake-up

Test commands

# Prepare the updated micropython
make firmware
# Deploy it on hardware
make deploy 
# Run each example individually on hardware
make run SCRIPT=lib/mcp23009e/examples/buttons.py
make run SCRIPT=lib/mcp23009e/examples/i2c_scan.py
make run SCRIPT=lib/mcp23009e/examples/binary_counter.py
make run SCRIPT=lib/mcp23009e/examples/combination_lock.py
make run SCRIPT=lib/mcp23009e/examples/dpad_counter.py
make run SCRIPT=lib/mcp23009e/examples/dpad_piano.py
make run SCRIPT=lib/mcp23009e/examples/menu_navigation.py
make run SCRIPT=lib/mcp23009e/examples/morse_code.py
make run SCRIPT=lib/mcp23009e/examples/reaction_timer.py
make run SCRIPT=lib/mcp23009e/examples/simon.py
make run SCRIPT=lib/mcp23009e/examples/sleep_on_button.py

Checklist

  • test_*.py files removed from examples (7 files)
  • 9 new practical examples added
  • Verify that all test cases from the removed test file(s) are covered in tests/scenarios/
  • ruff check passes
  • README updated with examples table
  • Tested on hardware with mpremote
  • Commit messages follow <scope>: <Description.> format

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refreshes the mcp23009e driver’s examples by removing validation-style test_*.py scripts and adding practical, user-focused demos, with the README updated to reflect the new examples set.

Changes:

  • Removed test_*.py scripts from lib/mcp23009e/examples/ (were test/validation oriented rather than user examples).
  • Added 9 new practical examples (games, state machines, and peripheral integrations).
  • Updated lib/mcp23009e/README.md to list the new examples.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
lib/mcp23009e/examples/test_pin_irq.py Removed validation/test script from examples.
lib/mcp23009e/examples/test_pin.py Removed validation/test script from examples.
lib/mcp23009e/examples/test_output_active_low.py Removed validation/test script from examples.
lib/mcp23009e/examples/test_output.py Removed validation/test script from examples.
lib/mcp23009e/examples/test_led_simple.py Removed validation/test script from examples.
lib/mcp23009e/examples/test_interrupts.py Removed validation/test script from examples.
lib/mcp23009e/examples/test_basic.py Removed validation/test script from examples.
lib/mcp23009e/examples/sleep_on_button.py Added low-power wake-on-interrupt example.
lib/mcp23009e/examples/simon.py Added Simon Says D-PAD game example.
lib/mcp23009e/examples/reaction_timer.py Added reaction timer game using interrupts.
lib/mcp23009e/examples/morse_code.py Added dot/dash timing (press duration) Morse input example.
lib/mcp23009e/examples/menu_navigation.py Added SSD1327 OLED + D-PAD menu navigation example.
lib/mcp23009e/examples/dpad_piano.py Added buzzer “piano” example driven by D-PAD.
lib/mcp23009e/examples/dpad_counter.py Added simple D-PAD-driven counter/state machine example.
lib/mcp23009e/examples/combination_lock.py Added secret-sequence “combination lock” example.
lib/mcp23009e/examples/binary_counter.py Added GPIO-output binary counter example.
lib/mcp23009e/README.md Updated examples list to match the new practical examples.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/mcp23009e/README.md
Comment thread lib/mcp23009e/README.md Outdated
Comment thread lib/mcp23009e/examples/dpad_piano.py Outdated
Comment thread lib/mcp23009e/examples/dpad_piano.py Outdated
Comment thread lib/mcp23009e/examples/binary_counter.py Outdated
Comment thread lib/mcp23009e/examples/sleep_on_button.py
@Charly-sketch
Copy link
Copy Markdown
Contributor Author

Copy link
Copy Markdown
Contributor

@nedseb nedseb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review - PR #247

Points positifs

  • 9 nouveaux exemples pratiques et variés (simon, morse, reaction timer, piano, binary counter, etc.) — bon travail sur la diversité.
  • 7 fichiers test supprimés correctement.
  • README mis à jour avec la table des exemples et la commande mpremote corrigée.
  • sleep_on_button.py : bonne utilisation de get_intf()/get_intcap() pour la détection fiable du bouton de réveil.
  • La plupart des corrections Copilot sont appliquées.

Bilan des commentaires Copilot

# Commentaire Corrige ? Qualité réponse
1 README reference test_basic.py Oui Lien commit seul
2 README GP0-GP3 vs GPIO1-GPIO4 Oui Lien commit seul
3 Pin.OUT_PP non standard Oui Citation du fix
4 MENU docstring mensonger Non Pas de réponse
5 binary_counter naming Oui Lien commit seul
6 sleep_on_button fallback Oui Mentionne la technique

Corrections requises

1. dpad_piano.py — MENU button fantôme (bloquant)

Le docstring ligne 10 dit "MENU exits the piano mode", mais :

  • MENU_BUTTON est utilisé dans setup_buttons() sans jamais être défini. -> NameError à l'exécution
  • Aucune logique de sortie via MENU n existe (seul Ctrl+C arrête le script)

Solutions possibles :

  • Simple : supprimer la ligne "MENU exits the piano mode" du docstring et retirer la référence à MENU_BUTTON dans setup_buttons()
  • Mieux : implémenter le MENU comme vrai bouton de sortie (si le pin MENU est disponible sur la carte)

Remarque sur la qualité des réponses

Les réponses aux commentaires Copilot sont meilleures qu'avant (tu mets les liens vers les commits). L'étape suivante : ajoute une phrase expliquant ce que tu as fait et pourquoi. Exemple :

Au lieu de : docs(mcp23009e): fix examples errors.

Préfère: Fixed in d561671. Updated the README command to reference buttons.py instead of the removed test_basic.py, and aligned GPIO naming with the driver constants (GPIO1-GPIO4).

Ça permet au relecteur de comprendre ta correction sans devoir ouvrir le commit.

@nedseb nedseb force-pushed the test/mcp23009e-expand-example branch from 705f380 to ab1b2c6 Compare March 26, 2026 09:54
@Charly-sketch
Copy link
Copy Markdown
Contributor Author

1. dpad_piano.py — Bouton MENU fantôme (bloquant)

Ajout de la gestion du bouton MENU afin de permettre de quitter l’exemple dpad_piano.

Peux-tu confirmer l’implémentation actuelle des boutons (lecture directe via les pins) ?
Existe-t-il un driver ou des fonctions utilitaires prévues pour gérer ces entrées que j’aurais manqués ?

Commit associé :
fb3a70a

@nedseb nedseb merged commit 1ac4b85 into main Mar 26, 2026
3 checks passed
@nedseb nedseb deleted the test/mcp23009e-expand-example branch March 26, 2026 11:43
@semantic-release-updater
Copy link
Copy Markdown

🎉 This PR is included in version 0.1.3 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

examples: Add practical examples for mcp23009e driver.

3 participants