{"id":15076,"date":"2020-07-05T10:42:18","date_gmt":"2020-07-05T08:42:18","guid":{"rendered":"http:\/\/blog.wenzlaff.de\/?p=15076"},"modified":"2023-08-10T20:22:25","modified_gmt":"2023-08-10T18:22:25","slug":"8x8-led-mit-max7219-auf-einen-raspberry-pi-mit-python-sagt-freut-euch-allezeit","status":"publish","type":"post","link":"http:\/\/blog.wenzlaff.de\/?p=15076","title":{"rendered":"8&#215;8 LED mit max7219 auf einen Raspberry Pi mit python sagt &#8222;Freut euch allezeit&#8220;"},"content":{"rendered":"<p>Hatte noch eine  8&#215;8 LED mit Treiber liegen. Die wollte ich mal an den Raspberry Pi anklemmen und \u00fcber die Kommandozeile ansteuern.<\/p>\n<div style=\"width: 406px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-15076-1\" width=\"406\" height=\"720\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2020\/07\/freut-euch-allezeit.mp4?_=1\" \/><a href=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2020\/07\/freut-euch-allezeit.mp4\">http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2020\/07\/freut-euch-allezeit.mp4<\/a><\/video><\/div>\n<p>Die Hardware ist mit 5 Dr\u00e4hten schnell verbunden:<\/p>\n<pre>\r\nrot    - vcc - +5 V  -> PIN 2\r\nsw     - gnd         -> PIN 6\r\nbraun  - vin         -> PIN 19\r\nws     - cs          -> PIN 24\r\ngr     - clk         -> PIN 23\r\n<\/pre>\n<p>Verwendet habe ich den <a href=\"https:\/\/luma-led-matrix.readthedocs.io\/en\/latest\/install.html#\" rel=\"noopener noreferrer\" target=\"_blank\">Luma.LED_Matrix: Display drivers for MAX7219, WS2812, APA102<\/a>. Den Kommandozeilen Wrapper gab es noch nicht. Also dann mal los &#8230; Mal wieder etwas python3 programmieren &#8230;<!--more--><\/p>\n<pre class=\"lang:python decode:true \" >#!\/usr\/bin\/env python\r\n# -*- coding: utf-8 -*-\r\n# Commandline Wrapper\r\n# Thomas Wenzlaff\r\n# See LICENSE.rst for details.\r\n\r\nimport time\r\nimport argparse\r\n\r\nfrom luma.led_matrix.device import max7219\r\nfrom luma.core.interface.serial import spi, noop\r\nfrom luma.core.legacy import show_message\r\nfrom luma.core.legacy.font import proportional, CP437_FONT\r\n\r\n\r\ndef output(n, block_orientation, rotate, inreverse, text):\r\n    # create matrix device\r\n    serial = spi(port=0, device=0, gpio=noop())\r\n    device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation,\r\n                     rotate=rotate or 0, blocks_arranged_in_reverse_order=inreverse)\r\n    print(text)\r\n\r\n    show_message(device, text, fill=\"white\", font=proportional(CP437_FONT), scroll_delay=0.05)\r\n    time.sleep(1)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n    parser = argparse.ArgumentParser(description='view_message arguments',\r\n        formatter_class=argparse.ArgumentDefaultsHelpFormatter)\r\n\r\n    parser.add_argument('--cascaded', '-n', type=int, default=1, help='Number of cascaded MAX7219 LED matrices')\r\n    parser.add_argument('--block-orientation', type=int, default=0, choices=[0, 90, -90], help='Corrects block orientation when wired vertically')\r\n    parser.add_argument('--rotate', type=int, default=0, choices=[0, 1, 2, 3], help='Rotate display 0=0\u00b0, 1=90\u00b0, 2=180\u00b0, 3=270\u00b0')\r\n    parser.add_argument('--reverse-order', type=bool, default=False, help='Set to true if blocks are in reverse order')\r\n    parser.add_argument('--text', '-t', default='&gt;&gt;&gt; No text set', help='Set text message')\r\n    args = parser.parse_args()\r\n\r\n    try:\r\n        output(args.cascaded, args.block_orientation, args.rotate, args.reverse_order, args.text)\r\n    except KeyboardInterrupt:\r\n        pass<\/pre>\n<p>Das Script braucht dann nur mit dem Parameter -t oder &#8211;text aufgerufen werden:<\/p>\n<pre class=\"lang:python decode:true \" >python3 view_message.py -t \"          --  &gt; &gt;  Freut euch allezeit\"<\/pre>\n<p>Hier liegt mein <a href=\"https:\/\/github.com\/IT-Berater\/luma.led_matrix\" rel=\"noopener noreferrer\" target=\"_blank\">Fork<\/a> der pull request l\u00e4uft.<br \/>\nAlso dann &#8230;<br \/>\n<figure id=\"attachment_15088\" aria-describedby=\"caption-attachment-15088\" style=\"width: 2560px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2020\/07\/always-rejoice-scaled.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2020\/07\/always-rejoice-scaled.jpg\" alt=\"\" width=\"2560\" height=\"1919\" class=\"size-full wp-image-15088\" srcset=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2020\/07\/always-rejoice-scaled.jpg 2560w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2020\/07\/always-rejoice-300x225.jpg 300w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2020\/07\/always-rejoice-1024x768.jpg 1024w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2020\/07\/always-rejoice-768x576.jpg 768w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2020\/07\/always-rejoice-1536x1151.jpg 1536w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2020\/07\/always-rejoice-2048x1535.jpg 2048w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/a><figcaption id=\"caption-attachment-15088\" class=\"wp-caption-text\">always rejoice<\/figcaption><\/figure><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hatte noch eine 8&#215;8 LED mit Treiber liegen. Die wollte ich mal an den Raspberry Pi anklemmen und \u00fcber die Kommandozeile ansteuern. Die Hardware ist mit 5 Dr\u00e4hten schnell verbunden: rot &#8211; vcc &#8211; +5 V -> PIN 2 sw &#8211; gnd -> PIN 6 braun &#8211; vin -> PIN 19 ws &#8211; cs -> &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/blog.wenzlaff.de\/?p=15076\" class=\"more-link\"><span class=\"screen-reader-text\">\u201e8&#215;8 LED mit max7219 auf einen Raspberry Pi mit python sagt &#8222;Freut euch allezeit&#8220;\u201c <\/span>weiterlesen<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[220,2469,79,4023,1023,2752],"tags":[2927,4025,1332,565,4026,473,2340,4024,617],"class_list":["post-15076","post","type-post","status-publish","format-standard","hentry","category-anleitung","category-github-projekte","category-programmierung","category-python","category-raspberry-pi","category-raspberry-pi-zero-w","tag-2927","tag-ansteuerung-matrix","tag-device","tag-led","tag-max7219","tag-programm","tag-python","tag-sieben-segment","tag-treiber"],"_links":{"self":[{"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=\/wp\/v2\/posts\/15076","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=15076"}],"version-history":[{"count":0,"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=\/wp\/v2\/posts\/15076\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=15076"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=15076"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=15076"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}