question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hello. Help with the Russian coding in the running line Raspberry PI3 Max7219 8x8x4 pi@raspberrypi:~ $ uname -a Linux raspberrypi 4.9.78-v7+ #1084 SMP Thu Jan 25 18:05:49 GMT 2018 armv7l GNU/Linux pi@raspberrypi:~ $

> #!/usr/bin/env python 
> # -*- coding: utf-8 -*- 
> # Copyright (c) 2017-18 Richard Hull and contributors 
> # See LICENSE.rst for details. 
> 
> import re
> import sys
> import datetime
> import time
> import argparse
> 
> from luma.led_matrix.device import max7219
> from luma.core.interface.serial import spi, noop
> from luma.core.render import canvas
> from luma.core.virtual import viewport
> from luma.core.legacy import text, show_message
> from luma.core.legacy.font import proportional, CP437_FONT, TINY_FONT, SINCLAIR_FONT, LCD_FONT
> 
> serial = spi(port=0, device=0, gpio=noop())
> device = max7219(serial, cascaded=4, block_orientation=-90)
> 
> while(True):
> 	msg = "Всем привет!!!"
>         show_message(device, msg, fill="white", font=proportional(SINCLAIR_FONT))
>         time.sleep(1)
> 
> for offset in range(8):
>     virtual.set_position((offset, offset))

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tarasiuscommented, Jan 29, 2018

@viktor6 This is my solution. To avoid concurrent messages, I made a daemon, which receives commands what to show with a pipe message. I use it with online radio, showing the station, artist and song. Here is daemon code:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
logging.basicConfig(format='%(asctime)s %(message)s') #,filename='LedSay')
log = logging.getLogger()
log.setLevel(logging.DEBUG)

import os, time, sys
import multiprocessing
from tendo import singleton
from luma.led_matrix.device import max7219
from luma.core.interface.serial import spi, noop
from luma.core.render import canvas
from luma.core.legacy import text, show_message
from luma.core.legacy.font import LCD_FONT, proportional
#CP437_FONT, TINY_FONT, SINCLAIR_FONT,

def say(msg, delay, intensity, orientation):
    # create matrix device
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, cascaded=1, block_orientation=0, rotate=orientation)    
    device.contrast(intensity * 16)

    # font=proportional(SINCLAIR_FONT)
    show_message(device, msg, fill="white", font=proportional(LCD_FONT), scroll_delay=delay)

if __name__ == "__main__":
	me = singleton.SingleInstance() # will sys.exit(-1) if other instance is running
	
	PipeName = '/LedsButtons/LedSayPipe'
	if not os.path.exists(PipeName):
		log.debug('Pipe not present. Creating.')
		os.mkfifo(PipeName, 0777)
		log.debug('Pipe is made')
	else:
		log.debug('Pipe already present')
		
	p = multiprocessing.Process(target=say, args=('Hello',0.1,1,3))
	p.start()
	
	log.debug('Open pipe for reading')
	PipeIn = open(PipeName, 'r')
	log.debug('Pipe is open for reading')

	while True:
		try:
			PipeString = PipeIn.readline() [:-1]
			if (len(PipeString)>0):
				log.info('LedSay '+PipeString)				
				if (p.is_alive()):
					log.debug('Terminating')
					p.terminate()
					p.join()
					del p
				d,i,o,m = PipeString.split('#')	
				log.debug('d='+d+' i='+i+' o='+o+' m='+m)				
				p = multiprocessing.Process(target=say, args=(m,float(d),int(i),int(o)))
				p.start()
				log.debug('Started')
		except:
			log.debug('Cant read Pipe')
		

And here is the script which communicates with daemon:

#!/usr/bin/env python
import logging
logging.basicConfig(format='%(asctime)s %(message)s') 
log = logging.getLogger()
log.setLevel(logging.DEBUG)

import os, time, sys
import argparse
import threading

def run(message, orientation, delay, intensity):
	PipeName = '/LedsButtons/LedSayPipe'
	if not os.path.exists(PipeName):
		log.debug('Pipe not present. Creating.')
		os.mkfifo(PipeName, 0777)
	
	PipeOut = open(PipeName, 'w')	
	DataPipeString = str(delay)+'#'+str(intensity)+'#'+str(orientation)+'#'+message+'\n'
	log.info(DataPipeString)
	PipeOut.write(DataPipeString)
	PipeOut.close	
	
def background(message, orientation, delay, intensity):
  led_thread = threading.Thread(target=run, args=[message, orientation, delay, intensity])
  led_thread.start()

	
if __name__ == "__main__":
	parser = argparse.ArgumentParser(description='ledsay arguments',
		formatter_class=argparse.ArgumentDefaultsHelpFormatter)

	parser.add_argument('message',metavar='m', help='Phrase to scroll on MAX7219 LED matrix')
	parser.add_argument('orientation', metavar='o',type=int, default=1, help='Block orientation')
	parser.add_argument('delay', metavar='d',type=float, default=1.0, help='Scroll delay')
	parser.add_argument('intensity', metavar='i', type=int, default=1, choices=range(1,16), help='Screen intensity')

	args = parser.parse_args()

	run(args.message, args.orientation, args.delay, args.intensity)

	
0reactions
tarasiuscommented, Jan 30, 2018

@thijstriemstra This is a way to protect the script from running more than once in the same time. https://pythonhosted.org/tendo/ I had some problem when daemon script was started more than once. Or for the case daemon started the script, and user starts it once again manually.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Russian Keyboard Online • Cyrillic Alphabet • LEXILOGOS
Online keyboard to type a text with the Cyrillic characters of the Russian alphabet.
Read more >
Texts with audio - Learn Russian for Free
Texts in Russian to read and practice your language skills. These reading exercises come with audio recordings to help you learn new words....
Read more >
Type Russian letters – online Russian keyboard
Simple, no-nonsense online Russian keyboard with an easy-to-learn QWERTY layout. Type Russian letters in the box, then copy your text wherever you want....
Read more >
Russian Reading: Russian Texts for Beginners - Lingua.com
Lingua.com has Russian texts with audio and exercises so that you can practice and improve your reading comprehension of this language. 18 free...
Read more >
Russian/English Parallel Texts Index
The following articles are parallel texts presented in Russian and English. Each text contains audio in Russian. They are designed to help you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found