Printing on LED matrix

I am new to coding and definitely new to coding an LED matrix. I have a python script that calls the price of a stock every ten seconds. I am trying to figure out 1. how to simply print something simple like a simple number on the matrix and 2. how to build a python script on a raspberry pi.

I feel like printing a data point on the matrix should be simple, but I have yet to figure it out. If anyone has a knowledge on how to help, it would be much appreciated.

Hi, I also want to display a python variable on my LED matrix display, have you managed to make any progress with this issue? I was hoping to edit the sample runtext.py but no luck so far.

Hi guys,

I’ve made a quick example for you.
This script simply displays a text read from a text file.
You have to change MATRIX CONFIG values to be yours and then run it like that :

sudo /usr/bin/python /home/pi/rpi-rgb-led-matrix/print_txt.py

Tell me if it work for you and if not tell me why i’ll do my best to help you.

#!/usr/bin/python
# SIMPLE TEXT DISPLAY FROM TEXT FILE
# Autor : A.HALET


import time
import sys
import os

from rgbmatrix import RGBMatrix, RGBMatrixOptions, graphics
from os import path


#============================================
#            MATRIX CONFIG
#============================================
options = RGBMatrixOptions()
options.rows = 16
options.cols = 32
options.chain_length = 6
options.parallel = 2
options.brightness = 50
options.multiplexing = 7
options.row_address_type = 2
options.pixel_mapper_config = "V-mapper;Rotate:-90"
options.disable_hardware_pulsing = 1
options.hardware_mapping = 'regular'
matrix = RGBMatrix(options = options)

#============================================
#            TEXT CONFIG
#============================================
offscreen_canvas = matrix.CreateFrameCanvas()
font = graphics.Font()
font.LoadFont("rpi-rgb-led-matrix/fonts/7x14.bdf")
pos = matrix.height

try:
    print("Press CTRL-C to stop.")

except KeyboardInterrupt:
    offscreen_canvas.Clear()
    matrix.Clear()
    sys.exit(0)
    

#============================================
#                MAIN LOOP
#============================================
while True: 
#============================================
#                  INIT
#============================================
    matrix.Clear()
    offscreen_canvas.Clear()

    pos_x=0
    pos_y=font.height
    color_R=255
    color_G=255
    color_B=255
    
#============================================
#            READ TEXT FILE
#============================================
    if(path.exists('/home/pi/rpi-rgb-led-matrix/toprint.txt')):                
        with open('/home/pi/rpi-rgb-led-matrix/toprint.txt', 'r') as file:
            content = file.readlines()
            txt_to_print=content[0].decode('utf8')
            file.close()                                                          
    else :
        txt_to_print="File doesn't exist"

    while True:
#============================================
#            DISPLAY TEXT
#============================================
        len_pic = graphics.DrawText(offscreen_canvas, font,pos_x, pos_y,graphics.Color(color_R,color_G,color_B),txt_to_print)
        pos -= 1
        if (pos + len_pic < 0):
            pos = offscreen_canvas.width
        time.sleep(0.01)
        offscreen_canvas = matrix.SwapOnVSync(offscreen_canvas)

Thanks Axel for your example, it looks promising. I will let you know what results I get.