Socket
Book a DemoInstallSign in
Socket

megapi-node-client

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

megapi-node-client

Unofficial MegaPi Node.js client

2.1.4
latest
Source
npmnpm
Version published
Weekly downloads
14
366.67%
Maintainers
1
Weekly downloads
 
Created
Source

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:

OptionDefaultDescription
isDebugMode: booleanfalsewhether debug mode is enabled. Debug mode will output serial I/O to logs.
logger: Objectconsoleclass that is used to write logs. Use this to plug in a logging library like Winston.
logWelcomeMessage: booleantruewhether 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 )

Keywords

mega pi

FAQs

Package last updated on 20 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.