Displays mit ST7735 TreiberIC: Unterschied zwischen den Versionen

Aus Micropython Referenz
Zur Navigation springen Zur Suche springen
Peter (Diskussion | Beiträge)
Peter (Diskussion | Beiträge)
 
(16 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 86: Zeile 86:


== Die ST7735 Module ==
== Die ST7735 Module ==
Es gibt im Internet diverse ST7735-Module:
Es gibt im Internet diverse ST7735-Module.


=== https://github.com/hosaka/micropython-st7735 ===
=== https://github.com/GuyCarver/MicroPython ===
Es gibt noch mehr Module für Micropython. Es lohnt sich diese mal anzusehen.
Es gibt hier noch mehr Module für Micropython. Es lohnt sich diese mal anzusehen.


Unter dieser URL: https://github.com/GuyCarver/MicroPython/blob/master/lib/ST7735.py kann das Modul heruntergeladen werden.
Unter dieser URL: https://github.com/GuyCarver/MicroPython/blob/master/lib/ST7735.py kann das Modul heruntergeladen werden.
Zeile 96: Zeile 96:


Dieses Modul verwendet verschiedene Fonts, die in .py Dateien gespeichert sind:
Dieses Modul verwendet verschiedene Fonts, die in .py Dateien gespeichert sind:
* seriffont.py
* sysfont.py
* terminalfont.py
* sevenseg.py
Diese habe ich ebenfalls nach /lib auf dem Pico herunter geladen. Sie werden auch für das Modul von [https://github.com/boochow/MicroPython-ST7735 boochow] benötigt.


Aus dem Quellcode der komplett in Micropython geschrieben ist ergibt sich folgendes:
Aus dem Quellcode der komplett in Micropython geschrieben ist ergibt sich folgendes:
Dieses st7735-Module ist für das PyBoard geschrieben und verwenden dessen pyb-Modul. Weiterhin wird die SPI-Schnittstelle des PyBoard durch Zeichen identifiziert und die zugehörigen Pins sind intern bekannt. Die Klasse '''ttf''' initialisiert auch die SPI-Schnittstelle.
Weiterhin gibt es wohl 3 verschiedene Versionen des 128x160 Displays. Es gibt im Quellcode Initialisierungsfunktionen für rote, grüne und blaue Platinen.


Die Displaygröße ist fest im Modul eingetragen:<syntaxhighlight lang="py3" line="1">
Die Displaygröße ist fest im Modul eingetragen:<syntaxhighlight lang="py3" line="1">
Zeile 104: Zeile 115:


==== Initialisierung ====
==== Initialisierung ====
Es gibt die Klasse '''tft''' mit der eine Instanz für das Display erstellt werden kann:<syntaxhighlight lang="py3" line="1">
Die Initialisierung habe ich nicht verstanden und konnte ich mangels PyBoard nicht testen.
disp = st7735.tft(spi, DC_Pin, RES_Pin)
 
</syntaxhighlight>Demofile: https://github.com/GuyCarver/MicroPython/blob/master/tft.py
Demofile: https://github.com/GuyCarver/MicroPython/blob/master/tft.py


==== Methoden ====
==== Methoden ====
 
Dieses Modul bietet folgende Methoden:
 
<!---
class tft(object)
 
def __init__( self, aLoc, aDC, aReset )
 
<nowiki>'''aLoc SPI pin location is either 1 for 'X' or 2 for 'Y'</nowiki>.
 
      aDC is the DC pin and aReset is the reset pin.<nowiki>'''</nowiki>
 
_SCREENSIZE = (128, 160) ist fest in dem Modul eingetragen
--->
 
; size()
; size()
: gibt die Displaygrössez urück
: gibt die Displaygrössez zurück


; on(aTF = True)
; on(aTF = True)
Zeile 138: Zeile 136:
: 0 - 3. Starts vertical with top toward pins and rotates 90 deg clockwise each step.<nowiki>'''</nowiki>
: 0 - 3. Starts vertical with top toward pins and rotates 90 deg clockwise each step.<nowiki>'''</nowiki>


def pixel( self, aPos, aColor )  
; pixel( self, aPos, aColor )
:  Setzt ein Pixel der Farbe aColor an aPos. aPos ist ein Tuple mit den x,y Koordinaten.
 
; text( self, aPos, aString, aColor, aFont, aSize = 1 )
: <nowiki>'''</nowiki>Draw a text at the given position.  If the string reaches the end of thedisplay it is wrapped to aPos[0] on the next line.  aSize may be an integer which will size the font uniformly on w,h or a or any type that may be indexed with [0] or [1].<nowiki>'''</nowiki>
 
; char( self, aPos, aChar, aColor, aFont, aSizes )
: <nowiki>'''</nowiki>Draw a character at the given position using the given font and color. aSizes is a tuple with x, y as integer scales indicating the # of pixels to draw for each pixel in the character.<nowiki>'''</nowiki>


def text( self, aPos, aString, aColor, aFont, aSize = 1 ) :
;line( self, aStart, aEnd, aColor )  
: <nowiki>'''</nowiki>Draws a line from aStart to aEnd in the given color.  Vertical or horizontal lines are forwarded to vline and hline.<nowiki>'''</nowiki>


   <nowiki>'''</nowiki>Draw a text at the given position.  If the string reaches the end of the
; vline( self, aStart, aLen, aColor )
: <nowiki>'''Draw a vertical line from aStart for aLen. aLen may be negative.'''</nowiki>


      display it is wrapped to aPos[0] on the next line.  aSize may be an integer
; hline( self, aStart, aLen, aColor )
: <nowiki>'''Draw a horizontal line from aStart for aLen. aLen may be negative.'''</nowiki>


      which will size the font uniformly on w,h or a or any type that may be
; rect( self, aStart, aSize, aColor )
: <nowiki>'''</nowiki>Draw a hollow rectangle.  aStart is the smallest coordinate corner and aSize is a tuple indicating width, height.<nowiki>'''</nowiki>


      indexed with [0] or [1].<nowiki>'''</nowiki>
; fillrect( self, aStart, aSize, aColor )
: <nowiki>'''</nowiki>Draw a filled rectangle.  aStart is the smallest coordinate corner and aSize is a tuple indicating width, height.<nowiki>'''</nowiki>


def char( self, aPos, aChar, aColor, aFont, aSizes ) :
; circle( self, aPos, aRadius, aColor )  
: <nowiki>'''Draw a hollow circle with the given radius and color with aPos as center.'''</nowiki>


   <nowiki>'''</nowiki>Draw a character at the given position using the given font and color.
; fillcircle( self, aPos, aRadius, aColor )
: <nowiki>'''Draw a filled circle with given radius and color with aPos as center'''</nowiki>


      aSizes is a tuple with x, y as integer scales indicating the
; fill( self, aColor = BLACK )
: <nowiki>'''Fill screen with the given color.'''</nowiki>


      # of pixels to draw for each pixel in the character.<nowiki>'''</nowiki>
=== https://github.com/boochow/MicroPython-ST7735 ===
Dieses Modul basiert auf dem von '''GuyCarver''' (s.o.) ist aber nicht an das PyBoard gebunden, sondern für Micropython ESP32 umgeschrieben.


def line( self, aStart, aEnd, aColor ) :
Ob es auch mit den Pico spielt?


   <nowiki>'''</nowiki>Draws a line from aStart to aEnd in the given color.  Vertical or horizontal
Hier werden die Font-Dateien von GuyCarver benötigt.


      lines are forwarded to vline and hline.<nowiki>'''</nowiki>
==== Initialisieren ====
<syntaxhighlight lang="py3" line="1" start="1">
from ST7735 import TFT
from sysfont import sysfont
from machine import SPI,Pin
import time
import math
spi = SPI(2, baudrate=20000000, polarity=0, phase=0, sck=Pin(14), mosi=Pin(13), miso=Pin(12))
tft=TFT(spi,16,17,18)  # TFT(spi, DC, Reset, CS)
tft.initr()
tft.rgb(True)
</syntaxhighlight>Das Modul '''sysfont.py''' stammt von https://github.com/GuyCarver/MicroPython.


def vline( self, aStart, aLen, aColor ) :
Die Initialisierung von '''spi''' und '''tft''' enthalten keine Besonderheiten. Allerdings sind noch 2 zusätzliche Aktionen nötig:<syntaxhighlight lang="py3" line="1">
tft.initr()
</syntaxhighlight>Initialisiert die Eigenheiten eines Displays mit roten Board. Außerdem gibt er noch


   <nowiki>'''Draw a vertical line from aStart for aLen. aLen may be negative.'''</nowiki>
* initg() für grünes Board und
* initb() für das blaue Board oder
* initb2() für ein anderes blaues Board.


def hline( self, aStart, aLen, aColor ) :
Die richtige Auswahl muss ggf. ausprobiert werden.<syntaxhighlight lang="py3" line="1">
tft.rgb(True)
</syntaxhighlight>Stellt die Farbcodierung auf RGB ein. Alternativ ist BGR möglich.


   <nowiki>'''Draw a horizontal line from aStart for aLen. aLen may be negative.'''</nowiki>
Die Farbe wird als 16-bit Wert erwartet. Es wird rgb 565 verteilt. Die Umwandlung von 888 in 565 wird von der Funktion '''TFTColor( R, G, B)''' vorgenommen.


def rect( self, aStart, aSize, aColor ) :
==== Methoden ====
Hier sind alle Methoden von GuyCarver implementiert. Zusätzlich gibt es noch:


   <nowiki>'''</nowiki>Draw a hollow rectangle.  aStart is the smallest coordinate corner
; image( self, x0, y0, x1, y1, data )
: Stellt ein Bild auf dem Display dar.


      and aSize is a tuple indicating width, height.<nowiki>'''</nowiki>
; setvscroll(self, tfa, bfa)
: Einstellung des Bereichs für vertikales Scrollen.


def fillrect( self, aStart, aSize, aColor ) :
; vscroll(self, value)
: Führt das Scrollen aus.


   <nowiki>'''</nowiki>Draw a filled rectangle.  aStart is the smallest coordinate corner
=== https://github.com/hosaka/micropython-st7735 ===


      and aSize is a tuple indicating width, height.<nowiki>'''</nowiki>


def circle( self, aPos, aRadius, aColor ) :


   <nowiki>'''Draw a hollow circle with the given radius and color with aPos as center.'''</nowiki>


def fillcircle( self, aPos, aRadius, aColor ) :


   <nowiki>'''Draw a filled circle with given radius and color with aPos as center'''</nowiki>
=== https://github.com/AnthonyKNorman/MicroPython_ST7735/tree/master ===
Dieses Modul basiert komplett auf Micropython, ist aber schon 8 Jahre alt.


def fill( self, aColor = BLACK ) :
Es besteht aus mehreren Modulen:
* ST7735.py  - Der eigentliche Treiber.
* lcd_gfx.py  - Stellt die grafischen Methoden bereit.
* bmp.py      - Lädt ein Bild auf das Display
* font5x7.fnt - Ein Font
Dieses Modul erscheint mir sehr übersichtlich und dürfte deshalb gut anzuwenden sein.


   <nowiki>'''Fill screen with the given color.'''</nowiki>


== Links: ==
== Links: ==
https://github.com/hosaka/micropython-st7735


https://github.com/AnthonyKNorman/MicroPython_ST7735
https://github.com/GuyCarver/MicroPython


https://github.com/AnthonyKNorman/MicroPython_SSD1306
https://github.com/AnthonyKNorman/MicroPython_SSD1306


https://www.electronicshub.org/esp32-nokia-5110-lcd/
https://www.electronicshub.org/esp32-nokia-5110-lcd/
https://github.com/boochow/MicroPython-ST7735
https://github.com/peterhinch/micropython-nano-gui
https://github.com/boochow/MicroPython-ST7735
https://github.com/boochow/MicroPython-ST7735/blob/master/ST7735.py
https://github.com/GuyCarver/MicroPython
https://github.com/GuyCarver/MicroPython/tree/master/lib
https://github.com/GuyCarver/MicroPython/blob/master/lib/ST7735.py
https://github.com/russhughes/st7789_mpy

Aktuelle Version vom 8. Januar 2024, 00:56 Uhr

1,77" Display 160x128 RGB SPI[Bearbeiten | Quelltext bearbeiten]

Dieses Display stammt von azdelivery.de: https://www.azdelivery.de/products/1-77-zoll-spi-tft-display

Front- und Rückansicht des Displays. In der Draufsicht liegt Pin1 ganz links.

Technische Daten[Bearbeiten | Quelltext bearbeiten]

✅ Leuchtstarkes, entspiegeltes TFT-Display mit großer 1,77 Zoll Bilddiagonale

✅ Große Auflösung von 128x160 Pixeln zur klaren Darstellung von Texten, Grafiken und Bildern

✅ Hohe Hardwarekompatibilität mit Arduino, Raspberry Pi & Co. dank Standard SPI-Datenschnittstelle und frei verfügbarer Bibliotheken für den ST7735 Bildcontroller

✅ Maße (LxBxH) – Board: 34 x 54 x 3,5* mm (ca. 12mm inkl. Pins); Display: 34 x 43 x 2,4 mm; Anzeigefläche: 28 x 35 mm

Vorbemerkung[Bearbeiten | Quelltext bearbeiten]

Die Ersten beiden st7735-Module sind für das PyBoard geschrieben und verwenden dessen pyb-Modul. Weiterhin wird die SPI-Schnittstelle des PyBoard durch Zeichen identifiziert und die zugehörigen Pins sind intern bekannt. Die Klasse ttf initialisiert auch die SPI-Schnittstelle.

Weiterhin gibt es wohl 3 verschiedene Versionen des 128x160 Displays. Es gibt im Quellcode Initialisierungsfunktionen für rote, grüne und blaue Platinen.

Testumgebung[Bearbeiten | Quelltext bearbeiten]

Raspberry Pi Pico[Bearbeiten | Quelltext bearbeiten]

Der Test es Displays und der Treibermodule erfolgt auf einem Raspberry Pi Pico. Es wird die Hardware-SPI-Schnittstelle 0 verwendet.

>>> print(SPI(0))
    SPI(0, baudrate=992063, polarity=0, phase=0, bits=8, sck=18, mosi=19, miso=16)

Es können die DefaultPins verwendet werden. Daraus ergibt sich folgende Verdrahtung:

Verdrahtung
1,77" Display Pico
Pin Bezeichnung GPIO
1 GND GND
2 Vcc 3V3
3 SCK 18
4 SDA 19
5 RES 22
6 RS 20
7 CS 17
8 LEDA 21

Display Initialisieren[Bearbeiten | Quelltext bearbeiten]

Da MISO nicht benutzt wird braucht ihm auch kein GPIO zugewiesen werden:

from machine import SPI, Pin

spi = SPI(0, miso=None)

Das führt aber nicht dazu, dass GPIO16 nicht initialisiert wird!

>>> print(spi)
    SPI(0, baudrate=992063, polarity=0, phase=0, bits=8, sck=18, mosi=19, miso=16)

GPIO16 wird nicht als IN oder OUT initialisiert, sonder als alternative Funktion und als Eingang wie "pull=PULL_DOWN" zeigt.

>>> print(Pin(16))
    Pin(GPIO16, mode=ALT, pull=PULL_DOWN, alt=SPI)

Deshalb wird GPIO16 vorerst nicht benutzt. Später werde ich testen, ob man ihn für andere Zwecke verwenden kann.

Die ST7735 Module[Bearbeiten | Quelltext bearbeiten]

Es gibt im Internet diverse ST7735-Module.

https://github.com/GuyCarver/MicroPython[Bearbeiten | Quelltext bearbeiten]

Es gibt hier noch mehr Module für Micropython. Es lohnt sich diese mal anzusehen.

Unter dieser URL: https://github.com/GuyCarver/MicroPython/blob/master/lib/ST7735.py kann das Modul heruntergeladen werden.

Ich habe es unter st7735_1.py gespeichert und in das lib-Verzeichnis des Pico kopiert.

Dieses Modul verwendet verschiedene Fonts, die in .py Dateien gespeichert sind:

  • seriffont.py
  • sysfont.py
  • terminalfont.py
  • sevenseg.py

Diese habe ich ebenfalls nach /lib auf dem Pico herunter geladen. Sie werden auch für das Modul von boochow benötigt.

Aus dem Quellcode der komplett in Micropython geschrieben ist ergibt sich folgendes:

Dieses st7735-Module ist für das PyBoard geschrieben und verwenden dessen pyb-Modul. Weiterhin wird die SPI-Schnittstelle des PyBoard durch Zeichen identifiziert und die zugehörigen Pins sind intern bekannt. Die Klasse ttf initialisiert auch die SPI-Schnittstelle.

Weiterhin gibt es wohl 3 verschiedene Versionen des 128x160 Displays. Es gibt im Quellcode Initialisierungsfunktionen für rote, grüne und blaue Platinen.

Die Displaygröße ist fest im Modul eingetragen:

_SCREENSIZE = (128, 160)

Bei einer anderen Displaygröße muss diese im Quellcode geändert werden.

Initialisierung[Bearbeiten | Quelltext bearbeiten]

Die Initialisierung habe ich nicht verstanden und konnte ich mangels PyBoard nicht testen.

Demofile: https://github.com/GuyCarver/MicroPython/blob/master/tft.py

Methoden[Bearbeiten | Quelltext bearbeiten]

Dieses Modul bietet folgende Methoden:

size()
gibt die Displaygrössez zurück
on(aTF = True)
Schaltet das Display ein/aus. on() schaltet ein. on(aTF=False) schaltet aus.
invertcolor(aBool)
aBool = TrueiInvertiert die Farbe. aBool = False invertiert nicht.
rgb(aTF = True)
True = rgb False = bgr
rotation( self, aRot )
0 - 3. Starts vertical with top toward pins and rotates 90 deg clockwise each step.'''
pixel( self, aPos, aColor )
Setzt ein Pixel der Farbe aColor an aPos. aPos ist ein Tuple mit den x,y Koordinaten.
text( self, aPos, aString, aColor, aFont, aSize = 1 )
'''Draw a text at the given position.  If the string reaches the end of thedisplay it is wrapped to aPos[0] on the next line.  aSize may be an integer which will size the font uniformly on w,h or a or any type that may be indexed with [0] or [1].'''
char( self, aPos, aChar, aColor, aFont, aSizes )
'''Draw a character at the given position using the given font and color. aSizes is a tuple with x, y as integer scales indicating the # of pixels to draw for each pixel in the character.'''
line( self, aStart, aEnd, aColor )
'''Draws a line from aStart to aEnd in the given color.  Vertical or horizontal lines are forwarded to vline and hline.'''
vline( self, aStart, aLen, aColor )
'''Draw a vertical line from aStart for aLen. aLen may be negative.'''
hline( self, aStart, aLen, aColor )
'''Draw a horizontal line from aStart for aLen. aLen may be negative.'''
rect( self, aStart, aSize, aColor )
'''Draw a hollow rectangle.  aStart is the smallest coordinate corner and aSize is a tuple indicating width, height.'''
fillrect( self, aStart, aSize, aColor )
'''Draw a filled rectangle.  aStart is the smallest coordinate corner and aSize is a tuple indicating width, height.'''
circle( self, aPos, aRadius, aColor )
'''Draw a hollow circle with the given radius and color with aPos as center.'''
fillcircle( self, aPos, aRadius, aColor )
'''Draw a filled circle with given radius and color with aPos as center'''
fill( self, aColor = BLACK )
'''Fill screen with the given color.'''

https://github.com/boochow/MicroPython-ST7735[Bearbeiten | Quelltext bearbeiten]

Dieses Modul basiert auf dem von GuyCarver (s.o.) ist aber nicht an das PyBoard gebunden, sondern für Micropython ESP32 umgeschrieben.

Ob es auch mit den Pico spielt?

Hier werden die Font-Dateien von GuyCarver benötigt.

Initialisieren[Bearbeiten | Quelltext bearbeiten]

from ST7735 import TFT
from sysfont import sysfont
from machine import SPI,Pin
import time
import math
spi = SPI(2, baudrate=20000000, polarity=0, phase=0, sck=Pin(14), mosi=Pin(13), miso=Pin(12))
tft=TFT(spi,16,17,18)   # TFT(spi, DC, Reset, CS)
tft.initr()
tft.rgb(True)

Das Modul sysfont.py stammt von https://github.com/GuyCarver/MicroPython. Die Initialisierung von spi und tft enthalten keine Besonderheiten. Allerdings sind noch 2 zusätzliche Aktionen nötig:

tft.initr()

Initialisiert die Eigenheiten eines Displays mit roten Board. Außerdem gibt er noch

  • initg() für grünes Board und
  • initb() für das blaue Board oder
  • initb2() für ein anderes blaues Board.

Die richtige Auswahl muss ggf. ausprobiert werden.

tft.rgb(True)

Stellt die Farbcodierung auf RGB ein. Alternativ ist BGR möglich.

Die Farbe wird als 16-bit Wert erwartet. Es wird rgb 565 verteilt. Die Umwandlung von 888 in 565 wird von der Funktion TFTColor( R, G, B) vorgenommen.

Methoden[Bearbeiten | Quelltext bearbeiten]

Hier sind alle Methoden von GuyCarver implementiert. Zusätzlich gibt es noch:

image( self, x0, y0, x1, y1, data )
Stellt ein Bild auf dem Display dar.
setvscroll(self, tfa, bfa)
Einstellung des Bereichs für vertikales Scrollen.
vscroll(self, value)
Führt das Scrollen aus.

https://github.com/hosaka/micropython-st7735[Bearbeiten | Quelltext bearbeiten]

https://github.com/AnthonyKNorman/MicroPython_ST7735/tree/master[Bearbeiten | Quelltext bearbeiten]

Dieses Modul basiert komplett auf Micropython, ist aber schon 8 Jahre alt.

Es besteht aus mehreren Modulen:

  • ST7735.py - Der eigentliche Treiber.
  • lcd_gfx.py - Stellt die grafischen Methoden bereit.
  • bmp.py - Lädt ein Bild auf das Display
  • font5x7.fnt - Ein Font

Dieses Modul erscheint mir sehr übersichtlich und dürfte deshalb gut anzuwenden sein.


Links:[Bearbeiten | Quelltext bearbeiten]

https://github.com/AnthonyKNorman/MicroPython_SSD1306

https://www.electronicshub.org/esp32-nokia-5110-lcd/