Modifications

Sauter à la navigation Sauter à la recherche
752 octets ajoutés ,  9 février 2018 à 13:17
aucun résumé de modification
Ligne 1 : Ligne 1 :  
{{RASP-PiOLED-NAV}}
 
{{RASP-PiOLED-NAV}}
  −
{{traduction}}
      
== Introduction ==
 
== Introduction ==
Ligne 167 : Ligne 165 :  
Le restant du code peut rester en commentaire.
 
Le restant du code peut rester en commentaire.
   −
Notez que ci-dessus, nous avons initialisé {{fname|RST = None}} parce que le PiOLED ne nécessite pas l'utilisation de la broche "reset".
+
Notez que ci-dessus, nous avons initialisé {{fname|1=RST = None}} parce que le PiOLED ne nécessite pas l'utilisation de la broche "reset".
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
Ligne 192 : Ligne 190 :  
</syntaxhighlight>
 
</syntaxhighlight>
   −
{{traduction}}
+
La portion de code ci-dessus, initialise la bibliothèque d'affichage avec {{fname|begin()}} et efface le contenu avec {{fname|clear()}} et {{fname|display()}} .
The next bit of code will initialize the display library with <code>begin()</code> and clear the display with <code>clear()</code>and <code>display()</code>.
     −
Then it will configure a PIL drawing class to prepare for drawing graphics. Notice that the image buffer is created in 1-bit mode with the <code>'1'</code> parameter, this is important because the display only supports black and white colors.
+
Ensuite, nous configurons une classe PIL drawing pour dessiner des graphiques. La mémoire tampon de l'image est crée avec un bit de profondeur (mode avec paramètre {{fname|'1'}}. Ce mode est important puisque l'afficheur ne propose que deux couleurs noir et blanc.
   −
We then re-draw a large black rectangle to clear the screen. In theory we don't have to clear the screen again, but its a good example of how to draw a shape!
+
Ensuite nous redessinons un grand rectangle noir pour effacer effacer le contenu de l'écran (éteindre tous les pixels). En théorie, il n'est pas nécessaire d'effacer une seconde fois l'écran... mais c'est toujours un bonne idée de savoir comment dessiner une forme!
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
# Load default font.
+
# Charger la font par défaut.
 
font = ImageFont.load_default()
 
font = ImageFont.load_default()
   −
# Alternatively load a TTF font.
+
# Chargement d'une autre font TTF.
# Some other nice fonts to try: http://www.dafont.com/bitmap.php
+
# D'autres fonts sont disponibles sur: http://www.dafont.com/bitmap.php
 
#font = ImageFont.truetype('Minecraftia.ttf', 8)
 
#font = ImageFont.truetype('Minecraftia.ttf', 8)
 
</syntaxhighlight>
 
</syntaxhighlight>
   −
Once the display is initialized and a drawing object is prepared, you can draw shapes, text and graphics using <a href="http://effbot.org/imagingbook/imagedraw.htm">PIL's drawing commands</a>. Here we are loading the <code>default</code> font, which works fine, but there's other fonts you can load.
+
Une fois l'afficheur initialisé et un objet dessin (ImageDrawing) préparé, vous pouvez dessiner des formes, du texte et des graphiques en utilisant [http://effbot.org/imagingbook/imagedraw.htm des commandes de dessin PIL] (''effbot.org, anglais''). Dans le cas présent, le code charge la font {{fname|par défaut}} qui est parfaite mais vous pouvez également charger d'autres fonts. Il es possible de charger des fonts TrueType et de les utiliser pour faire du rendu de texte de tout style
   −
Next the code loads a built-in default font and draws a few lines of text. You can also load your own TrueType font and use it to render fancy text in any style you like
+
Une fois la font par défaut chargée, il est possible d'afficher quelques lignes de texte.  
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
 
while True:
 
while True:
   −
     # Draw a black filled box to clear the image.
+
     # Afficher un rectangle noir pour effacer l'image de l'écran.
 
     draw.rectangle((0,0,width,height), outline=0, fill=0)
 
     draw.rectangle((0,0,width,height), outline=0, fill=0)
   −
     # Shell scripts for system monitoring from here : https://unix.stackexchange.com/questions/119126/command-to-display-memory-usage-disk-usage-and-cpu-load
+
     # Script shell pour surveiller les paramètres système :  
 +
    # https://unix.stackexchange.com/questions/119126/command-to-display-memory-usage-disk-usage-and-cpu-load
 
     cmd = "hostname -I | cut -d\' \' -f1"
 
     cmd = "hostname -I | cut -d\' \' -f1"
 
     IP = subprocess.check_output(cmd, shell = True )
 
     IP = subprocess.check_output(cmd, shell = True )
