{"id":14978134,"url":"https://github.com/wallysalami/tkgpio","last_synced_at":"2025-04-04T23:06:48.152Z","repository":{"id":44960053,"uuid":"294493999","full_name":"wallysalami/tkgpio","owner":"wallysalami","description":"A Python library to simulate electronic devices connected to the GPIO on a Raspberry Pi, using TkInter.","archived":false,"fork":false,"pushed_at":"2025-03-13T19:49:11.000Z","size":126,"stargazers_count":94,"open_issues_count":6,"forks_count":19,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-03-28T22:11:28.392Z","etag":null,"topics":["education","python","raspberry-pi","tkinter"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wallysalami.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":"wallysalami","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2020-09-10T18:42:56.000Z","updated_at":"2025-03-13T19:49:15.000Z","dependencies_parsed_at":"2025-03-28T22:11:23.524Z","dependency_job_id":"79f78619-c9e1-4428-9cc6-53e69558b1d2","html_url":"https://github.com/wallysalami/tkgpio","commit_stats":{"total_commits":37,"total_committers":5,"mean_commits":7.4,"dds":"0.43243243243243246","last_synced_commit":"a19802f45004bbee1053fa48783b39e2c000e851"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wallysalami%2Ftkgpio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wallysalami%2Ftkgpio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wallysalami%2Ftkgpio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wallysalami%2Ftkgpio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wallysalami","download_url":"https://codeload.github.com/wallysalami/tkgpio/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247261600,"owners_count":20910108,"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","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":["education","python","raspberry-pi","tkinter"],"created_at":"2024-09-24T13:56:54.930Z","updated_at":"2025-04-04T23:06:48.131Z","avatar_url":"https://github.com/wallysalami.png","language":"Python","funding_links":["https://ko-fi.com/wallysalami"],"categories":[],"sub_categories":[],"readme":"# tkgpio\nA Python library to simulate electronic devices connected to the GPIO on a Raspberry Pi, using TkInter.\n\n\u003cimg src=\"https://user-images.githubusercontent.com/2084188/126525595-5b16f74f-c9bb-4828-be3c-79971756ac5a.png\" width=\"600\"\u003e\n\u003cimg src=\"https://user-images.githubusercontent.com/2084188/126411751-eddab125-392b-49ae-a007-73275abaa44d.png\" width=\"600\"\u003e\n\n\n## About\n\nDue to the Coronavirus outbreak in 2020, students enrolled in my Microcontroller course could not use the laboratory. So I decided to build a Raspberry Pi circuit simulator, to make remote class activities possible. And it works pretty well!\n\nThe main goal here is to enable students to use the same APIs that control physical devices connected to the GPIO, but interacting with a GUI instead. I'm not worried about creating a realistic electronic simulation.\n\nSince we were already using Python to program on Raspberry Pi, I've built the interface with TkInter. Some libraries (like gpiozero) allowed me to easily mock the devices in the GUI. In other cases, I had to reimplement the API inside the library – but since I can temporaraly add folders to Python's PATH, `import` commands keep working exactly as the original ones.\n\nTkGPIO currently supports the following devices:\n\n- Some [gpiozero](https://github.com/gpiozero/gpiozero) components (more coming soon)\n  - LED / PWMLED\n  - (Active) Buzzer\n  - DC Motor\n  - Servomotor\n  - Push Button\n  - Toggle Switch\n  - Distance Sensor (HC-SR04)\n  - Light Sensor (LDR)\n  - Motion Sensor (HC-SR501)\n  - Potentiometer (via MCP3xxx chip)\n- LCD display (reimplementing [Adafruit_CharLCD API](https://github.com/adafruit/Adafruit_Python_CharLCD))\n  - Only `message` and `clear` methods are supported for now (more coming soon)\n- Infrared emmitter (reimplementing [py_irsend API](https://github.com/ChristopherRogers1991/python-irsend))\n- Infrared receiver (reimplementing [python-lirc API](https://github.com/tompreston/python-lirc))\n\nTkGPIO also supports labels with text, border and background color.\n\n## Usage\n\nThis is a simple example to create and control 2 LEDs and 1 Button.\n\n\u003cimg src=\"https://user-images.githubusercontent.com/2084188/92954753-5c2db000-f43a-11ea-8a73-22e9e337c785.png\" width=\"300\"\u003e\n\n```python3\nfrom tkgpio import TkCircuit\n\n# initialize the circuit inside the GUI\n\nconfiguration = {\n    \"width\": 300,\n    \"height\": 200,\n    \"leds\": [\n        {\"x\": 50, \"y\": 40, \"name\": \"LED 1\", \"pin\": 21},\n        {\"x\": 100, \"y\": 40, \"name\": \"LED 2\", \"pin\": 22}\n    ],\n    \"buttons\": [\n        {\"x\": 50, \"y\": 130, \"name\": \"Press to toggle LED 2\", \"pin\": 11},\n    ]\n}\n\ncircuit = TkCircuit(configuration)\n@circuit.run\ndef main ():\n    \n    # now just write the code you would use on a real Raspberry Pi\n    \n    from gpiozero import LED, Button\n    from time import sleep\n    \n    led1 = LED(21)\n    led1.blink()\n    \n    def button_pressed():\n        print(\"button pressed!\")\n        led2.toggle()\n    \n    led2 = LED(22)\n    button = Button(11)\n    button.when_pressed = button_pressed\n    \n    while True:\n        sleep(0.1)\n\n```\n\nYou could also initialize the circuit in a function inside a separate Python file, to hide it from students.\n\nCheck more sample code files in `docs/examples`.\n\n\n## Instalation\n\nUse PyPI to install TkGPIO in your computer.\n\n```bash\npip install tkgpio\n```\n\nBy default, buzzers will flash on the window but will not play any sound. To enable that, install `numpy` and `sounddevice`, or install tkgpio using the command\n\n```bash\npip install 'tkgpio[sound]'\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwallysalami%2Ftkgpio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwallysalami%2Ftkgpio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwallysalami%2Ftkgpio/lists"}