{"id":250,"date":"2018-01-14T12:15:53","date_gmt":"2018-01-14T12:15:53","guid":{"rendered":"https:\/\/www.root42.de\/blog\/?p=250"},"modified":"2018-01-14T12:15:53","modified_gmt":"2018-01-14T12:15:53","slug":"rgb-led-matrix-with-the-raspberry-pi","status":"publish","type":"post","link":"https:\/\/www.root42.de\/blog\/?p=250","title":{"rendered":"RGB LED Matrix with the Raspberry Pi"},"content":{"rendered":"<p>Here I show how to attach a WS2812 based LED strip or matrix to the Raspberry Pi.<\/p>\n<p><iframe loading=\"lazy\" width=\"840\" height=\"473\" src=\"https:\/\/www.youtube.com\/embed\/csw5YyiPuXE?feature=oembed\" frameborder=\"0\" allow=\"autoplay; encrypted-media\" allowfullscreen><\/iframe><\/p>\n<p>Short introduction on how to actually install the <a href=\"https:\/\/github.com\/jgarff\/rpi_ws281x\">rpi_ws218x<\/a> library on the Pi:<\/p>\n<ol>\n<li style=\"list-style-type: none\">\n<ol>\n<li>Install build essentials:\n<pre><span class=\"pln\">sudo apt<\/span><span class=\"pun\">-<\/span><span class=\"kwd\">get<\/span><span class=\"pln\"> update &amp;&amp; <\/span><span class=\"pln\">sudo apt<\/span><span class=\"pun\">-<\/span><span class=\"kwd\">get<\/span><span class=\"pln\"> install build<\/span><span class=\"pun\">-<\/span><span class=\"pln\">essential python<\/span><span class=\"pun\">-<\/span><span class=\"pln\">dev git scons swig<\/span><\/pre>\n<\/li>\n<li>Clone the repository and build the library:\n<pre><span class=\"pln\">git clone https<\/span><span class=\"pun\">:<\/span><span class=\"com\">\/\/github.com\/jgarff\/rpi_ws281x.git\r\n<\/span><span class=\"pln\">cd rpi_ws281x\r\n<\/span><span class=\"pln\">scons<\/span><\/pre>\n<\/li>\n<li>Compile and install the Python library:\n<pre><span class=\"pln\">cd python\u00a0\r\n<\/span><span class=\"pln\">sudo python setup<\/span><span class=\"pun\">.<\/span><span class=\"pln\">py install<\/span><\/pre>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>Also, I have written this small example program, large parts were taken from the supplied example programs in the repository:<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n#!\/usr\/bin\/env python\r\nimport time\r\nimport math\r\nimport colorsys\r\nfrom neopixel import *\r\n\r\n# LED strip configuration:\r\nLED_COUNT = 64      # Number of LED pixels.\r\nLED_PIN = 18      # GPIO pin connected to the pixels (must support PWM!).\r\nLED_FREQ_HZ = 800000  # LED signal frequency in hertz (usually 800khz)\r\nLED_DMA = 10       # DMA channel to use for generating signal (try 10)\r\nLED_BRIGHTNESS = 255  # Set to 0 for darkest and 255 for brightest\r\n# True to invert the signal (when using NPN transistor level shift)\r\nLED_INVERT = False\r\n\r\ndef plasma (w, h, t):\r\n    out = &#x5B; Color( 0, 0, 0 ) for x in range( w * h ) ]\r\n    for x in range( w ):\r\n        for y in range( h ):\r\n            hue = 4.0 + math.sin( t + x ) + math.sin( t + y \/ 4.5 ) \\\r\n                + math.sin( x + y + t ) + math.sin( math.sqrt( ( x + t ) ** 2.0 + ( y + 1.5 * t ) ** 2.0 ) \/ 4.0 )\r\n            hsv = colorsys.hsv_to_rgb( hue \/ 8.0, 1, 1 )\r\n            out&#x5B; x + y * w ] = Color( *&#x5B; int( round( c * 10.0 ) ) for c in hsv ] )\r\n    return out\r\n\r\n# Main program logic follows:\r\nif __name__ == '__main__':\r\n    # Create NeoPixel object with appropriate configuration.\r\n    strip = Adafruit_NeoPixel(\r\n        LED_COUNT,\r\n        LED_PIN,\r\n        LED_FREQ_HZ,\r\n        LED_DMA,\r\n        LED_INVERT,\r\n        LED_BRIGHTNESS\r\n    )\r\n    # Intialize the library (must be called once before other functions).\r\n    strip.begin()\r\n\r\n    t = 0.0                                                                       # time\r\n    dt = 0.1                                                                      # speed of time\r\n\r\n    for i in range( 0, strip.numPixels(), 1):                                     # iterate over all LEDs\r\n        strip.setPixelColor( i, Color( 0, 0, 0 ) )                                # set LED to black (off)\r\n\r\n    while True:\r\n        t = t + dt                                                                # increment time\r\n        pic = plasma( 8, 8, t )                                                   # render plasma of size 8x8 at time t\r\n\r\n        for i in range( 0, strip.numPixels(), 1 ):                                # iterate over all LEDs\r\n            strip.setPixelColor(                                                  # set pixel to color in picture\r\n                i,\r\n                pic&#x5B; i ]\r\n            )\r\n        strip.show()                                                              # update LEDs\r\n        time.sleep(0.001)                                                         # white a short while before loop\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here I show how to attach a WS2812 based LED strip or matrix to the Raspberry Pi. Short introduction on how to actually install the rpi_ws218x library on the Pi: Install build essentials: sudo apt-get update &amp;&amp; sudo apt-get install build-essential python-dev git scons swig Clone the repository and build the library: git clone https:\/\/github.com\/jgarff\/rpi_ws281x.git &hellip; <a href=\"https:\/\/www.root42.de\/blog\/?p=250\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;RGB LED Matrix with the Raspberry Pi&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[119,118,112,120,117],"_links":{"self":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/250"}],"collection":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=250"}],"version-history":[{"count":2,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/250\/revisions"}],"predecessor-version":[{"id":252,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/250\/revisions\/252"}],"wp:attachment":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}