{"id":16648969,"url":"https://github.com/rohan-bhautoo/python-simulation","last_synced_at":"2026-04-27T02:32:38.268Z","repository":{"id":136017678,"uuid":"181050044","full_name":"rohan-bhautoo/Python-Simulation","owner":"rohan-bhautoo","description":"This project consists of controlling a simulator called readopcForStrands to display led animation by using Python.","archived":false,"fork":false,"pushed_at":"2022-02-13T19:47:39.000Z","size":5683,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-27T11:06:26.541Z","etag":null,"topics":["arduino","opc","python"],"latest_commit_sha":null,"homepage":"","language":"Python","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/rohan-bhautoo.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":"2019-04-12T17:02:16.000Z","updated_at":"2025-01-01T07:41:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"c3e9f8f6-7f43-4442-90cf-8e7ff61bffbf","html_url":"https://github.com/rohan-bhautoo/Python-Simulation","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rohan-bhautoo/Python-Simulation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohan-bhautoo%2FPython-Simulation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohan-bhautoo%2FPython-Simulation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohan-bhautoo%2FPython-Simulation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohan-bhautoo%2FPython-Simulation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rohan-bhautoo","download_url":"https://codeload.github.com/rohan-bhautoo/Python-Simulation/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohan-bhautoo%2FPython-Simulation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32320335,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T23:26:28.701Z","status":"online","status_checked_at":"2026-04-27T02:00:06.769Z","response_time":128,"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":["arduino","opc","python"],"created_at":"2024-10-12T09:06:11.681Z","updated_at":"2026-04-27T02:32:38.244Z","avatar_url":"https://github.com/rohan-bhautoo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg width=\"200\" height=\"200\" src=\"https://github.com/rohan-bhautoo/Python-Simulation/blob/master/Screenshots/Daco_4428823.png\"\u003e\n\u003c/p\u003e\n\u003ch1 align=\"center\"\u003ePython Simulation\u003c/h1\u003e\n\u003cp\u003e\n  \u003cimg alt=\"Version\" src=\"https://img.shields.io/badge/version-1.2.0-brightgreen.svg\" /\u003e\n  \u003cimg alt=\"Python\" src=\"https://img.shields.io/badge/Python_\u003e=3.7.2-3776AB?logo=python\u0026logoColor=white\" /\u003e\n  \u003cimg alt=\"Arduino\" src=\"https://img.shields.io/badge/Arduino-038C8C?logo=arduino\u0026logoColor=white\" /\u003e\n\u003c/p\u003e\n\n## Description\n\u003e This project consists of controlling a simulator called *readopcForStrands* to display led animation by using Python.\n\u003e \n\u003e See other images of the project in the [Screenshot](/Screenshots) folder.\n\n### 🏠 [Homepage](/Python%20Simulation/Python%20code/Coursework.py)\n\u003cp align=\"center\"\u003e\n  \u003cimg width=\"600\" src=\"https://github.com/rohan-bhautoo/Python-Simulation/blob/master/Screenshots/welcome_animation.png\"\u003e\n\u003c/p\u003e\n\n\u003e A menu will then be displayed on the Shell command prompt to allow the user to select different animations.\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/rohan-bhautoo/Python-Simulation/blob/master/Screenshots/Menu.png\"\u003e\n\u003c/p\u003e\n\n## Prerequisite\n\n### IDLE Python\n\u003e Python is a programming language that lets you work more quickly and integrate your systems more effectively. Download it [here](https://www.python.org/downloads/).\n\n### Arduino UNO R3 Board\n\u003e Arduino Uno is a microcontroller board based on the ATmega328P (datasheet). It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz ceramic resonator (CSTCE16M0V53-R0), a USB connection, a power jack, an ICSP header and a reset button. Buy it [here](https://store.arduino.cc/products/arduino-uno-rev3/).\n\n### Breadboard\n\u003e A breadboard is a solderless construction base used for developing an electronic circuit and wiring for projects with microcontroller boards. Buy it [here](https://www.aliexpress.com/item/32845516827.html?aff_fcid=0810a3482d99482cb204845fdf406717-1644774917577-09852\u0026aff_fsk\u0026aff_platform=api-new-product-detail\u0026sk\u0026aff_trace_key=0810a3482d99482cb204845fdf406717-1644774917577-09852\u0026terminal_id=ba6fbd5591524f96930b577c93b7f7fa).\n\n### Microphone Sound Sensor\n\u003e The Microphone Sound Sensor will be used to detech sound and display random animation on the simulator based on the sound intensity. Buy it [here](https://www.amazon.com/dp/B0173OAWE4?tag=makeradvisor-20\u0026linkCode=ogi\u0026th=1\u0026psc=1).\n\n## Libraries\n\u003e A library is a set of method and function that is declared at the beginning of the program, this will prevent the programmer from writing long section of codes. Below is how different libraries were implemented in this project.\n```python\nimport opc\nimport time\nimport random\nfrom nanpy import ArduinoApi\nfrom nanpy import SerialManager\n```\n\n### OPC.py\n\u003e OPC.py library allows the python code to have access to the LED simulator to display the animation. It will also act as the local server host.\n```python\nclient = opc.Client('localhost:7890')\n```\n\n### Time.py\n\u003e The Time library is used in order to control the time sleep between the LED animations.\n```python\nled_coulour[181] = colour\ntime.sleep(0.08)\nclient.put_pixels(led_colour)\n\nled_coulour[240] = colour\ntime.sleep(0.08)\nclient.put_pixels(led_colour)\n\nled_coulour[241] = colour\ntime.sleep(0.08)\nclient.put_pixels(led_colour)\n```\n\n### Random.py\n\u003e Random function is used to be able to generate different RGB colour codes to obtain different led colours during the animations.\n```python\nred = random.randint(0,256)\ngreen = random.randint(0,256)\nblue = random.randint(0,256)\ncolour = (red,green,blue)\n```\n\u003e *random.randint* followed by integers in the brackets. The integer used in the bracket is 0 to 256. These are integer are for RGB value and random will generate a value between this 0 to 255 range as the final value in not taken into account\n\u003cp align=\"center\"\u003e\n  \u003cimg height=\"300\" src=\"https://github.com/rohan-bhautoo/Python-Simulation/blob/master/Screenshots/random_animation.png\"\u003e\n\u003c/p\u003e\n\n### Nanpy.py\n\u003e Nanpy is a library that use your Arduino as a slave, controlled by a master device where you run your scripts, such as a PC, a Raspberry Pi etc. This would imply that the Arduino will only read the data from the python IDLE. Nanpy will allow communication between the PC, Arduino and Mircrophone sensor.\n```sh\npip install nanpy\n```\n\n\u003e The following code is implemented to communicate with the Arduino from the python IDLE using SerialManager(‘COM6’). COM6 is the port used for Arduino.\n\u003e \n\u003e The sound sensor is connected to pin 8 on the Arduino.\n\n```python\nconnection = SerialManager('COM6')\na = ArduinoApi (connection=connection)\nsoundSensor = 8\na.pinMode(soundSensor, a.INPUT)\n\n#reading values from sound sensor\nSensorData = a.digitalRead(soundSensor)\nprint(SensorData)\n\nled_colour1=[(255,0,0)]*360\nled_colour2=[(0,0,0)]*360\n\n#condition for intensity of SensorData\nif(SensorData == 0):\n  client.put_pixels(led_colour1)\nelif(SensorData == 1):\n  client.put_pixels(led_colour2)\n```\n\n## Exception handling and verification\n\u003e In order to avoid a program from crashing, an exception handling and try except are used, along with KeyboardInterrupt Exception. This will read the user input from the keyboard and will cancel the animation. As soon as the program is stopped, the menu will show up again. In order for this to happen, the continue function is added. This will keep the program to run again and again until the user decides to exit.\n\u003cp align=\"center\"\u003e\n  \u003cimg height=\"300\" src=\"https://github.com/rohan-bhautoo/Python-Simulation/blob/master/Screenshots/keyboard_interrupt_exception.png\"\u003e\n\u003c/p\u003e\n\n\u003e To verify if the user has input a numeric value, the if else has a section where it will verify on the input, if the input is not a numeric value, it will display a message and will prompt the user to input a new value.\n\u003cp align=\"center\"\u003e\n  \u003cimg height=\"300\" src=\"https://github.com/rohan-bhautoo/Python-Simulation/blob/master/Screenshots/non_numeric_exception.png\"\u003e\n\u003c/p\u003e\n\n\u003e Conditional staments was used to check if the option entered by the user, in the Menu, is a valid one. If not, then the program will return an error and the menu will be displayed again.\n\u003cp align=\"center\"\u003e\n  \u003cimg height=\"300\" src=\"https://github.com/rohan-bhautoo/Python-Simulation/blob/master/Screenshots/menu_validation.png\"\u003e\n\u003c/p\u003e\n\n## Arduino Connection\n\u003cp align=\"center\"\u003e\n  \u003cimg width=\"600\" src=\"https://github.com/rohan-bhautoo/Python-Simulation/blob/master/Screenshots/arduino_connection.png\"\u003e\n\u003c/p\u003e\n\n## Usage\n\u003e 1 - Open Python IDLE \n\u003e \n\u003e 2 - From the File setting, open the \\Python Simulation\\Python code\\Coursework.py file.\n\u003e \n\u003e 3 - Run the /Python Simulation/simulator/bin/windows64/readopcForStrands.exe.\n\u003e \n\u003e 4 - Run python code and view the python simulator.\n\u003e \n\u003e 5 - The WELCOME animation will appear.\n\n## Author\n\n👤 **Rohan Bhautoo**\n\n* Github: [@rohan-bhautoo](https://github.com/rohan-bhautoo)\n* LinkedIn: [@rohan-bhautoo](https://linkedin.com/in/rohan-bhautoo)\n\n## Show your support\n\nGive a ⭐️ if this project helped you!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frohan-bhautoo%2Fpython-simulation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frohan-bhautoo%2Fpython-simulation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frohan-bhautoo%2Fpython-simulation/lists"}