issue201:micro-ci
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
issue201:micro-ci [2024/01/28 07:53] – d52fr | issue201:micro-ci [2024/01/29 15:02] (Version actuelle) – auntiee | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
**Rotary Encoders | **Rotary Encoders | ||
- | What looks like a potentiometer, | + | What looks like a potentiometer, |
- | Think of a rotary switch with an unlimited number of switch positions. | + | Think of a rotary switch with an unlimited number of switch positions. It really isn’t, but it sort of acts like that. |
- | While there are many different models of rotary encoders, the particular encoder we will be using in this project is a KY-040. | + | While there are many different models of rotary encoders, the particular encoder we will be using in this project is a KY-040. You can get them from many places on the Internet starting for about $3.00 USD. Some come in packs of 5 for $10.00. I borrowed this image from https:// |
- | There is a pretty good PDF on how the KY-040 works at https:// | + | There is a pretty good PDF on how the KY-040 works at https:// |
- | The actual encoder has three pins, but the breakout board has 5. | + | The actual encoder has three pins, but the breakout board has 5. One extra feature of the KY-040 is that the shaft can be pressed to provide a momentary Normally Open switch.** |
- | **The drivers that we’ll need for this project can be found at https:// | + | Encodeurs rotatifs |
- | For now, let’s start wiring the breadboard. | + | Qu' |
- | Now for the code. You need to copy from the rotary encoder driver zip the rotary.py and rotary_irq_rp2.py files to your RPi Pico. Then you need to copy the example_simple.py file from the Examples folder and save it as example_simple_rotary.py onto your Pico as well. This is the file we need to modify (top right). | + | Imaginez un commutateur rotatif avec un nombre illimité de positions. Ce n'est pas vraiment le cas, mais c'est un peu comme ça qu'il se comporte. |
+ | |||
+ | Bien qu'il existe de nombreux modèles différents d' | ||
+ | https:// | ||
+ | |||
+ | Un bon PDF sur le fonctionnement du KY-040 est disponible à l' | ||
+ | |||
+ | L' | ||
+ | |||
+ | |||
+ | **The drivers that we’ll need for this project can be found at https:// | ||
+ | |||
+ | For now, let’s start wiring the breadboard. | ||
+ | |||
+ | Now for the code. You need to copy from the rotary encoder driver zip the rotary.py and rotary_irq_rp2.py files to your RPi Pico. Then you need to copy the example_simple.py file from the Examples folder and save it as example_simple_rotary.py onto your Pico as well. This is the file we need to modify (top right). | ||
Now we need to add the driver for the SSD1306 (below). | Now we need to add the driver for the SSD1306 (below). | ||
- | Now we need to define all the pins for the rotary encoder. | + | Now we need to define all the pins for the rotary encoder. Note that these are the GPIO pins, not the physical pins. I’ve included the GPIO pin numbers to the Physical pin numbers in the table above.** |
- | The first line sets the switch for the shaft push momentary switch. The next lines handle the IRQ set ups. We use max_val to define the max number of positions. By setting reverse=True means that turning the shaft clockwise the counter increments and anti-clockwise decrements the counter. | + | Les pilotes dont nous aurons besoin pour ce projet se trouvent à l' |
- | **We keep two values to determine the current value of the encoder. | + | Pour l' |
+ | |||
+ | Passons maintenant au code. Vous devez copier les fichiers rotary.py et rotary_irq_rp2.py dans votre RPi Pico à partir du fichier zip du pilote de l' | ||
+ | |||
+ | Nous devons maintenant ajouter le pilote pour le SSD1306 (ci-dessous). | ||
+ | |||
+ | Puis nous devons définir toutes les broches de l' | ||
+ | |||
+ | |||
+ | **The first line sets the switch for the shaft push momentary switch. The next lines handle the IRQ set ups. We use max_val to define the max number of positions. By setting reverse=True means that turning the shaft clockwise the counter increments and anti-clockwise decrements the counter. Finally range_mode=RANGE_WRAP causes the counter to go from max_val to min_val (bottom right). | ||
+ | |||
+ | We keep two values to determine the current value of the encoder. Val_old is set to make sure that we don’t report the same value each time the loop is run. We’ve used the SSD1306 fill, text and show methods before, so I won’t go into depth on those (next page, top right). | ||
If you want to use the shaft switch to exit the loop, change the while loop from | If you want to use the shaft switch to exit the loop, change the while loop from | ||
+ | |||
+ | while True:** | ||
+ | |||
+ | La première ligne définit le commutateur pour l' | ||
+ | |||
+ | Nous conservons deux valeurs pour déterminer la valeur actuelle du codeur. Val_old est définie pour s' | ||
+ | |||
+ | Si vous voulez utiliser le commutateur de l'axe pour sortir de la boucle, changez la boucle while de | ||
while True: | while True: | ||
- | To | ||
+ | **To | ||
doloop = True | doloop = True | ||
Ligne 38: | Ligne 71: | ||
And then in the if button.value check, add the line | And then in the if button.value check, add the line | ||
- | doloop = False** | + | doloop = False |
- | **When you run the program each time you turn the shaft of the encoder the value printout on the OLED should change (and the REPL should show the value). | + | When you run the program each time you turn the shaft of the encoder the value printout on the OLED should change (and the REPL should show the value). |
Ligne 48: | Ligne 81: | ||
Until next time, HAPPY NEW YEAR and, as always; stay safe, healthy, positive and creative!** | Until next time, HAPPY NEW YEAR and, as always; stay safe, healthy, positive and creative!** | ||
+ | |||
+ | en | ||
+ | |||
+ | doloop = True | ||
+ | |||
+ | while doloop: | ||
+ | |||
+ | Et ensuite, dans la vérification if button.value, | ||
+ | |||
+ | doloop = False | ||
+ | |||
+ | Lorsque vous exécutez le programme, chaque fois que vous tournez l' | ||
+ | |||
+ | J'ai mis en place un dépôt pour le projet à https:// | ||
+ | |||
+ | C'est tout pour ce mois-ci. | ||
+ | |||
+ | Jusqu' | ||
+ |
issue201/micro-ci.1706424804.txt.gz · Dernière modification : 2024/01/28 07:53 de d52fr