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

megapi-node-client

v2.1.4

Published

Unofficial MegaPi Node.js client

Downloads

3

Readme

MegaPi Node Client

Unofficial MegaPi Node.js client derived from the unmaintained Makeblock library.

This projects brings the following major improvements:

  • fixed a bunch of functions to work with latest firmware (the official Node project was out of sync with firmware)
  • added support for Node.js v10 (last version supported on Raspberry Pi Zero)
  • moved to a modern ES6 syntax (classes, async functions...)
  • added a debug mode to trace serial communication

Works with MegaPi firmware 0e.01.016 and USB connection.

WARNING: not all functions work. Some functions were not working in the original project and haven't been fixed (PRs welcome). Commented functions indicate the ones that have been tested.

How To Use

Assuming that you are running Node.js on a Raspberry Pi connected to MegaPi via USB.

npm install megapi-node-client
  • 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).
import MegaPi from 'megapi-node-client';

const megaPi = new MegaPi('/dev/ttyUSB0');
await megaPi.connect();
await megaPi.encoderMotorMove(1, 100, 500);
await megaPi.encoderMotorMove(3, 100, 300);
await megaPi.disconnect();
  • Build and run your code

API

Documentation is kept in the code (JSDoc) but here's an overview of what's available.

Constructor Options

The client is build by calling this constructor: MegaPi(port = '/dev/ttyAMA0', options = {}). Options are the following:

| Option | Default | Description | | ---------------------------- | --------- | ------------------------------------------------------------------------------------- | | isDebugMode: boolean | false | whether debug mode is enabled. Debug mode will output serial I/O to logs. | | logger: Object | console | class that is used to write logs. Use this to plug in a logging library like Winston. | | logWelcomeMessage: boolean | true | whether to log the welcome message that indicates the firmware version. |

Function Overview

Functions annotated with ✔ have been tested with hardware, are documented and are know to work. The others may or may not work.

  • Main

    • MegaPi( serialPortPath, options )
    • disconnect()
    • firmwareVersionRead()
    • reset()
  • GPIO

    • digitalWrite( pin, level )
    • pwmWrite( pin, pwm )
    • digitalRead( pin )
    • analogRead( pin )
  • Motion

    • DC Motor
      • dcMotorRun( port, speed )
      • dcMotorStop( port )
    • Servo Motor
      • servoRun( port, slot, angle )
    • Encoder Motor
      • encoderMotorRun( slot, speed )
      • encoderMotorStopn( slot )
      • encoderMotorMove( slot, speed, distance )
      • encoderMotorMoveTo( slot, speed, position )
      • encoderMotorPosition( slot )
      • encoderMotorSpeed( slot )
    • Stepper Motor
      • stepperMotorSetting( port, microsteps, acceleration )
      • stepperMotorRun( port, speed )
      • stepperMotorMove( port, speed, distance )
      • stepperMotorMoveTo( port, speed, position )
    • Custom Firmware (0e.01.016poz)
      • getModeMoveSpeed()
      • setModeMoveSpeed( speed )
  • Sensors

    • Ultrasonic Sensor
      • ultrasonicSensorRead( port )
    • LineFollow Sensor
      • lineFollowerRead( port )
    • Light Sensor
      • lightSensorRead( port )
    • Sound Sensor
      • soundSensorRead( port )
    • Temperature Sensor
      • temperatureRead( port )
    • PIR Motion Sensor
      • pirMotionSensorRead( port )
    • Touch Sensor
      • touchSensorRead( port )
    • LimitSwitch
      • limitSwitchRead( port, slot )
    • Humiture Sensor
      • humitureSensorRead( port, type )
    • Gas Sensor
      • gasSensorRead( port )
    • Flame Sensor
      • flameSensorRead( port )
    • Button
      • buttonRead( port )
    • Potentiometer
      • potentiometerRead( port )
    • Joystick
      • joystickRead( port, axis )
    • 3-Axis Accelerometer and Gyro Sensor
      • gyroRead( axis )
    • Compass
      • compassRead( function onResult )
  • Display

    • RGB Led
      • rgbledDisplay( port, slot, index, r, g, b )
      • rgbledShow( port, slot )
    • 7-segment Display
      • sevenSegmentDisplay( port, value )
    • Led Matrix Display
      • ledMatrixMessage( port, x, y, msg )
      • ledMatrixDisplay( port, x, y, buffer )
    • Serial LCD Display
      • lcdDisplay( string )
  • DSLR Shutter

    • shutterOn( port )
    • shutterOff( port )
    • focusOn( port )
    • focusOff( port )