{"id":15290596,"url":"https://github.com/mayhem/smi_leds","last_synced_at":"2026-03-06T02:46:59.484Z","repository":{"id":237708557,"uuid":"795097811","full_name":"mayhem/smi_leds","owner":"mayhem","description":"C/C++/Python module to drive up to 8 or 16 WS2812b LED strips with a single Raspberry Pi","archived":false,"fork":false,"pushed_at":"2024-12-29T19:48:02.000Z","size":134,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-27T20:20:34.850Z","etag":null,"topics":["c","python","raspberry-pi","ws2812b"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mayhem.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-05-02T15:22:48.000Z","updated_at":"2025-11-12T21:53:14.000Z","dependencies_parsed_at":"2024-05-07T16:30:35.722Z","dependency_job_id":"621c82de-3e39-4f6f-bb48-a06d399323b7","html_url":"https://github.com/mayhem/smi_leds","commit_stats":null,"previous_names":["mayhem/rpi_smi_led","mayhem/smi_leds"],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/mayhem/smi_leds","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mayhem%2Fsmi_leds","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mayhem%2Fsmi_leds/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mayhem%2Fsmi_leds/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mayhem%2Fsmi_leds/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mayhem","download_url":"https://codeload.github.com/mayhem/smi_leds/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mayhem%2Fsmi_leds/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30159969,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-05T22:39:40.138Z","status":"online","status_checked_at":"2026-03-06T02:00:08.268Z","response_time":250,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","python","raspberry-pi","ws2812b"],"created_at":"2024-09-30T16:08:44.270Z","updated_at":"2026-03-06T02:46:59.437Z","avatar_url":"https://github.com/mayhem.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SMI LEDs\n\nThis project allows you to drive 8 or 16 WS2812 LED strips with one single Raspberry Pi!\n\nThe basis for this project is Jeremy P Bentham's [rpi_smi_leds](https://github.com/jbentham/rpi/tree/master)\nproject that uses the RPi's SMI memory interface to accurately drive 8 or 16 LED strips -- flicker free and without\na lot of CPU overhead -- simply amazing. For all the gory details on how this works,\nread Jeremy's excellent blog post about his code:\n\n    https://iosoft.blog/category/neopixel/\n\nHowever, Jeremy's code was just that -- some code, but with zero documentaion on how to\nbuild it (several fixes were needed) or how to install it on a RPi. This project \naddresses those shortcomings and packages that code into a deployable project.\n\nYou can choose to link to a static C library build with CMake and include it in your\nC/C++ project, or you can choose the python module, which can be installed from pip.\n\nIMPORTANT: This code does not run on a Raspberry Pi 5!\n\n## Design philosophy\n\nThis module is for advanced users of LED strips and thus it may be missing some of the \nfeatures you'd expect in other modules (e.g. setting indiviual LED values). For the\nmoment, this module assumes that you are an advanced user of LEDs and thus likely\nalready have some tools around creating LED sequences in your toolkit. \n\nThe only way to update the leds is via the led_set() function which takes a buffer\nof bytes exactly NUM_STRIPS * NUM_LEDS * 3 in size with LED data and sends it to the \ndriver. The led_send() function actually shifts the LEDs out to the LED strips.\n\nThere is some code in the driver for setting indiviual pixels, but it wasn't working,\nso I've not exposed that function. But if people want that, someone should be able to\nmake it work.\n\n## RGB data structure\n\nFor this setup, it is assumed that you have 8 or 16 equally sized LED strips.\n\nEach time you call led_set, MUST send the same number of bytes:\n\n* 8 * num_leds * num_strips * 3 bytes for an 8 strip setup\n* 16 * num_leds * num_strips * 3 bytes for a 16 strip setup\n\nIf you have LED strips with differing lengths, set num_leds to the length of your\nlongest LED strip. Then, for all strips that are shorter than the maximum length\npad the RGB with zeros, so that you're always sending the same number of bytes\nfor each of your strips. The extra zeros will be ignored by the shorter strips.\n\nIf you have fewer than 8 or 16 LED strips: Pad the RGB data sent to the strips\nout to 8 (or 16) strips. If you have 4 strips, send 4 strips of data and then\n4 strips of zeros for a 8 strip setup.\n\n\n# Installation\n\n## OS Choice\n\nCurrently this code only works on a 32 bit Raspberry Pi OS images. 64 bit images are\ncurrently not supported, but I'll see about getting those working as well.\n\n## Raspberry Pi Setup\n\nIn order for the smi_leds to work, the i2s system that is used to provide audio\non the RPi must be disabled. The easiest way to do this is to edit \n/boot/firmware/config.txt (previously used to be /boot/config.txt) and\nto change the line:\n\n```\n#dtparam=i2s=on\n```\n\nto\n\n```\ndtparam=i2s=off\n\n```\n\nDon't forget to uncomment the line. Once you've made this change, reboot your\nRPi.\n\n## Prerequisites\n\nTo install this library, you'll need to have the following packages installed:\n\n* python-dev-is-python3: Python dev headers, formerly python3-dev\n* cmake\n\nOn a recent RPi install, this line should work:\n\n```\nsudo apt install -y build-essential python-dev-is-python3 cmake\n```\n\n## Install the C/C++ static library\n\n## Prerequisites\n\nTo install this library, you'll need to have the following packages installed:\n\n* cmake\n* build-essential\n\n```\napt install -y build-essential cmake\n```\n\n## Installation\n\nTo install smi_leds for 8 LED strands:\n\n```\nmkdir build\ncd build\ncmake ..\nmake\nsudo make install\n```\n\nTo install for 16 channels, pass an option to cmake:\n\n```\nmkdir build\ncd build\ncmake .. -DENABLE_16_CHANNELS:BOOL=ON\nmake\nsudo make install\n```\n\n### Building your own code\n\nTo build your own code, run:\n\n```\ngcc -I /usr/local/include -L /usr/local/lib my_test.c -lsmi_leds\n```\n\n## Install Python 3 module\n\n## Prerequisites\n\nTo install this library, you'll need to have the following packages installed:\n\n* python-dev-is-python3: Python dev headers, formerly python3-dev\n* cmake\n* build-essential\n\n```\nsudo apt install -y build-essential python-dev-is-python3 cmake\n```\n\n## Installation\n\nTo install via pip for 8 LED strands:\n\n```\npip install smileds\n```\n\nTo install via pip for 16 LED strands:\n\n```\nexport LED_NCHANS=16\npip install smileds\n```\n\n# Hardware Setup\n\nThe image below shows the GPIO pins that will drive the LED strips:\n\n![alt text](https://github.com/mayhem/smi_leds/blob/main/docs/rpi_smi_pinout.png?raw=true)\n\nRemember that each one of these outputs will likely need to be level-shifted to 5V\n(unless your LED strips are 3.3V tolerant) and have a 300 Ohm resisor in-line if you'd like\nto follow best practices.\n\nHere is the same information in a more convenient table:\n\n![alt text](https://github.com/mayhem/smi_leds/blob/main/docs/rpi_smi_pins-2.png?raw=true)\n\nSD0 through SD17 are the GPIOs that will drive your LED strips.\n\n# Software Setup\n\n## C\n\nThe full example in examples/example.c. This fragment sets all the LEDs to\nwhite at 25% brightness:\n\n```\n    // Allocate a buffer, set it to all 0xFF (white)\n    uint8_t buffer[NUM_LEDS * NUM_STRIPS * 3];\n    memset(buffer, 0xFF, NUM_LEDS * NUM_STRIPS * 3);\n\n    // initialize the smi_leds module, starting with a 25% brightness\n    leds_init(NUM_LEDS, 25);\n    \n    // Transfer our local buffer to the SMI buffer\n    leds_set(buffer);\n\n    // Shift the SMI buffer out to the LEDs\n    leds_send();\n```\n\n## Python 3\n\nThe python version is quite similar:\n\n```\nimport smileds\nfrom time import sleep\n\nnum_leds = 25\nnum_strips = 1\n\n# initialize the smi_leds module, starting with a 25% brightness\nsmileds.leds_init(num_leds, 25)\n\n# Build the LED data array\nleds = bytearray()\nfor strip in range(num_strips):\n    for led in range(num_leds):\n        leds += bytearray((255, 0, 255))\n\n# Set the buffer into to the smileds module\nsmileds.leds_set(leds)\n\n# Shift them out to the strips\nsmileds.leds_send()\n\n# Wait while the data is shifted to the SMI bus\nsleep(1)\n```\n\nThis code snipped will turn 25 leds purple on 1 strip at brightness 25%.\n\n# Troubleshooting\n\nA common problem might be getting a segmentation fault when calling leds_set(), which is caused by sending in the\nwrong buffer size for the current number of strip configuration. If you setup smi_leds with 8 strips, you need to\npass in a buffer to the C functions that is at least 3 * 8 * NUM_LEDs large.\n\n# Demo video\n\nHere is a super short demonstration video for this module in action:\n\n[![smi_leds demo video](https://img.youtube.com/vi/Yu0YikcP2a4/0.jpg)](https://www.youtube.com/watch?v=Yu0YikcP2a4)\n\n# Future work\n\nThis module could use various improvements over time if people are interesting in developing it further:\n\n* Consider adding gamma correction\n* Debug the set_pixel() function to allow changing single pixels\n\nAlso, if someone else would like to take over the development of this module, I would be\nhappy to pass it on.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmayhem%2Fsmi_leds","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmayhem%2Fsmi_leds","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmayhem%2Fsmi_leds/lists"}