{"id":19999185,"url":"https://github.com/mr-addict/pi-pico-macropad","last_synced_at":"2025-08-31T05:33:42.129Z","repository":{"id":107624838,"uuid":"452315776","full_name":"MR-Addict/Pi-Pico-MacroPad","owner":"MR-Addict","description":null,"archived":false,"fork":false,"pushed_at":"2022-01-28T17:08:46.000Z","size":388,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-01T23:29:18.059Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MR-Addict.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2022-01-26T14:51:59.000Z","updated_at":"2024-01-03T02:23:05.000Z","dependencies_parsed_at":"2023-06-08T15:15:23.899Z","dependency_job_id":null,"html_url":"https://github.com/MR-Addict/Pi-Pico-MacroPad","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MR-Addict/Pi-Pico-MacroPad","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MR-Addict%2FPi-Pico-MacroPad","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MR-Addict%2FPi-Pico-MacroPad/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MR-Addict%2FPi-Pico-MacroPad/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MR-Addict%2FPi-Pico-MacroPad/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MR-Addict","download_url":"https://codeload.github.com/MR-Addict/Pi-Pico-MacroPad/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MR-Addict%2FPi-Pico-MacroPad/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272940940,"owners_count":25019004,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-31T02:00:09.071Z","response_time":79,"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":[],"created_at":"2024-11-13T05:10:58.662Z","updated_at":"2025-08-31T05:33:42.104Z","avatar_url":"https://github.com/MR-Addict.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"#  DIY Pi Pico MacroPad\n# 1. Description\nThis a DIY Pi Pico MacroPad based on C/C++ SDK.\n\nIf you like C/C++ development instead of MacroPython, you must have a look on my project.\n\n![Macropad schematic](images/MacroPad.jpg)\n\n# 2. Needed Components \u0026 Schematic\n- **Pi Pico Board** x1\n- **Rotary Encoder** x1\n- **Mechanical Key** x8\n- **Mini WS2812** x8\n- **DIY MacroPad board** x1\n\nYou can find Gerber in `pcb` folder.\n![Schematic](images/MacroPad.png)\n\n# 3.Drivers\nIn this projects, almost all of the components wee need to driver ourselves, thus it's a good chance to improve our skill on investigating and coding.\n\nNext, I gonna to talk about detailed process about how to drive them.\n\n## 3.1 Rotary Encoder \u0026 Mechanical Key\n\nThough it's mechanical Key, but it's just some buttons which are more nice and expensive. Here is an example.\n\n```cpp\nint main() {\n    Button button(11);\n    Encoder encoder(14, 15);\n    stdio_init_all();\n    int8_t count = 0;\n    while (true) {\n        int8_t encoder_dir = encoder.getDirection();\n        if (encoder_dir == 1) {\n            count++;\n            printf(\"%d,Encoder rotated CK!\\n\", count);\n        } else if (encoder_dir == -1) {\n            count--;\n            printf(\"%d,Encoder rotated CCK!\\n\", count);\n        }\n        if (button.isPressed()) {\n            count = 0;\n            printf(\"%d,Button Pressed!\\n\", count);\n        }\n    }\n    return 0;\n}\n```\n\nYou can find my library in `src/lib/Encoder` folder.\n\nNote that this folder contains both button and encoder code.\n\n## 3.2 WS2812\nDue to WS2812 is a timing sensitive component, so I use `PIO(Programmable Input/Ouput)` which Pi Pico features.\n\nI learned a lot about PIO and how to use, and search a lot information about how to drive WS2812.\n\nAnd I think it's really really not easy to use them. You can follow bellow articals and code examples.\n\n- [A closer look at Raspberry Pi RP2040 Programmable IOs (PIO) By Jadhav](https://www.cnx-software.com/2021/01/27/a-closer-look-at-raspberry-pi-rp2040-programmable-ios-pio/)\n\n- [Raspberry Pico: Programming with PIO State Machines By Sebastian](https://medium.com/geekculture/raspberry-pico-programming-with-pio-state-machines-e4610e6b0f29)\n\n- [Pi Pico Offical PIO example](https://github.com/raspberrypi/pico-examples/tree/master/pio/ws2812)\n\n- [ForsakenNGS PicoLED library for ws2812 LEDs](https://github.com/ForsakenNGS/PicoLED)\n\nAnd I suggest directily use my library or ForsakenNGS's library, that's would be an easy way. Just like below.\n\n```cpp\nRGB leds[LED_LENGTH];\nWS2812 LEDStrip(leds, LED_PIN, LED_LENGTH);\n```\n\nYou can find my library in `src/lib/WS2812` folder.\n\n## 3.3 TinyUSB\nWrite C/C++ to make hid interface come true would be a nightmare, but luckily `TinyUSB` support RP2040, and there's an offical example in pico-sdk examples.\n\nYou can have a look here [Pi Pico Offical TinyUSB example](https://github.com/raspberrypi/pico-examples/tree/master/usb/device/dev_hid_composite).\n\nBut it's easy to use TinyUSB, you just need to initilize by calling two fuctions, call `tud_task()` all the time and use `tud_hid_keyboard_report()` to report keyboard event to your host like below.\n\n```cpp\nvoid hid_task(void) {\n    if (tud_hid_ready()) {\n        if (button.isPressed()) {\n            uint8_t keycode[6] = {0};\n            keycode[0] = HID_KEY_A;\n            tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, keycode);\n        } else\n            tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, NULL);\n    }\n}\n\nint main(void) {\n    board_init();\n    tusb_init();\n    while (true) {\n        tud_task();\n        hid_task();\n    }\n    return 0;\n}\n```\n\nAnd you can find it in my `src/lib/tinyusb` folder.\n\n## 3.4 FreeRTOS\nUsing FreeRTOS, you can manage multi tasks and similarily run them at the same time.\n\nYou can creat a task like this and even more tasks.\n\n```cpp\nvoid led_task(void* parameter) {\n    while (true) {\n        LEDStrip.fillSolid(CHSV(colorIndex++, 255, 255));\n        LEDStrip.show();\n        vTaskDelay(100 / portTICK_PERIOD_MS);\n    }\n}\n\nint main(){\n    xTaskCreate(led_task, \"led_task\", 128, NULL, 1, NULL);\n    vTaskStartScheduler();\n    return 0;\n}\n```\n\nBut you are not necessarily to use FreeRTOS in your project, if you are interested in how to setup FreeRTOS on raspberry pi pico, you can go to my another project [FreeRTOS on Raspberry Pi Pico](https://github.com/MR-Addict/FreeRTOS-on-Raspberry-Pi-Pico).\n\n## 3.5 Custom Your MacroPad Key\nI custom 8 keys on my macropad, and you can change it in `buttonkey` arrey.\n\n``` cpp\nuint8_t buttonkey[LED_LENGTH] = {\n    HID_KEY_S,      HID_KEY_Z,  \n    HID_KEY_C,      HID_KEY_X,      HID_KEY_V,  \n    HID_KEY_HOME,   HID_KEY_DELETE, HID_KEY_END\n};\n```\n\nThat's all.Happy kacking!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmr-addict%2Fpi-pico-macropad","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmr-addict%2Fpi-pico-macropad","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmr-addict%2Fpi-pico-macropad/lists"}