Ligne 228 : Ligne 226 :  
     Disk = subprocess.check_output(cmd, shell = True )
 
     Disk = subprocess.check_output(cmd, shell = True )
   −
     # Write two lines of text.
+
     # Ecrire quatre lignes de texte
 
   
     draw.text((x, top),      "IP: " + str(IP),  font=font, fill=255)
 
     draw.text((x, top),      "IP: " + str(IP),  font=font, fill=255)
 
     draw.text((x, top+8),    str(CPU), font=font, fill=255)
 
     draw.text((x, top+8),    str(CPU), font=font, fill=255)
Ligne 235 : Ligne 232 :  
     draw.text((x, top+25),    str(Disk),  font=font, fill=255)
 
     draw.text((x, top+25),    str(Disk),  font=font, fill=255)
   −
     # Display image.
+
     # Afficher l'image sur l'écran
 
     disp.image(image)
 
     disp.image(image)
 
     disp.display()
 
     disp.display()
     time.sleep(.1)
+
    # pause de 100 millisecondes
 +
     time.sleep(.1)  
 
</syntaxhighlight>
 
</syntaxhighlight>
   −
Using the subprocess class, python can utilize linux commands to access the Pi's system information. This loop updates the screen at 10 times a second.<br><br>That's all there is to the '''stats.py''' code!
+
En utilisant la classe subprocess, python peut utiliser des commandes Linux pour accéder aux informations systèmes du Pi. La boucle {{fname|while}} effectue un rafraîchissement de l'écran 10 fois par seconde.  
 +
 
 +
Voilà, c'est tout en ce qui concerne le code de '''stats.py''' !
   −
== More Demos & Examples ==
+
== Plus d'exemples ==
You can check out our other examples in the example, just make sure to edit each one with '''nano animate.py''' for example, and find the line that says:
+
Vous pouvez consulter les autres exemples du sous-répertoire {{fname|examples}}.
 +
 
 +
Assurez-vous d'éditer chacun des exemples (avec '''nano animate.py''' par exemple) et trouvez la ligne mentionnant:
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
Ligne 251 : Ligne 253 :  
</syntaxhighlight>
 
</syntaxhighlight>
   −
and change it to:
+
et la changer en :
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
 
# Raspberry Pi pin configuration:
 
# Raspberry Pi pin configuration:
RST = None # PiOLED does not require reset pin
+
RST = None # PiOLED n'a pas besoin de la broche Reset
 
</syntaxhighlight>
 
</syntaxhighlight>
   −
and make sure that the configuration section where you choose which type of display, looks like this
+
puis assurez vous que la configuration section utilise la déclaration correspond à votre afficheur PiOled... comme ceci:
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
Ligne 274 : Ligne 276 :  
</syntaxhighlight>
 
</syntaxhighlight>
   −
That is, we'll be using I2C 128x32 display!
+
Voila, le script d'exemple utilise maintenant un afficheur I2C 128x32 pixels (sans broche Reset)!
   −
== Speeding Up the Display ==
+
== Améliorer la vitesse de l'afficheur ==
For the best performance, especially if you are doing fast animations, you'll want to tweak the I2C core to run at 1MHz. By default it may be 100KHz or 400KHz
+
Pour de meilleures performances, plus spécialement si vous avez besoin d'animation rapide, vous pouvez optimiser le fonctionnement du bus I2C pour qu'il fonctionne 1MHz. En effet, le bus est configuré à la fréquence 100KHz ou 400KHz
   −
To do this edit the config with '''sudo nano /boot/config.txt'''
+
Pour modifier la vitesse du bus, éditez le fichier de configuration avec '''sudo nano /boot/config.txt'''
   −
and add to the end of the file
+
et ajoutez la ligne suivante à la fin du fichier
   −
'''dtparam=i2c_baudrate=1000000'''
+
<syntaxhighlight lang="python">
 +
dtparam=i2c_baudrate=1000000
 +
</syntaxhighlight>
    
{{ADFImage|RASP-PiOLED-Utiliser-06.png|640px}}
 
{{ADFImage|RASP-PiOLED-Utiliser-06.png|640px}}
   −
reboot to 'set' the change.
+
Redémarrer le Pi pour appliquer les modifications.
 
      
{{RASP-PiOLED-TRAILER}}
 
{{RASP-PiOLED-TRAILER}}
29 917

modifications

Menu de navigation