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.7k stars 1.17k forks source link

Send text via Command #815

Open Thor421 opened 5 years ago

Thor421 commented 5 years ago

Hello and thank you very much hzeller for your work!

As in this subject, https://github.com/hzeller/rpi-rgb-led-matrix/issues/678, I want to send a text via a simple command line.

Unfortunately, echo "TEST" | sudo ./text-example ... does not work Maybe a change has occurred in the bookstore this past year?

I specify that the matrix works very well by doing sudo ./text-example -f ../fonts/8x13.bdf Hello

Thank you for your help

Thor421 commented 5 years ago

small precision: this command line works but "TEST" remains 0.1 seconds in the matrix.

Thor421 commented 5 years ago

New precision : I use the fonction while from this topic : (while :; do cat Anzeige.txt ; sleep 0.2 ; done) | sudo ./text-example -f ../fonts/7x13.bdf --led-rows 16 --led-gpio-mapping=adafruit-hat --led-cols 64 -y 1 -C 255,0,0 But, I can not clear the matrix. With CTRL+C, I have some points that stay on. Is there a solution to clear all the matrice please ?

Thank you :)

angelogoncalve commented 5 years ago

Use matrix.Clear()

examples.zip

angelogoncalve commented 5 years ago

from rgbmatrix import RGBMatrix, RGBMatrixOptions, graphics import time

Configuration for the matrix

options = RGBMatrixOptions() options.rows = 16 options.cols = 64 options.chain_length = 1 options.parallel = 1 options.hardware_mapping = 'adafruit-hat'

matrix = RGBMatrix(options = options)

offscreen_canvas = matrix.CreateFrameCanvas() font = graphics.Font() font.LoadFont("../../../fonts/7x13.bdf") textColor = graphics.Color(255, 0, 0) my_text = "TEST"

len = graphics.DrawText(offscreen_canvas, font, pos, 10, textColor, my_text) time.sleep(5) offscreen_canvas.Clear()

Thor421 commented 5 years ago

Thank you angelogoncalve :) I adapted the code for my material but there is no display.

Can you help me please ?

from rgbmatrix import RGBMatrix, RGBMatrixOptions, graphics
import time
#Configuration for the matrix

options = RGBMatrixOptions()
options.rows = 16
options.cols = 32
options.chain_length = 2
options.parallel = 1
options.hardware_mapping = 'adafruit-hat'
options.multiplexing = 3
options.row_address_type = 2

matrix = RGBMatrix(options = options)

offscreen_canvas = matrix.CreateFrameCanvas()
font = graphics.Font()
font.LoadFont("../../../fonts/7x13.bdf")
textColor = graphics.Color(255, 255, 255)
pos = offscreen_canvas.width
my_text = "TEST"

len = graphics.DrawText(offscreen_canvas, font, pos, 10, textColor, my_text)
time.sleep(5)
offscreen_canvas.Clear()
Thor421 commented 5 years ago

I'm progressing slowly and I have a new problem to solve.

Can I use anything other than a CTRL-C to stop the display of text? I looked at SIGINT but I do not see how to adapt this function to python code.

Can you help me please ? Thank you !

Thor421 commented 5 years ago

Maybe his information will be useful.

1- I run: sudo ./text.py (it shows me a static text) 2- I wish to interrupt 1 3- To launch: sudo ./text2.py (it shows me a static text) I do not use a keyboard, only a box with pushbuttons mounted on an arduino card that communicates in bluetooth with the raspberry (a python file manages the reception of bluetooth data)

How to interrupt 1? I hope it's more understandable :)

hyamanieu commented 5 years ago

@Thor421 you need to import signal and os then do os.killpg(os.getpgid(pid_of_your_prog), signal.SIGTERM) you need to start your command from another python script to do that and have its PID saved. You can use p = subprocess.Popen(['python3','text.py], cwd=yourpath, preexec_fn=os.setsid) to do that, the pid is then p.pid.

angelogoncalve commented 5 years ago

you can use killing threads to clear the panel (stop RPi sending data to the display):

https://eli.thegreenplace.net/2011/12/27/python-threads-communication-and-stopping

https://www.geeksforgeeks.org/python-different-ways-to-kill-a-thread/

Thor421 commented 5 years ago

Thanks for your help hyamanieu and angelogoncalve :) I just coded the lines to kill the process from the PID

os.killpg(os.getpgid(pid), signal.SIGINT)

Now, I think I have to modify the samplebase.py file and especially this part to add this line, but how ?

        try:
            # Start loop
            print("Press CTRL-C to stop sample")
            self.run()
        except KeyboardInterrupt:
            print("Exiting\n")
sys.exit(0)

Thank you so much !

Thor421 commented 5 years ago

My problem : Python does not execute any command while a text is displayed on the matrix. The commands made (when I press the push button) while displaying the text (including os.killpg) are done after I have done CTRL + C.

Of course, if I manually call the python file to send the SIGINT signal, everything works.

Could you give me an additional indication to solve this problem please?

ser = serial.Serial('/dev/rfcomm0', 9600) // Connect to the bluetooth
while True:
    result = ser.read()
    print(result)               

         if result == 'f' :         

        os.system("sudo python ./30.py") // It's display the text of the matrice

         if result == '7' :         

        os.system("sudo python ./killprocess.py") // It's not execute because 30.py is launched