Neuling steht auf dem "Schlauch"
Verfasst: Donnerstag 8. März 2018, 22:00
Hallo liebes Forum,
ich bin gerade dabei mich mit py auseinander zu setzen. Und ja, für das erste Projekt bräuchte ich noch viel mehr Kenntnis in Programmiersprachen.
Ziel ist es auf einer PunktMatrix 8x4 (max7219) Newsfeeds und CPU Temperatur, später noch Zeit usw. anzuzeigen. Ich möchte das Projekt mit meinen Kenntnissen in py ständig erweitern. Es liegt auch schon eine 32x32 RGB Matrix hier die nicht einstauben soll.
Nun mal zu meinem ersten Problem,
ich verstehe die While Schleife in meinem Script noch nicht. Es wird auf der Matrix einmalig ein neuer RSS-Feed ausgegeben und die aktuelle
CPU Temperatur der PI(2)
Nach dem ersten Durchlauf wird allerdings nur die CPU Temperatur neu eingelesen und ausgegeben. Der alte RSS-Feed bleibt bestehen und aktualisiert nicht.
hier mal der Script:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2017-18 Richard Hull and contributors
# See LICENSE.rst for details.
import feedparser
import re
import time
import argparse
import os
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
def getCPUtemperature():
res = os.popen("vcgencmd measure_temp").readline()
return(res.replace("temp="," ").replace("'C\n", ""))
# Function to fetch the rss feed and return the parsed RSS
def parseRSS( rss_url ):
return feedparser.parse(rss_url)
# Function grabs the rss feed headlines (titles) and returns them as a list
def getHeadlines( rss_url ):
headlines = []
feed = parseRSS (rss_url)
for newsitem in feed['items']:
headlines.append(newsitem['title'])
return headlines
allheadlines = []
newsurls = {
'apnews': 'http://hosted2.ap.org/atom/APDEFAULT/3d ... aa0db04305',
'googlenews': 'https://news.google.com/news/rss/?hl=en&ned=US&gl=US',
'news': 'http://rss.dw.com/xml/rss-de-news',
'yahoonews': 'http://news.yahoo.com/rss/'
}
for key,url in newsurls.items():
allheadlines.extend( getHeadlines( url))
for hl in allheadlines:
msgn = (hl)
def matrix(n, block_orientation, rotate):
serial = spi(port=0, device=0, gpio=noop())
device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation, rotate=rotate or 0)
print (msgn)
show_message(device, msgn, fill="white", font=proportional(CP437_FONT),scroll_delay=0.02)
time.sleep(1)
msgt = ("CPU Temp : " + getCPUtemperature() + "C")
print (msgt)
show_message(device, msgt, fill="white", font=proportional(CP437_FONT),scroll_delay=0.02)
time.sleep(1)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='matrix_demo arguments',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--cascaded', '-n', type=int, default=4, help='Number of cascaded MAX7219 LED matrices')
parser.add_argument('--block-orientation', type=int, default=-90, choices=[0, 90, -90], help='Corrects block orientation when wired vertically')
parser.add_argument('--rotate', type=int, default=0, choices=[0, 1, 2, 3], help='Rotate display 0=0°, 1=90°, 2=180°, 3=270°')
args = parser.parse_args()
try:
while True:
matrix(args.cascaded, args.block_orientation, args.rotate)
except (KeyboardInterrupt, BrokenPipeError):
pass
---------------------------------------------------------------------------------------------------------------------------------------------------------------
Ich denke ich müsste die while Schleife unterbrechen, aber leider enden meine Versuche meist mit Err oder funktionieren nicht.
Hoffe es kann mir einer hier mal auf die Sprünge helfen.
ich bin gerade dabei mich mit py auseinander zu setzen. Und ja, für das erste Projekt bräuchte ich noch viel mehr Kenntnis in Programmiersprachen.
Ziel ist es auf einer PunktMatrix 8x4 (max7219) Newsfeeds und CPU Temperatur, später noch Zeit usw. anzuzeigen. Ich möchte das Projekt mit meinen Kenntnissen in py ständig erweitern. Es liegt auch schon eine 32x32 RGB Matrix hier die nicht einstauben soll.
Nun mal zu meinem ersten Problem,
ich verstehe die While Schleife in meinem Script noch nicht. Es wird auf der Matrix einmalig ein neuer RSS-Feed ausgegeben und die aktuelle
CPU Temperatur der PI(2)
Nach dem ersten Durchlauf wird allerdings nur die CPU Temperatur neu eingelesen und ausgegeben. Der alte RSS-Feed bleibt bestehen und aktualisiert nicht.
hier mal der Script:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2017-18 Richard Hull and contributors
# See LICENSE.rst for details.
import feedparser
import re
import time
import argparse
import os
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
def getCPUtemperature():
res = os.popen("vcgencmd measure_temp").readline()
return(res.replace("temp="," ").replace("'C\n", ""))
# Function to fetch the rss feed and return the parsed RSS
def parseRSS( rss_url ):
return feedparser.parse(rss_url)
# Function grabs the rss feed headlines (titles) and returns them as a list
def getHeadlines( rss_url ):
headlines = []
feed = parseRSS (rss_url)
for newsitem in feed['items']:
headlines.append(newsitem['title'])
return headlines
allheadlines = []
newsurls = {
'apnews': 'http://hosted2.ap.org/atom/APDEFAULT/3d ... aa0db04305',
'googlenews': 'https://news.google.com/news/rss/?hl=en&ned=US&gl=US',
'news': 'http://rss.dw.com/xml/rss-de-news',
'yahoonews': 'http://news.yahoo.com/rss/'
}
for key,url in newsurls.items():
allheadlines.extend( getHeadlines( url))
for hl in allheadlines:
msgn = (hl)
def matrix(n, block_orientation, rotate):
serial = spi(port=0, device=0, gpio=noop())
device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation, rotate=rotate or 0)
print (msgn)
show_message(device, msgn, fill="white", font=proportional(CP437_FONT),scroll_delay=0.02)
time.sleep(1)
msgt = ("CPU Temp : " + getCPUtemperature() + "C")
print (msgt)
show_message(device, msgt, fill="white", font=proportional(CP437_FONT),scroll_delay=0.02)
time.sleep(1)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='matrix_demo arguments',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--cascaded', '-n', type=int, default=4, help='Number of cascaded MAX7219 LED matrices')
parser.add_argument('--block-orientation', type=int, default=-90, choices=[0, 90, -90], help='Corrects block orientation when wired vertically')
parser.add_argument('--rotate', type=int, default=0, choices=[0, 1, 2, 3], help='Rotate display 0=0°, 1=90°, 2=180°, 3=270°')
args = parser.parse_args()
try:
while True:
matrix(args.cascaded, args.block_orientation, args.rotate)
except (KeyboardInterrupt, BrokenPipeError):
pass
---------------------------------------------------------------------------------------------------------------------------------------------------------------
Ich denke ich müsste die while Schleife unterbrechen, aber leider enden meine Versuche meist mit Err oder funktionieren nicht.
Hoffe es kann mir einer hier mal auf die Sprünge helfen.