{"id":17652382,"url":"https://github.com/bashleigh/gpio","last_synced_at":"2025-05-07T07:47:47.658Z","repository":{"id":62501664,"uuid":"90019284","full_name":"bashleigh/GPIO","owner":"bashleigh","description":"GPIO pin environment manager","archived":false,"fork":false,"pushed_at":"2018-04-26T09:54:27.000Z","size":38,"stargazers_count":5,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-31T07:51:13.369Z","etag":null,"topics":["gpio","gpio-manager","hardware","laravel","pwm","raspberry-pi","sensor"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/bashleigh.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}},"created_at":"2017-05-02T10:10:38.000Z","updated_at":"2022-02-24T09:57:52.000Z","dependencies_parsed_at":"2022-11-02T09:46:29.876Z","dependency_job_id":null,"html_url":"https://github.com/bashleigh/GPIO","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bashleigh%2FGPIO","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bashleigh%2FGPIO/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bashleigh%2FGPIO/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bashleigh%2FGPIO/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bashleigh","download_url":"https://codeload.github.com/bashleigh/GPIO/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252839193,"owners_count":21812083,"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":["gpio","gpio-manager","hardware","laravel","pwm","raspberry-pi","sensor"],"created_at":"2024-10-23T11:46:43.647Z","updated_at":"2025-05-07T07:47:47.633Z","avatar_url":"https://github.com/bashleigh.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"GPIO manager\n===\n\n\u003e requires testing\n\nThe GPIO manager is designed to house your hardware environment setup and allow you to manager and interact with the hardware. \n\nThe GPIO manager comes with a Laravel bridged service provider for easy integration with Laravel.\n\nThe GPIO class requires gpio to be installed \n\n```bash\napt-get install gpio\n```\n\n## Installing into laravel \nAdd the package to your application via composer\n\n```bash\ncomposer require chickentikkamasala/gpio\n```\n\n```php\n'providers' =\u003e [\n\n    ...\n    \n    \\ChickenTikkaMasala\\GPIO\\Bridge\\Laravel\\GPIOServiceProvider::class,\n    \n    ...\n    \n];\n```\n\nAdd the event listener to your Event Service Provider \n\n```php\n$subscribe = [\n    \\ChickenTikkaMasala\\GPIO\\Bridge\\Laravel\\Events\\EventSubscriber::class,\n];\n```\nThe above is for recaching the GPIO manager after a request to prevent redeclaration of the manager and resetting everything to their default value. \n\n\u003e If you run your application and alter your environment setup, you may want to run `php artisan cache:clear` to clear the cached setup.\n\nPublish the vendor to get the config files\n\n```bash\nphp artisan vendor:publish --provider=\"ChickenTikkaMasala\\GPIO\\Bridge\\Laravel\\GPIOServiceProvider\"\n```\nExample setup\n```php\n    'pins' =\u003e [\n        'redled' =\u003e [\n            'pin' =\u003e 1,\n            'mode' =\u003e 'pwm',\n        ],\n    ],\n```\n### Testing with the command line \n\nTurn the redled on pin 1 on full\n\n```bash\nphp artisan gpio:set redled 1023\n```\nList all GPIO pin input from your setup\n```bash\nphp artisan gpio:list\n```\nThis will output an array of all the GPIOs setup with the manager\n\n### Creating a new connection\n\nAlternatively to config setup you can call the create function to add new connections. \n\n```php\n    public function index(GPIOManager $manager) \n    {\n        $manager-\u003ecreate('greenled', 2);\n        $manager-\u003egreenled = 'ON';\n    }\n```\n\nThe manager maps your named connections as parameters as shown above. When reading pins we can use the same method with the parameters to get the result \n\n```php\n    public function index(GPIOManager $manager)\n    {\n        //create an analog sensor\n        $manager-\u003ecreate('sensor', 3, 'aread');\n        $value = $manager-\u003esensor;\n        \n        return response()-\u003ejson(['sensor' =\u003e $value]);\n    }\n```\n\nMapping also applies to the values 'OFF' and 'ON' where PWM expects 1023 as max and write expect 1. 'OFF' will equal to 0.\n\n### Custom GPIO Classes/Modes\n\nYou can however add your own GPIO modes/classes in 2 ways. \n\nFirst being \n\n```php\n\nuse ChickenTikkaMasala\\GPIO\\GPIO;\n\nclass RedLED extends GPIO\n{\n    public function __construct()\n    {\n        parent::__construct(1, 'pwm', 'OFF');\n    }\n    \n    public function getMethod()\n    {\n        return 'out';\n    }\n    \n}\n```\n\n```php\n    public function index(GPIOManager $manager)\n    {\n        $redLED = new RedLED();\n        $manager-\u003eadd($redLED);\n    }\n```\n\nAnother method is to use the registerMode function to register the mode type for the manager so you can do something like this\n\n```php\n    $manager-\u003ecreate('red', 1, 'LED');\n```\nOur GPIO config array in app/gpio.php\n```php\n    'modes' =\u003e [\n        'LED' =\u003e \\App\\GPIO\\Modes\\LED::class,\n    ],\n```\n\n### Terminal functions\n\n- `gpio:set redled 500` =\u003e set red LED to 500\n- `gpio:get sensor` =\u003e print the sensor reading\n- `gpio:list` =\u003e list all connections\n- `gpio:function redled increment 1023 1000` =\u003e call the increment function with the options (options needs implementing)\n- `gpio:listen sensor --onChange` =\u003e prints the state of the sensor (onChange option to only print if value has changed else consistently print incoming value)\n\n## Available default modes \n\n- PWM =\u003e for incrementing the voltage between 0 and max\n- Awrite\n- ARead\n- Write =\u003e for writing to pins either OFF or ON (0v or max voltage)\n- Read =\u003e for reading pins either OFF or ON \n\n## Value conversions \n\nYou may remember seeing (if you've ever used an arduino) values being set as HIGH or LOW. You can do this with the GPIO and depending on it's mode it will automatically fix your maximum value. \n\n```php\n    //PWM all the below = 1023\n    $manager-\u003eredled = 'HIGH';\n    $manager-\u003eredled = 'UP';\n    $manager-\u003eredled = 'ON';\n    \n    //Where as for write and awrite: these equal to 1\n    $manager-\u003eredled = 'HIGH';\n    $manager-\u003eredled = 'UP';\n    $manager-\u003eredled = 'ON';\n    //all equal to 1\n    \n    //The below all equal to 0\n    $manager-\u003eredled = 'LOW';\n    $manager-\u003eredled = 'DOWN'\n    $manager-\u003eredled = 'OFF';\n```\n\n## Getting the GPIO class out of the manager\n\nYou can get the class out of the manager if you wish using \n\n```php\n    $redled = $manager-\u003eget('redled');\n    \n    //if you wanted to put it back simply use the add function again\n    \n    $manager-\u003eadd('redled', $redled);\n```\n\n\n### PWM functions\n\nIn PWM GPIO I have added 2 function for incrementing and decrementing for incrementing/decrementing to a value within an interval.\n```php\n$redled = $manager-\u003eget('redled');\n$redled-\u003eincrement(1023, 200);\n//redled will 'fade' from 0 to 1023 \n//increment will increase every 200th millisecond\n\n$redled-\u003edecrement(0, 200);\n\n$manager-\u003eadd('redled', $redled);\n```\n\n### GPIO Options \nIf you see http://wiringpi.com/the-gpio-utility/ there is a usage section. These options are available to pass to the GPIOManager like so (example to use BCM pins):\n\n```php\n    'pins' =\u003e [\n        'redled' =\u003e [\n            'pin' =\u003e 18, //wiring pi pin 1 = BCM pin 18\n            'mode' =\u003e 'pwm',\n            'options' =\u003e [\n                '-g',\n            ],\n        ],\n    ],\n```\n\nAn extremely handy pin map https://pinout.xyz/\n\n### Default GPIO value\n```php\n    'pins' =\u003e [\n        'redled' =\u003e [\n            'pin' =\u003e 18,\n            'mode' =\u003e 'pwm',\n            'defaultValue' =\u003e 1023,//turn pin on full on boot of application \n        ],\n    ],\n```\n\n# Coming soon\n\n- Symfony bridge\n- mapping values from 'low' to 'high' (for ESCs for example a pwm value of 60 is 0. For servos we may want to map 0 - 1023 to something like 0 - 180 degrees where a 'high' of 1023 = 180 degrees)\n- exceptions for command errors\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbashleigh%2Fgpio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbashleigh%2Fgpio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbashleigh%2Fgpio/lists"}