{"id":15172884,"url":"https://github.com/pozil/megapi-node-client","last_synced_at":"2026-02-24T06:37:43.476Z","repository":{"id":35851202,"uuid":"219726073","full_name":"pozil/megapi-node-client","owner":"pozil","description":"Unofficial MegaPi Node.js client","archived":false,"fork":false,"pushed_at":"2023-10-02T21:26:01.000Z","size":622,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T20:35:15.085Z","etag":null,"topics":["megapi","node","raspberry-pi"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/pozil.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-11-05T11:12:38.000Z","updated_at":"2022-02-12T17:56:42.000Z","dependencies_parsed_at":"2024-11-07T20:07:34.756Z","dependency_job_id":"dfc8f7f3-324f-4ff3-8a0c-d22fe79b1311","html_url":"https://github.com/pozil/megapi-node-client","commit_stats":{"total_commits":45,"total_committers":3,"mean_commits":15.0,"dds":0.4222222222222223,"last_synced_commit":"9a999221e54fa1561afc31ab495e337b78764321"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pozil%2Fmegapi-node-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pozil%2Fmegapi-node-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pozil%2Fmegapi-node-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pozil%2Fmegapi-node-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pozil","download_url":"https://codeload.github.com/pozil/megapi-node-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239686381,"owners_count":19680515,"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":["megapi","node","raspberry-pi"],"created_at":"2024-09-27T10:22:20.134Z","updated_at":"2025-10-25T12:14:45.424Z","avatar_url":"https://github.com/pozil.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MegaPi Node Client\n\nUnofficial MegaPi Node.js client derived from the unmaintained [Makeblock library](https://github.com/Makeblock-Official/NodeForMegaPi).\n\nThis projects brings the following major improvements:\n\n-   fixed a bunch of functions to work with latest firmware (the official Node project was out of sync with firmware)\n-   added support for Node.js v10 (last version supported on Raspberry Pi Zero)\n-   moved to a modern ES6 syntax (classes, async functions...)\n-   added a debug mode to trace serial communication\n\nWorks with MegaPi firmware `0e.01.016` and USB connection.\n\n**WARNING:** not all functions work. Some functions were not working in the original project and haven't been fixed (PRs welcome).\u003cbr/\u003e\nCommented functions indicate the ones that have been tested.\n\n## How To Use\n\nAssuming that you are running Node.js on a Raspberry Pi connected to MegaPi via USB.\n\n-   Compile and upload the [Firmware to your MegaPi](https://github.com/Makeblock-Official/FirmwareForMegaPi)\n-   Install the client on your Raspberry Pi:\n\n```\nnpm install megapi-node-client\n```\n\n-   Use this sample code to try out the project. You may need to change the `/dev/ttyUSB0` port depending on where you plug the USB cable. You can also pass options to the MegaPi constuctor (not shown here, see API section for details).\n\n```js\nimport MegaPi from 'megapi-node-client';\n\nconst megaPi = new MegaPi('/dev/ttyUSB0');\nawait megaPi.connect();\nawait megaPi.encoderMotorMove(1, 100, 500);\nawait megaPi.encoderMotorMove(3, 100, 300);\nawait megaPi.disconnect();\n```\n\n-   Build and run your code\n\n## API\n\nDocumentation is kept in the code (JSDoc) but here's an overview of what's available.\n\n## Constructor Options\n\nThe client is build by calling this constructor: `MegaPi(port = '/dev/ttyAMA0', options = {})`.\nOptions are the following:\n\n| Option                       | Default   | Description                                                                           |\n| ---------------------------- | --------- | ------------------------------------------------------------------------------------- |\n| `isDebugMode: boolean`       | `false`   | whether debug mode is enabled. Debug mode will output serial I/O to logs.             |\n| `logger: Object`             | `console` | class that is used to write logs. Use this to plug in a logging library like Winston. |\n| `logWelcomeMessage: boolean` | `true`    | whether to log the welcome message that indicates the firmware version.               |\n\n## Function Overview\n\nFunctions annotated with ✔ have been tested with hardware, are documented and are know to work. The others may or may not work.\n\n-   Main\n\n    -   ✔ **MegaPi**( serialPortPath, options )\n    -   ✔ **disconnect**()\n    -   ✔ **firmwareVersionRead**()\n    -   ✔ **reset**()\n\n-   GPIO\n\n    -   **digitalWrite**( pin, level )\n    -   **pwmWrite**( pin, pwm )\n    -   **digitalRead**( pin )\n    -   **analogRead**( pin )\n\n-   Motion\n\n    -   DC Motor\n        -   ✔ **dcMotorRun**( port, speed )\n        -   ✔ **dcMotorStop**( port )\n    -   Servo Motor\n        -   **servoRun**( port, slot, angle )\n    -   Encoder Motor\n        -   ✔ **encoderMotorRun**( slot, speed )\n        -   ✔ **encoderMotorStopn**( slot )\n        -   ✔ **encoderMotorMove**( slot, speed, distance )\n        -   ✔ **encoderMotorMoveTo**( slot, speed, position )\n        -   ✔ **encoderMotorPosition**( slot )\n        -   ✔ **encoderMotorSpeed**( slot )\n    -   Stepper Motor\n        -   **stepperMotorSetting**( port, microsteps, acceleration )\n        -   **stepperMotorRun**( port, speed )\n        -   **stepperMotorMove**( port, speed, distance )\n        -   **stepperMotorMoveTo**( port, speed, position )\n    -   Custom Firmware (0e.01.016poz)\n        -   ✔ **getModeMoveSpeed**()\n        -   ✔ **setModeMoveSpeed**( speed )\n\n-   Sensors\n\n    -   Ultrasonic Sensor\n        -   ✔ **ultrasonicSensorRead**( port )\n    -   LineFollow Sensor\n        -   ✔ **lineFollowerRead**( port )\n    -   Light Sensor\n        -   **lightSensorRead**( port )\n    -   Sound Sensor\n        -   **soundSensorRead**( port )\n    -   Temperature Sensor\n        -   **temperatureRead**( port )\n    -   PIR Motion Sensor\n        -   **pirMotionSensorRead**( port )\n    -   Touch Sensor\n        -   **touchSensorRead**( port )\n    -   LimitSwitch\n        -   **limitSwitchRead**( port, slot )\n    -   Humiture Sensor\n        -   **humitureSensorRead**( port, type )\n    -   Gas Sensor\n        -   **gasSensorRead**( port )\n    -   Flame Sensor\n        -   **flameSensorRead**( port )\n    -   Button\n        -   **buttonRead**( port )\n    -   Potentiometer\n        -   **potentiometerRead**( port )\n    -   Joystick\n        -   **joystickRead**( port, axis )\n    -   3-Axis Accelerometer and Gyro Sensor\n        -   **gyroRead**( axis )\n    -   Compass\n        -   **compassRead**( **function** onResult )\n\n-   Display\n\n    -   RGB Led\n        -   **rgbledDisplay**( port, slot, index, r, g, b )\n        -   **rgbledShow**( port, slot )\n    -   7-segment Display\n        -   **sevenSegmentDisplay**( port, value )\n    -   Led Matrix Display\n        -   **ledMatrixMessage**( port, x, y, msg )\n        -   **ledMatrixDisplay**( port, x, y, buffer )\n    -   Serial LCD Display\n        -   **lcdDisplay**( string )\n\n-   DSLR Shutter\n    -   **shutterOn**( port )\n    -   **shutterOff**( port )\n    -   **focusOn**( port )\n    -   **focusOff**( port )\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpozil%2Fmegapi-node-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpozil%2Fmegapi-node-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpozil%2Fmegapi-node-client/lists"}