{"action":"created","issue":{"url":"https://api.github.com/repos/hzeller/rpi-rgb-led-matrix/issues/159","repository_url":"https://api.github.com/repos/hzeller/rpi-rgb-led-matrix","labels_url":"https://api.github.com/repos/hzeller/rpi-rgb-led-matrix/issues/159/labels{/name}","comments_url":"https://api.github.com/repos/hzeller/rpi-rgb-led-matrix/issues/159/comments","events_url":"https://api.github.com/repos/hzeller/rpi-rgb-led-matrix/issues/159/events","html_url":"https://github.com/hzeller/rpi-rgb-led-matrix/issues/159","id":160479110,"number":159,"title":"Python binding and performance.","user":{"login":"coulix","id":26057,"avatar_url":"https://avatars.githubusercontent.com/u/26057?v=3","gravatar_id":"","url":"https://api.github.com/users/coulix","html_url":"https://github.com/coulix","followers_url":"https://api.github.com/users/coulix/followers","following_url":"https://api.github.com/users/coulix/following{/other_user}","gists_url":"https://api.github.com/users/coulix/gists{/gist_id}","starred_url":"https://api.github.com/users/coulix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coulix/subscriptions","organizations_url":"https://api.github.com/users/coulix/orgs","repos_url":"https://api.github.com/users/coulix/repos","events_url":"https://api.github.com/users/coulix/events{/privacy}","received_events_url":"https://api.github.com/users/coulix/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":41,"created_at":"2016-06-15T17:28:10Z","updated_at":"2016-09-14T22:01:28Z","closed_at":null,"body":"Hello there,\r\n\r\nFirst, Great work! We can finally start playing with Led panels without much electronic knowledge.\r\n\r\nI love Python and did an experiment where I run random colors for each pixels as fast possible calling `SetPixel`.\r\n\r\n```python\r\nfrom rgbmatrix import RGBMatrix\r\n\r\n# 32 Rows, 1 panel.\r\nmatrix = RGBMatrix(32, 1)\r\n\r\n# Bits used for PWM. Something between 1..11. Default: 11\r\nmatrix.pwmBits = 11\r\n\r\n# Sets brightness level. Default: 100. Range: 1..100\"\r\nmatrix.brightness = 100\r\n\r\n# Buffer canvas.\r\noffsetCanvas = matrix.CreateFrameCanvas()\r\n\r\nfrom numpy import random\r\n\r\nimport time\r\n\r\ncolors = random.randint(255, size=(1024, 3))\r\n\r\nwhile True:\r\n    for x in range(0, 1024):\r\n        color = colors[random.randint(1024)]\r\n        offsetCanvas.SetPixel(x%32, x/32, color[0], color[1], color[2])\r\n\r\n    offsetCanvas = matrix.SwapOnVSync(offsetCanvas)\r\n```\r\n\r\nI get the expected output at low framerate ~2-3FPS.\r\n\r\nThen I tried the following C++ code (noob level).\r\n\r\n```C\r\n#include \"led-matrix.h\"\r\n#include \"graphics.h\"\r\n\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n#include <unistd.h>\r\n#include <iostream>\r\n\r\n\r\nusing namespace rgb_matrix;\r\n\r\nint colors[3072];\r\n\r\nint main(int argc, char *argv[]) {\r\n   // Random colors.\r\n   for (int j=0; j<3072; j++) {\r\n       int x = rand() % 255;\r\n       colors[j] = x;\r\n   }\r\n\r\n  //  Set up GPIO pins. This fails when not running as root.\r\n  GPIO io;\r\n  if (!io.Init())\r\n      return 1;\r\n\r\n  // Set up the RGBMatrix. It implements a 'Canvas' interface.\r\n  RGBMatrix *canvas = new RGBMatrix(&io, 32, 1, 1);\r\n\r\n  canvas->SetBrightness(100);\r\n  int width_ = canvas->width();\r\n  int height_ = canvas->height();\r\n\r\n  while(true) {\r\n      for (int x=0; x<width_; ++x) {\r\n          for (int y=0; y<height_; ++y) {\r\n             int i = rand() % 3070;\r\n             int r_ = colors[i];\r\n             int g_ = colors[i+1];\r\n             int b_ = colors[i+2];\r\n             canvas->SetPixel(x, y, r_, g_, b_);\r\n        }\r\n      }\r\n      usleep(16 * 1000); // ms\r\n  }\r\n  fprintf(stdout, \"Done\\n\");\r\n\r\n  // Finished. Shut down the RGB matrix.\r\n  canvas->Clear();\r\n  delete canvas;\r\n\r\n  return 0;\r\n}```\r\n\r\nAnd it is very fast.\r\n\r\nShould I give up on using Python to control LEDS in realtime?\r\nDid I miss something obvious?\r\n"},"comment":{"url":"https://api.github.com/repos/hzeller/rpi-rgb-led-matrix/issues/comments/247169789","html_url":"https://github.com/hzeller/rpi-rgb-led-matrix/issues/159#issuecomment-247169789","issue_url":"https://api.github.com/repos/hzeller/rpi-rgb-led-matrix/issues/159","id":247169789,"user":{"login":"Duality4Y","id":1276401,"avatar_url":"https://avatars.githubusercontent.com/u/1276401?v=3","gravatar_id":"","url":"https://api.github.com/users/Duality4Y","html_url":"https://github.com/Duality4Y","followers_url":"https://api.github.com/users/Duality4Y/followers","following_url":"https://api.github.com/users/Duality4Y/following{/other_user}","gists_url":"https://api.github.com/users/Duality4Y/gists{/gist_id}","starred_url":"https://api.github.com/users/Duality4Y/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Duality4Y/subscriptions","organizations_url":"https://api.github.com/users/Duality4Y/orgs","repos_url":"https://api.github.com/users/Duality4Y/repos","events_url":"https://api.github.com/users/Duality4Y/events{/privacy}","received_events_url":"https://api.github.com/users/Duality4Y/received_events","type":"User","site_admin":false},"created_at":"2016-09-14T22:01:28Z","updated_at":"2016-09-14T22:01:28Z","body":"yea it does indeed, but that is not hard to work around though. "}}
{"actor":{"display_login":"Duality4Y"}}