{"id":14978042,"url":"https://github.com/bywulf/brickpi3-nodejs","last_synced_at":"2025-10-28T07:31:15.253Z","repository":{"id":82608468,"uuid":"102987875","full_name":"byWulf/brickpi3-nodejs","owner":"byWulf","description":"The BrickPi3 connects LEGO Mindstorms with the Raspberry Pi. - nodejs implementation","archived":false,"fork":false,"pushed_at":"2018-08-27T18:11:20.000Z","size":6251,"stargazers_count":8,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-09T08:31:27.315Z","etag":null,"topics":["brickpi","brickpi3","lego","lego-ev3","lego-mindstorms","lego-nxt","raspberry-pi","raspberrypi"],"latest_commit_sha":null,"homepage":"https://www.dexterindustries.com/brickpi/","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/byWulf.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":"2017-09-09T22:09:48.000Z","updated_at":"2023-04-07T00:11:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"fa111e90-a9b1-4ff5-b1a4-d8f14aa9e202","html_url":"https://github.com/byWulf/brickpi3-nodejs","commit_stats":{"total_commits":27,"total_committers":3,"mean_commits":9.0,"dds":"0.14814814814814814","last_synced_commit":"b506f06ba6f2df7e3629b3818f7dca0c9d38932b"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byWulf%2Fbrickpi3-nodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byWulf%2Fbrickpi3-nodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byWulf%2Fbrickpi3-nodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byWulf%2Fbrickpi3-nodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/byWulf","download_url":"https://codeload.github.com/byWulf/brickpi3-nodejs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238614440,"owners_count":19501458,"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":["brickpi","brickpi3","lego","lego-ev3","lego-mindstorms","lego-nxt","raspberry-pi","raspberrypi"],"created_at":"2024-09-24T13:56:46.065Z","updated_at":"2025-10-28T07:31:14.911Z","avatar_url":"https://github.com/byWulf.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BrickPi3 package for nodejs\nWith this package you can control your BrickPi3 with nodejs. \n\nThis package has the same interface as the python library and was copied 1:1 with sligth language adjustments (bitwise operators are a bit different and the return values are promises). So just look at their examples (https://github.com/DexterInd/BrickPi3/tree/master/Software/Python/Examples) to see, how you can archive different tasks. Just remember, that you get promises back from most of the methods.\n\nIf you find any bugs, please open an issue or submit a pull request. I couldn't test everything, because I only have ev3 large motors. So I need your help to know if everything else works :)\n\n## Install\n```bash\nnpm install --save brickpi3\n```\n\n## Usage\n\n```javascript\nconst brickpi3 = require('brickpi3');\n\n(async () =\u003e {\n    try {\n        let BP = new brickpi3.BrickPi3();\n        \n        //Make sure to stop and free all motors and sensors when the programm exits\n        brickpi3.utils.resetAllWhenFinished(BP);\n        \n        //Resetting offset position of motor A to 0\n        let encoder = await BP.get_motor_encoder(BP.PORT_A);\n        await BP.offset_motor_encoder(BP.PORT_A, encoder);\n        await BP.set_motor_power(BP.PORT_A, 10);\n    } catch (err) {\n        console.log(err);        \n    }\n})();\n```\n    \n### Utils\nWhen you need to find the extreme offsets of the motor (f.e. an arm can only get from point a to point b but not beyond), there is a helper function available like explained in this video: https://youtu.be/d0bghBZZMUg?t=1m35s\n\n```javascript\nconst brickpi3 = require('brickpi3');\n\n(async () =\u003e {\n    try {\n        let BP = new brickpi3.BrickPi3();\n        brickpi3.utils.resetAllWhenFinished(BP);\n        \n        await brickpi3.utils.resetMotorEncoder(BP, BP.PORT_A, brickpi3.utils.RESET_MOTOR_LIMIT.MIDPOINT_LIMIT);\n        await BP.set_motor_position(BP.PORT_A, 0);\n        console.log(\"Motor should now be in the middle of its two extremes\");\n    } catch (err) {\n        console.log(err);\n    }\n})();\n```\n\nFor easier working with motors and sensors, you can get an instance of each of them and then access their methods:\n```javascript\nconst brickpi3 = require('brickpi3');\n\n(async () =\u003e {\n    try {\n        let BP = new brickpi3.BrickPi3();\n        brickpi3.utils.resetAllWhenFinished(BP);\n        \n        //Get the instance of one motor and sensor\n        let motor = brickpi3.utils.getMotor(BP, BP.PORT_A);\n        //getSensor has an optional third parameter which allows to overwrite the default configuration time limit\n        let sensor = brickpi3.utils.getSensor(BP, BP.PORT_2);\n        \n        //First set the type of the sensor\n        await sensor.setType(BP.SENSOR_TYPE.EV3_TOUCH);\n        \n        //You can also change the default configuration time limit (3000ms) for the sensor configuration after initialization\n        sensor.setConfigurationTimeLimit(4000);\n\n        //Reset the motors encoder to 0\n        await motor.resetEncoder();\n        \n        //Rotates the motor one revolution - will resolve only when finished\n        await motor.setPosition(360);\n        \n        //Powers on the motor until the callback function is true (good to use with sensors f.e.)\n        await motor.setPower(50, async () =\u003e {\n            return await sensor.getValue() === 1;\n        });\n    } catch (err) {\n        console.log(err);\n    }\n})();\n```\n\nIf you want to calculate, what gear ratio some connected gears have, there is also a helper:\n```javascript\nconst brickpi3 = require('brickpi3');\n\n//A 8-teeth-gear drives a 24-teeth-gear, which is connected to another 8-teeth-gear, which drives another 24-teeth-gear\nconsole.log(new brickpi3.utils.Gear(8).drive(24).connect(8).drive(24).getFactor());\n// =\u003e 0.111 (so if you rotate the initial 8-teeth-gear one evolution, the last 24-teeth-gear will rotate 0.111 rounds in the same direction)\n```\n![](https://raw.githubusercontent.com/bywulf/brickpi3-nodejs/master/docs/gearExplanation.gif)\n\n### BrickPi3 Stacking\nIf you have multiple brickPi3's, you can stack them and control even more motors/sensors with a single raspberry pi.\n\nFirst attach each brickPi separatly and execute the following script. You need to write down the id of each brickPi.\n    \n```javascript\nconst brickpi3 = require('brickpi3');\n\n(async () =\u003e {\n    try {\n        let BP = new brickpi3.BrickPi3();\n        console.log(await BP.get_id());\n    } catch (err) {\n        console.log(err);\n    }\n})();\n```\n    \nThen you can set the address for each of your brickPi's in the initializing part and access the four sensors and motors with each brickPi object instance.\n\n```javascript\nconst brickpi3 = require('brickpi3');\n\n(async () =\u003e {\n    try {\n        await brickpi3.set_address(1, 'A778704A514D355934202020FF110722');\n        await brickpi3.set_address(2, 'DF9E6AC3514D355934202020FF112718');\n        \n        const BP1 = new brickpi3.BrickPi3(1);\n        const BP2 = new brickpi3.BrickPi3(2);\n            \n        brickpi3.utils.resetAllWhenFinished(BP1);\n        brickpi3.utils.resetAllWhenFinished(BP2);\n        \n        const motor1 = brickpi3.utils.getMotor(BP1, BP1.PORT_A);\n        const motor2 = brickpi3.utils.getMotor(BP2, BP2.PORT_A);\n            \n        //Reset Motor A offset of your first brickPi\n        await motor1.resetEncoder();\n            \n        //Reset Motor A offset of your second brickPi\n        await motor2.resetEncoder();\n            \n        //Let the motor A of your first brickPi turn constantly\n        await motor1.setPower(10);\n            \n        //Let the motor A of your second brickPi rotate by 45° every two seconds.\n        let target = 0;\n        const moveOn = async () =\u003e {\n            target = target + 45;\n            await motor2.setPosition(target);\n    \n            setTimeout(moveOn, 2000);\n        };\n        moveOn();\n            \n    } catch(err) {\n        console.log(err);\n    }\n})();\n```\n\n## Special thanks\nThanks to Sumit Kumar (http://twitter.com/tweetsofsumit) for providing an example on how to communicate with the brickPi3 in nodejs on his repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbywulf%2Fbrickpi3-nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbywulf%2Fbrickpi3-nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbywulf%2Fbrickpi3-nodejs/lists"}