npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

3d-printer-controller

v1.0.3

Published

Control your 3D printer directly from nodeJS

Downloads

22

Readme

3D printer controller

This module helps you control your 3d printer from JavaScript (& TypeScript). The module uses promises, so you can wait for the motor moves to be completed.

Features

  • Send custom GCode to the printer
  • Move the nozzle to an absolute position
  • Move the nozzle with a relative position
  • Set the speed of movement in mm/s
  • Get current position, get target position
  • Auto home the nozzle on the specified axes.

Get started

  1. Add the module to your dependencies:
    npm i 3d-printer-controller --save
  2. Create a printer instance in your code and call its .init() function:
    import {Printer} from "3d-printer-controller";
       
    (async () => {
        const myPrinter = new Printer("COM5", 115200, {x: 220, y: 220, z: 300});
        await myPrinter.init();
    })();
    Note, that you should provide the correct size of the printing area in case you don't want your printer be broken. You have to write your code inside an async function if you want to use await.

API

Cosntructor

new Printer(port: string, baudRate: number, maxPrintSize: Vector3D);
    // Vector3D is an object like {x: number, y: number, z: number}

Example:

const myPrinter = new Printer("COM5", 115200, {x: 220, y: 220, z: 300});

Initialise the 3D printer

await myPrinter.init();

You must invoke this method before using the printer.

Auto home

await myPrinter.autoHome(["X", "Y", "Z"]);

This auto homes the nozzle on the X, Y, and Z axes.

There is a particular function which auto homes the nozzle on the X and Y axes.

await myPrinter.autoHomeXY();

Send GCode

You can send a GCode string, or an array of GCode strings with this function:

// string:
await myPrinter.sendGCode("G28");

// array:
await myPrinter.sendGCode([
    "G91",
    "G0 F4800",
    "G0 X10 Y40"
]);

Set the speed of the movement

await myPrinter.setSpeed(80);

Sets the speed of the movement in millimeters / second.

Go to a specified position

You can make the nozzle go to specified position in millimeters. You can specify a vector or the X, Y(optional), Z(optional) components of the vector directly:

await myPrinter.goTo({x: 30, y: 60, z: 1}); // The nozzle goes to (30; 60; 1)
await myPrinter.goTo(50, 90, 2); // The nozzle goes to (50; 90; 2).
await myPrinter.goTo(30, 50); // The z value was not specified, so it goes remains the same as in the previous movement. The new position will be (30; 50; 2).

Get current position

const currentPos = await myPrinter.getCurrentPosition();
console.log(currentPos); // {x: number, y: number, z: number}

Returns the current position of the nozzle. This value is changing while the nozzle moves. This will become equal to the target position as soon as the nozzle finishes its movement.

Get target position

const targetPos = await myPrinter.getTargetPosition();
console.log(targetPos); // {x: number, y: number, z: number}

Returns the target position of the nozzle.

Get current position and target position at once

const posData = await myPrinter.getPositionData();
const currentPos = posData.currentPosition;
const targetPos = posData.targetPosition;

This method is only for saving time when we need all the two positions in one place (for example when waiting for the nozzle to finish its movement).