hzeller / rpi-rgb-led-matrix

Controlling up to three chains of 64x64, 32x32, 16x32 or similar RGB LED displays using Raspberry Pi GPIO
GNU General Public License v2.0
3.67k stars 1.17k forks source link

I can't use "graphics.DrawText" with "matrix.SetPixel()" without parasite #1269

Closed XomaFR closed 3 years ago

XomaFR commented 3 years ago

Sorry for my english ^^', My matrix (64x32) is controlled by my raspberry pi4 and hat adafruit. I'm using rpi-rgb-led-matrix/bindings/python/samples/runtext.py to create Clock.py.


`#!/usr/bin/env python

-- coding: utf-8 --

Cette matrice affiche l'heure et la date en étant synchroniser avec la machine qui l'éxécute.

from samplebase import SampleBase from rgbmatrix import graphics, RGBMatrix, RGBMatrixOptions from datetime import datetime, timedelta import time

class Clock(SampleBase): def init(self, *args, *kwargs): super(Clock, self).init(args, **kwargs)

def run(self):
    offscreen_canvas = self.matrix.CreateFrameCanvas()
    font = graphics.Font()
    font.LoadFont("/home/pi/rgb/rpi-rgb-led-matrix/fonts/5x8.bdf")
    textColor = graphics.Color(255, 255, 0)
    pos = offscreen_canvas.width
    while True:
        offscreen_canvas.Clear()
        HMS=datetime.now() + timedelta(seconds=1)
        Heure = HMS.strftime('%H:%M:%S')
        Date=datetime.now().strftime('%d/%m/%Y')
        Jour=datetime.today()
        listejour=["Lun", "Mar", "Mer", "Jeu", "Ven", "Sam", "Dim"]
        Jour=listejour[Jour.weekday()]
        warning(59,26,True)
        graphics.DrawText(offscreen_canvas, font, 0, 6, textColor, Jour)
        graphics.DrawText(offscreen_canvas, font, 15, 6, textColor, Date)
        graphics.DrawText(offscreen_canvas, font, 0, 32, textColor, Heure)
        time.sleep(1)
        offscreen_canvas = self.matrix.SwapOnVSync(offscreen_canvas)

Main function

if name == "main": clock = Clock() if (not clock.process()): clock.print_help() `


Result: IMG_20210307_105938

I want to add warning symbol with function matrix.SetPixel(). But when i add "Configuration for the matrix" to define the function matrix. My screen display a parasite and the text flashes:


`#!/usr/bin/env python

-- coding: utf-8 --

Cette matrice affiche l'heure et la date en étant synchroniser avec la machine qui l'éxécute.

from samplebase import SampleBase from rgbmatrix import graphics, RGBMatrix, RGBMatrixOptions from datetime import datetime, timedelta import time

Configuration for the matrix

options = RGBMatrixOptions() options.rows = 32 options.cols = 64 options.gpio_slowdown = 4 options.parallel = 1 options.brightness = 70 options.hardware_mapping="adafruit-hat" matrix = RGBMatrix(options = options)

def warning(ax,ay,actif):

Le /_\ est en bas a droite par défault l'axe x représente l'horizon et l'axe la hauteur.

# matrix.SetPixel(X,Y,R,V,B)
matrix.SetPixel(2+ax,0+ay,255,0,0)
matrix.SetPixel(2+ax,1+ay,255,0,0)
matrix.SetPixel(1+ax,2+ay,255,0,0)
matrix.SetPixel(3+ax,2+ay,255,0,0)
matrix.SetPixel(1+ax,3+ay,255,0,0)
matrix.SetPixel(3+ax,3+ay,255,0,0)
matrix.SetPixel(0+ax,4+ay,255,0,0)
matrix.SetPixel(4+ax,4+ay,255,0,0)
matrix.SetPixel(0+ax,5+ay,255,0,0)
matrix.SetPixel(1+ax,5+ay,255,0,0)
matrix.SetPixel(2+ax,5+ay,255,0,0)
matrix.SetPixel(3+ax,5+ay,255,0,0)
matrix.SetPixel(4+ax,5+ay,255,0,0)

class Clock(SampleBase): def init(self, *args, *kwargs): super(Clock, self).init(args, **kwargs)

def run(self):
    offscreen_canvas = self.matrix.CreateFrameCanvas()
    font = graphics.Font()
    font.LoadFont("/home/pi/rgb/rpi-rgb-led-matrix/fonts/5x8.bdf")
    textColor = graphics.Color(255, 255, 0)
    pos = offscreen_canvas.width
    while True:
        offscreen_canvas.Clear()
        HMS=datetime.now() + timedelta(seconds=1)
        Heure = HMS.strftime('%H:%M:%S')
        Date=datetime.now().strftime('%d/%m/%Y')
        Jour=datetime.today()
        listejour=["Lun", "Mar", "Mer", "Jeu", "Ven", "Sam", "Dim"]
        Jour=listejour[Jour.weekday()]
        warning(59,26,True)
        graphics.DrawText(offscreen_canvas, font, 0, 6, textColor, Jour)
        graphics.DrawText(offscreen_canvas, font, 15, 6, textColor, Date)
        graphics.DrawText(offscreen_canvas, font, 0, 32, textColor, Heure)
        time.sleep(1)
        offscreen_canvas = self.matrix.SwapOnVSync(offscreen_canvas)

Main function

if name == "main": clock = Clock() if (not clock.process()): clock.print_help() print(date)`


1615111809398

the symbol: image

So i don't understand how configure to use graphic with setpixel. Thank for your help and good day :)

XomaFR commented 3 years ago

This problem is solve i have replace matrix.setPixel by graphics.DrawLine