issue173:micro-ci_micro-la
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue173:micro-ci_micro-la [2021/09/26 11:08] – créée auntiee | issue173:micro-ci_micro-la [2021/10/03 17:19] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | This month, we will continue playing with the SSD1302 OLED display. We’ve seen how to simply display text using the default font and how to use other fonts through the micropython-font-to-py library package. | + | **This month, we will continue playing with the SSD1302 OLED display. We’ve seen how to simply display text using the default font and how to use other fonts through the micropython-font-to-py library package. |
Let’s jump right in to some new things that we can do. | Let’s jump right in to some new things that we can do. | ||
Ligne 9: | Ligne 9: | ||
In order to do simple graphics like lines, circles and so on, you need to download a graphics driver for the SSD1302. You can get it at https:// | In order to do simple graphics like lines, circles and so on, you need to download a graphics driver for the SSD1302. You can get it at https:// | ||
- | I was able to gain a tremendous amount of information on using the SSD1302 from the web. One of the most useful websites was the Random Nerds Tutorials site. Their page for this section is https:// | + | I was able to gain a tremendous amount of information on using the SSD1302 from the web. One of the most useful websites was the Random Nerds Tutorials site. Their page for this section is https:// |
- | We’ll start (right) with the normal import and I2C setup code… This is for the ESP32/ | + | Ce mois-ci, nous allons continuer à jouer avec l' |
+ | |||
+ | Passons directement à de nouvelles choses que nous pouvons faire. | ||
+ | |||
+ | Graphiques simples | ||
+ | |||
+ | REMARQUE : Le code présenté ici a été développé avec l' | ||
+ | |||
+ | Afin de réaliser des graphiques simples comme des lignes, des cercles, etc., vous devez télécharger un pilote graphique pour le SSD1302. Vous pouvez l' | ||
+ | |||
+ | J'ai pu obtenir une grande quantité d' | ||
+ | |||
+ | |||
+ | **We’ll start (right) with the normal import and I2C setup code… This is for the ESP32/ | ||
Now the necessary preliminaries are out of the way, we can concentrate on how to draw our graphics. | Now the necessary preliminaries are out of the way, we can concentrate on how to draw our graphics. | ||
Ligne 22: | Ligne 35: | ||
So we would code it as follows… | So we would code it as follows… | ||
+ | |||
+ | graphics.line(0, | ||
+ | |||
+ | oled.show()** | ||
+ | |||
+ | Nous allons commencer (à droite) par le code normal d' | ||
+ | |||
+ | Maintenant que les préliminaires nécessaires sont terminés, nous pouvons nous concentrer sur la façon de dessiner nos graphiques. | ||
+ | |||
+ | Ligne simple | ||
+ | |||
+ | Nous allons commencer par dessiner une ligne de la position 0,0 à la position 128, sur la ligne inférieure de l' | ||
+ | |||
+ | line(x0, y0, x1, y1, color) | ||
+ | |||
+ | Nous le coderons donc comme suit : | ||
graphics.line(0, | graphics.line(0, | ||
Ligne 27: | Ligne 56: | ||
oled.show() | oled.show() | ||
- | By using oled_height as our y1 parameter, we can ensure that this will work for both 128x64 and 128x32 displays. Now, sleep for 2 seconds, then clear the display and we will move on to the next demo. | + | |
+ | **By using oled_height as our y1 parameter, we can ensure that this will work for both 128x64 and 128x32 displays. Now, sleep for 2 seconds, then clear the display and we will move on to the next demo. | ||
sleep(2) | sleep(2) | ||
Ligne 44: | Ligne 74: | ||
oled.show() | oled.show() | ||
+ | |||
+ | sleep(2) | ||
+ | |||
+ | oled.fill(0)** | ||
+ | |||
+ | En utilisant oled_height comme paramètre y1, nous pouvons nous assurer que cela fonctionnera pour les écrans 128x64 et 128x32. Maintenant, sleep pendant 2 secondes, puis effacez l' | ||
sleep(2) | sleep(2) | ||
Ligne 49: | Ligne 85: | ||
oled.fill(0) | oled.fill(0) | ||
- | Filled Rectangle | + | Rectangle |
+ | |||
+ | Ensuite, nous allons dessiner un rectangle. Les paramètres de la fonction rectangle sont : | ||
+ | |||
+ | rect(x0, y0, largeur, hauteur, couleur) | ||
+ | |||
+ | Nous allons dessiner un rectangle de 0,0 à 50,20. De cette façon, il fonctionnera sur l'un ou l' | ||
+ | |||
+ | graphics.rect(0, | ||
+ | |||
+ | oled.show() | ||
+ | |||
+ | sleep(2) | ||
+ | |||
+ | oled.fill(0) | ||
+ | |||
+ | |||
+ | **Filled Rectangle | ||
To create a filled rectangle we’ll use a very similar function fill_rect with the same parameters as before. | To create a filled rectangle we’ll use a very similar function fill_rect with the same parameters as before. | ||
+ | |||
+ | graphics.fill_rect(0, | ||
+ | |||
+ | oled.show() | ||
+ | |||
+ | sleep(2) | ||
+ | |||
+ | oled.fill(0)** | ||
+ | |||
+ | Rectangle rempli | ||
+ | |||
+ | Pour créer un rectangle rempli, nous allons utiliser une fonction très similaire, fill_rect, avec les mêmes paramètres que précédemment. | ||
graphics.fill_rect(0, | graphics.fill_rect(0, | ||
Ligne 61: | Ligne 126: | ||
oled.fill(0) | oled.fill(0) | ||
- | Circles | + | |
+ | **Circles | ||
Circles are just as easy as rectangles. The functions are circle and fill_circle. They both use the same parameter list. | Circles are just as easy as rectangles. The functions are circle and fill_circle. They both use the same parameter list. | ||
Ligne 84: | Ligne 150: | ||
graphics.fill_circle(64, | graphics.fill_circle(64, | ||
+ | |||
+ | oled.show() | ||
+ | |||
+ | sleep(2) | ||
+ | |||
+ | oled.fill(0)** | ||
+ | |||
+ | Cercles | ||
+ | |||
+ | Les cercles sont tout aussi simples que les rectangles. Les fonctions sont circle et fill_circle. Elles utilisent toutes deux la même liste de paramètres. | ||
+ | |||
+ | circle(x0, y0, rayon, couleur) | ||
+ | |||
+ | fill_circle(x0, | ||
+ | |||
+ | Encore une fois, nous utiliserons des paramètres qui fonctionneront sur l'un ou l' | ||
+ | |||
+ | # Cercle (x0, y0, rayon, couleur) | ||
+ | |||
+ | graphics.circle(64, | ||
oled.show() | oled.show() | ||
Ligne 91: | Ligne 177: | ||
oled.fill(0) | oled.fill(0) | ||
- | Triangles | + | # Cercle rempli |
+ | |||
+ | graphics.fill_circle(64, | ||
+ | |||
+ | oled.show() | ||
+ | |||
+ | sleep(2) | ||
+ | |||
+ | oled.fill(0) | ||
+ | |||
+ | |||
+ | **Triangles | ||
The triangle functions are similar to the rect and circle functions, but have a third set of coordinates. | The triangle functions are similar to the rect and circle functions, but have a third set of coordinates. | ||
Ligne 120: | Ligne 217: | ||
oled.fill(0) | oled.fill(0) | ||
+ | |||
+ | oled.show()** | ||
+ | |||
+ | Triangles | ||
+ | |||
+ | Les fonctions triangle sont similaires aux fonctions rect et circle, mais possèdent un troisième ensemble de coordonnées. | ||
+ | |||
+ | triangle(x0, | ||
+ | |||
+ | fill_triangle(x0, | ||
+ | |||
+ | Comme pour les dernières fonctions, nous utiliserons des coordonnées qui s' | ||
+ | |||
+ | graphics.triangle(0, | ||
oled.show() | oled.show() | ||
- | Easy enough, right? | + | sleep(2) |
+ | |||
+ | oled.fill(0) | ||
+ | |||
+ | oled.show() | ||
+ | |||
+ | # Triangle rempli | ||
+ | |||
+ | graphics.fill_triangle(0, | ||
+ | |||
+ | oled.show() | ||
+ | |||
+ | sleep(2) | ||
+ | |||
+ | oled.fill(0) | ||
+ | |||
+ | oled.show() | ||
+ | |||
+ | |||
+ | **Easy enough, right? | ||
The file on the repository for this section is called rnerd_ssd1306_esp32_graphics1.py for the ESP32/ | The file on the repository for this section is called rnerd_ssd1306_esp32_graphics1.py for the ESP32/ | ||
Ligne 131: | Ligne 261: | ||
Sometimes, you want to make something nicer than a static display where the text simply overwrites itself. Having the text scroll in from the side or top and pause a few seconds, then scroll off the screen, gives your project a certain “WOW” factor. These days, we need a “WOW” factor to make our projects stand out. | Sometimes, you want to make something nicer than a static display where the text simply overwrites itself. Having the text scroll in from the side or top and pause a few seconds, then scroll off the screen, gives your project a certain “WOW” factor. These days, we need a “WOW” factor to make our projects stand out. | ||
- | I originally tested this code on the ESP32, but I was able to get it to run on the RPi Pico. The only thing you have to make sure of is the I2C setup. Between the information from last month and the information in the code above, you should have no problems getting things to work. Just in case you have forgotten, I got this demo from Random Nerds Tutorials web site. You can find the link in the text above. | + | I originally tested this code on the ESP32, but I was able to get it to run on the RPi Pico. The only thing you have to make sure of is the I2C setup. Between the information from last month and the information in the code above, you should have no problems getting things to work. Just in case you have forgotten, I got this demo from Random Nerds Tutorials web site. You can find the link in the text above.** |
+ | |||
+ | C'est assez facile, non ? | ||
+ | |||
+ | Sur le dépôt, le fichier pour cette section s' | ||
+ | |||
+ | Défilement de l' | ||
+ | |||
+ | Parfois, vous voulez faire quelque chose de plus agréable qu'un affichage statique où le texte est écrasé au fur et à mesure. Le défilement du texte depuis le côté ou le haut, suivi d'une pause de quelques secondes, puis une évacuation hors de l' | ||
+ | |||
+ | À l' | ||
- | Getting Started | + | **Getting Started |
As I do most of the time, we’ll start (top right) with the import section and, in this case, the I2C setup. As I said, if you were able to get the code above to work you can get this to work. | As I do most of the time, we’ll start (top right) with the import section and, in this case, the I2C setup. As I said, if you were able to get the code above to work you can get this to work. | ||
Ligne 141: | Ligne 282: | ||
At this point (bottom right), we can create our first support function. This one is called scroll_in_screen and will scroll the screen horizontally from left to right. Once everything has been passed into the display, the function is finished and you can call sleep for a period so the user can read the message. | At this point (bottom right), we can create our first support function. This one is called scroll_in_screen and will scroll the screen horizontally from left to right. Once everything has been passed into the display, the function is finished and you can call sleep for a period so the user can read the message. | ||
- | Now that we have all of our support functions coded (final ones shown top right), we can start using them. Each demo portion is fairly long, so we’ll just loop three times. The original code (next page, on the left) had this as a forever loop. | + | Now that we have all of our support functions coded (final ones shown top right), we can start using them. Each demo portion is fairly long, so we’ll just loop three times. The original code (next page, on the left) had this as a forever loop.** |
- | Once the demo is finished, clear the display. | + | Mise en route |
+ | |||
+ | Comme je le fais la plupart du temps, nous allons commencer (en haut à droite) par la section d' | ||
+ | |||
+ | Maintenant que nous avons mis en place le texte des « écrans », nous devons créer une liste de listes (au milieu à droite) que nous passerons dans les fonctions que nous allons créer. Chaque entrée de la liste est configurée comme X (colonne), Y (ligne) et message. Dans le code ci-dessus, nous avons créé trois messages comme « screen1 », deux messages comme « screen2 » et un message comme « screen3 ». Il nous suffit donc de définir l' | ||
+ | |||
+ | À ce stade (en bas à droite), nous pouvons créer notre première fonction de support. Celle-ci s' | ||
+ | |||
+ | Maintenant que nous avons codé toutes nos fonctions de support (les dernières en haut à droite), nous pouvons commencer à les utiliser. Chaque partie de la démo est assez longue, donc nous allons simplement boucler trois fois. Dans le code original (page suivante, à gauche), il s' | ||
+ | |||
+ | |||
+ | **Once the demo is finished, clear the display. | ||
# Clear the OLED | # Clear the OLED | ||
Ligne 155: | Ligne 307: | ||
I’ve taken up all the space that I should, so that’s all for this month. You can find the code for both projects (in both Pico and ESP formats) at my github repository at https:// | I’ve taken up all the space that I should, so that’s all for this month. You can find the code for both projects (in both Pico and ESP formats) at my github repository at https:// | ||
- | Until next time, as always; stay safe, healthy, positive and creative! | + | Until next time, as always; stay safe, healthy, positive and creative!** |
+ | |||
+ | Une fois la démo terminée, effacez l' | ||
+ | |||
+ | # Clear the OLED | ||
+ | |||
+ | oled.fill(0) | ||
+ | |||
+ | oled.show() | ||
+ | |||
+ | Maintenant que vous avez vu les fonctions qui fonctionnent de gauche à droite et de haut en bas, vous pouvez essayer de créer des fonctions qui défilent de droite à gauche et de bas en haut. | ||
+ | |||
+ | J'ai pris toute la place que je devais prendre et c'est tout pour ce mois-ci. Vous pouvez trouver le code des deux projets (aux formats Pico et ESP) dans mon dépôt github à l' | ||
+ | |||
+ | Jusqu' | ||
+ | |||
+ | |||
+ | |||
+ | // Textes en noir dans les encadrés : // | ||
+ | p. 33 : | ||
+ | **For the RPi Pico, I used GP8 and GP9 (physical pins 11 and 12) for the connection to the I2C bus. The code for the Pico will be…** | ||
+ | Pour le RPi Pico, j'ai utilisé GP8 et GP9 (picots physiques 11 et 12) pour les connexions au bus I2C. Le code pour le Pico sera : | ||
+ | |||
+ | **From here the code for all three microcontrollers will be the same.** | ||
+ | À partir d'ici, le code est le même pour les 3 microcontrôleurs. | ||
+ | |||
+ | p. 35 : | ||
+ | **At this point, let’s set up a few simple lines of text that will embody our “screens” that will be scrolled.** | ||
+ | Arrivé ici, paramétrons quelques simples lignes de texte qui peupleront nos « écrans » qui défileront. | ||
+ | |||
+ | **The next function will take the data that is already on the screen and scroll it off the display towards the right side. This function has a speed parameter.** | ||
+ | Le fonction suivante prendra les données qui sont déjà à l' | ||
+ | |||
+ | p. 36 : | ||
+ | **Here is the scroll vertically from top to bottom, pausing when the screen is full.** | ||
+ | Voici le déroulement vertical du haut vers le bas, avec un arrêt quand l' | ||
+ | |||
+ | **This is the function that will scroll the data off the bottom of the screen.** | ||
+ | Voici la fonction qui évacuera les données par le bas de l' | ||
+ | |||
+ | **Finally, here is the continuous vertical scroll support function.** | ||
+ | Enfin, voici la fonction qui prend en charge le déroulement vertical continu. | ||
issue173/micro-ci_micro-la.1632647319.txt.gz · Dernière modification : 2021/09/26 11:08 de auntiee