Modifications

Sauter à la navigation Sauter à la recherche
1 005 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 121 : Ligne 119 :     
Vous pouvez également noter l'importation de quelques éléments de la bibliothèque'' '''P'''ython '''I'''maging '''L'''ibrary'' comme '''Image''', '''ImageDraw''' et  '''ImageFont'''. Comme vous pouvez l'imaginer, ces éléments servirons a dessiner des images, des formes et du texte/font!
 
Vous pouvez également noter l'importation de quelques éléments de la bibliothèque'' '''P'''ython '''I'''maging '''L'''ibrary'' comme '''Image''', '''ImageDraw''' et  '''ImageFont'''. Comme vous pouvez l'imaginer, ces éléments servirons a dessiner des images, des formes et du texte/font!
 +
 +
Ci dessous les différentes valeurs de configuration et classe pour les afficheurs OLED. Il y a 4 variantes d'afficheur OLED, avec 128x32 pixels ou 128x64 pixels -ET- avec I2C ou avec SPI.
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
Ligne 156 : Ligne 156 :  
</syntaxhighlight>
 
</syntaxhighlight>
   −
Below the configuration values is the display class setup. There are 4 variants of OLED displays, with 128x32 pixels or 128x64 pixels, and with I2C or with SPI. 
+
Etant donné que l'afficheur PiOLED est un afficheur OLED 128x32 sur bus (uniquement), vous devez uniquement utiliser le code:
   −
However since the PiOLED is a 128x32 I2C display ''only'' you should only use the
+
<syntaxhighlight lang="python">
 
+
# afficheur 128x32 avec bus I2C matériel:
<code># 128x32 display with hardware I2C:</code><br><code>disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)</code>
+
disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)
 +
</syntaxhighlight>
   −
variant for creating the display object! The rest can remain commented out.
+
Le restant du code peut rester en commentaire.
   −
Note that above, we initialize <code>RST = None</code> because the PiOLED does not require a reset pin.
+
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">
# Initialize library.
+
# initialiser la bibliothèque d'affichage.
 
disp.begin()
 
disp.begin()
   −
# Clear display.
+
# Effacer l'affichage.
 
disp.clear()
 
disp.clear()
 
disp.display()
 
disp.display()
   −
# Create blank image for drawing.
+
# Créer une image vierge pour dessiner dessus.
# Make sure to create image with mode '1' for 1-bit color.
+
# L'image doit être créé avec mode '1' (couleur 1-bit).
 
width = disp.width
 
width = disp.width
 
height = disp.height
 
height = disp.height
 
image = Image.new('1', (width, height))
 
image = Image.new('1', (width, height))
   −
# Get drawing object to draw on image.
+
# Obtenir un objet ImageDraw (dessiner sur l'image)
 +
# pour l'image.
 
draw = ImageDraw.Draw(image)
 
draw = ImageDraw.Draw(image)
   −
# Draw a black filled box to clear the image.
+
# Dessiner un rectangle noir (rempli) pour effacer
 +
# le fond de l'image (sinon cela allumera les Pixels).
 
draw.rectangle((0,0,width,height), outline=0, fill=0)
 
draw.rectangle((0,0,width,height), outline=0, fill=0)
 
</syntaxhighlight>
 
</syntaxhighlight>
   −
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>.
+
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()}} .
   −
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 222 : 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 229 : 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''' !
 +
 
 +
== Plus d'exemples ==
 +
Vous pouvez consulter les autres exemples du sous-répertoire {{fname|examples}}.
   −
== More Demos & Examples ==
+
Assurez-vous d'éditer chacun des exemples (avec '''nano animate.py''' par exemple) et trouvez la ligne mentionnant:
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:
      
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
Ligne 245 : 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 268 : 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