Coder Social home page Coder Social logo

riologiuseppe / rf24js Goto Github PK

View Code? Open in Web Editor NEW
1.0 4.0 2.0 44 KB

Module rf24js wants to be a simple wrapper of RF24C++ library by TMRH20. No logic added, just existing methods wrapped.

Python 0.63% C++ 43.97% TypeScript 55.40%
radio wrapper nrf24 rf24 tmrh20 javascript nodejs npm node-gyp typescript

rf24js's Introduction

rf24js

Support Node of LTS npm version Build passing Build passing Support dependencies rf24 nan License mit tested


Description

Module rf24js wants to be a simple wrapper of RF24C++ library by TMRH20. No logic added, just existing methods wrapped.

How to use

Install dependencies:

The only one dependency is the library it wants to wrapper: RF24. Use the following instructions to compile and install it from sources:

git clone https://github.com/nRF24/RF24.git
cd RF24 
make
sudo make install

Import in node js

After RF24 is installed, simple run:

npm install --save rf24js

Use in your project

Typescript

import {radio, PALevel,CRCLength,Datarate} from 'rf24js'

Javascript

var rf24js = require('rf24js');
var radio = rf24js.radio;
var PALevel = rf24js.PALevel;
var CRCLength = rf24js.CRCLength;
var Datarate = rf24js.Datarate;

Configure and setup your radio using create(ce, cs) method.

Parameter ce is the mini-pc pin number in with is connected radio chip enable pin.
Parameter cs is a number (byte) to select SPI device in with is connected the radio. In general this parameter is an integer that represent the id, without dot, of the spi devices you find using command ls /dev. Example: for spidev0.0 CS is 0, for spidev0.1 CS is 1, for spidev1.0 CS is 10, ecc

radio.create(2, 10); // OrangePi-Zero 
radio.create(22, 0); // RaspberryPi 1/2/3 
radio.begin();
radio.printDetails(); // Optionally: is used to show radio configuration

Declare and open read and write pipes

var pipe1 = new Buffer("1Node\0");
var pipe2 = new Buffer("2Node\0");
radio.openWritingPipe(pipe1);
radio.openReadingPipe(1, pipe2);

Read data

var buffer = null;
if (radio.available())
    buffer = radio.read(4);

Write data

var buffer = new Buffer(4).fill(0);
buffer.writeUInt32LE(50);
var success = radio.write(buffer, buffer.length);

Note

In some OS like Raspibian yuo need to start node application as super user.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.