Git Product home page Git Product logo

cylon-gpio's Introduction

Cylon.js For GPIO

Cylon.js (http://cylonjs.com) is a JavaScript framework for robotics, physical computing, and the Internet of Things (IoT).

This module provides drivers for General Purpose Input/Output (GPIO) devices (https://en.wikipedia.org/wiki/General_Purpose_Input/Output). It must be used along with an adaptor module such as cylon-firmata (https://github.com/hybridgroup/cylon-firmata) that supports the needed interfaces for GPIO devices.

Want to use Ruby on robots? Check out our sister project Artoo (http://artoo.io)

Want to use the Go programming language to power your robots? Check out our sister project Gobot (http://gobot.io).

Build Status Code Climate Test Coverage

Getting Started

Install the module with: npm install cylon cylon-gpio

Note you must also install whichever adaptor you want to use, such as: npm install cylon-firmata

Example

var Cylon = require('cylon');

// Initialize the robot
Cylon.robot({
  connections: {
    arduino: { adaptor: 'firmata', port: '/dev/ttyACM0' }
  },

  devices: {
    led: { driver: 'led', pin: 13 },
    button: { driver: 'button', pin: 2 }
  },

  work: function(my) {
    my.button.on('push', my.led.toggle);
  }
}).start();

Hardware Support

Cylon.js has a extensible system for connecting to hardware devices. The following 14 GPIO devices are currently supported:

  • Analog Sensor
  • Button
  • Continuous Servo
  • Direct Pin
  • IR Range Sensor
  • LED
  • Makey Button (high-resistance button like the MakeyMakey)
  • Maxbotix Ultrasonic Range Finder
  • Motor
  • Relay
  • RGB LED
  • Servo
  • Temperature Sensor
  • TP401 Gas Sensor

More drivers are coming soon...

Documentation

We're busy adding documentation to our web site at http://cylonjs.com/ please check there as we continue to work on Cylon.js

Thank you!

Contributing

For our contribution guidelines, please go to https://github.com/hybridgroup/cylon/blob/master/CONTRIBUTING.md .

Release History

For the release history, please go to https://github.com/hybridgroup/cylon-gpio/blob/master/RELEASES.md .

License

Copyright (c) 2013-2016 The Hybrid Group. Licensed under the Apache 2.0 license.

cylon-gpio's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cylon-gpio's Issues

problem running Maxbotix demo

This is my exact code. When I run I can see only the first trace. Is there a method or property of *my.maxbotix * that might help in debugging potential hardware, wiring issues?

var Cylon = require('cylon');
    Cylon.robot({
       connections: {
          edison: { adaptor: 'intel-iot' }
    },

devices: {
    maxbotix: { driver: 'maxbotix', pin:'1' }
 },    
work: function (my) {
    every((1).seconds(), function () {
        console.log('0 ASSERT  FIRST TRACE 1 second interval my.maxbotix' + my.maxbotix);

        my.maxbotix.range(function (data) {
            console.log("1 ASSERT 2ND TRACE range: " + data);
         });
      });
  }
}).start();

RGB LED driver does not work correctly on Intel Edison

When using the RGB LED driver and the .setRGB() function, the PWM value is not set correctly. The MRAA specifications say that the Pwm.write() function takes a float value representing the percentage of the duty cycle, however the setRGB function parses the hexadecimal color code into three one-byte values ranging from 0-256 and passes those directly to the pwmWrite function. This means that the colors #FF0100 and #FFFF00 look identical.

This can be fixed by changing the following code (rgb-led.js:82-84):

this.connection.pwmWrite(this.redPin, val.r);
this.connection.pwmWrite(this.greenPin, val.g);
this.connection.pwmWrite(this.bluePin, val.b);

to this:

this.connection.pwmWrite(this.redPin, val.r / 256.0);
this.connection.pwmWrite(this.greenPin, val.g / 256.0);
this.connection.pwmWrite(this.bluePin, val.b / 256.0);

I'd be happy to make a pull request if this is determined to be an acceptable solution for this issue.

direct pin : uncaught , unspecified error event

"use strict";
var camera = require('./Camera');
var deviceList = {
    lidar: { driver: "lidar-lite" }
}

var lidarList = [{ driver: 'direct-pin', pin: 40 }];

var Cylon = require("cylon");

var capturedTime = 0;
function init() {
    for (var i = 0; i < lidarList.length; i++) {
        deviceList["liderEn" + i] = {
            driver: 'direct-pin', pin: lidarList[i].pin
        }
    }
    Cylon.robot({
        connections: {
            raspi: { adaptor: "raspi" }
        },

        devices: deviceList,
        work: function (my) {
            every(100, function () {
                switchLider(my)
                my.lidar.distance(function (err, data) {
                    if (err) { console.error(err); }
                    console.log("distance: " + data);
                    if (data < 10) {
                        var time = Date.now()
                        if (time - capturedTime >= 10000) {
                            capturedTime = time;
                            camera.capture(time + ".jpg", function (err, timestamp, filename) {
                                if (err) {
                                    console.log(err)
                                } else {
                                    console.log("captured : " + filename)
                                }
                            })
                        }
                    }
                });
            });
        }
    }).start();
}

var currentPinIndex = 0;
function switchLider(my) {
    for (var i = 0; i < lidarList.length; i++) {
        var s = currentPinIndex++ == i?1:0;
        my["liderEn" + i].digitalWrite(s, function (err, val) {
            if (err) {
                console.log(err);
            }
        });
        if (currentPinIndex >= lidarList.length) {
            currentPinIndex = 0;
        }
    }
}


init();

Result :

2015-10-27T09:15:18.757Z : [Robot 1] - Starting connections.
2015-10-27T09:15:18.802Z : [Robot 1] - Starting connection 'raspi'.
2015-10-27T09:15:18.814Z : [Robot 1] - Starting devices.
2015-10-27T09:15:18.815Z : [Robot 1] - Starting device 'lidar'.
2015-10-27T09:15:18.817Z : [Robot 1] - Starting device 'liderEn0' on pin 40.
2015-10-27T09:15:18.817Z : [Robot 1] - Working.
distance: 225

Error: Uncaught, unspecified "error" event.
at Error (native)
at DigitalPin.emit (events.js:87:13)
at DigitalPin._setModeCallback (/home/pi/Documents/Projects/nodeDetect/node_modules/cylon/lib/io/digital-pin.js:152:17)
at DigitalPin. (/home/pi/Documents/Projects/nodeDetect/node_modules/cylon/lib/io/digital-pin.js:146:10)
at fs.js:1077:21
at FSReqWrap.oncomplete (fs.js:95:15)

Error is generated at the first time and program is down. Then run again , no error caused.
Restart program, same error happened. and run again . no problem.

Infrared proximity sensor always returns distance as 0

There's a problem with the infrared proximity sensor driver where the distance value always returns 0. In the following example given here:

var Cylon = require('cylon');

Cylon.robot({
  connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' },

  device: {
    name: 'sensor',
    driver: 'ir-range-sensor',
    pin: 0,
    model: 'gp2y0a41sk0f'
  },

  work: function(my) {
    every((1).seconds(), function(){
      var range = my.sensor.range();
      console.log('Range ===>', range);
    });
  }

}).start();

The "Range" always shows as 0. Going through the code on ir-range-sensor.js in cylon-gpio,

for (var range in this.rangeTable.rangeDistances){
    tmpRange = parseInt(range);
    if ((this.analogVal <= tmpRange) && (this.analogVal + 5 > tmpRange)){
      dist = this.rangeTable.rangeDistances[range].dist;
      break;
    }
  }

and logging "this.analogVal" in the console, I found that it is "undefined", hence the condition in the "if" statement never evaluates to "true" and therefore "dist" is always returned as 0.

Digital Input

I am new with arduino stuff and Cylon, so sorry if this question sounds silly.

I have attach a laser receiver sensor to my arduino board and I'd to read its state change with Cylon.
I try to look up on the available GPIO drivers and end up trying 'button'. The event I know is 'on push' which seems will be triggered only when it state change from 0 to 1. But I need also the opposite, which is from 1 to 0.

How do I get the event? Thank you.

How to register just created new driver with out a forking cylon-gpio

I want to add a general driver to gpio;

lets say ultrasonic(hcsr04)

  • the problem is became solved when we manually add it to the node_modules/cylon-gpio/libs folder
  • and register it in index.js

I has resolved that by forking gpio and link to my fork in the package.json but i need to update fork manually all the time is there any better solution for that?

analogRead returning values out of range

I have attached the output of a basic voltage divider to measure the value of a simple pressure sensor to Analog Pin 2 on an Edison Arduino breakout board. I also hooked up a Grove LCD display. The voltages that I read on my DMM range anywhere from 100mv when full pressure applied to 5v when no pressure applied. However, when I run the following code, the values from analogRead appear to be anywhere from about 300 to 9900. Based on the documentation, I was expecting 0 to 1023. Can someone let me know what I'm doing wrong here?

require('cylon').robot({
connections: { edison: { adaptor: 'intel-iot' } },
devices: {
led: { driver: 'led', pin: 13 },
screen: { driver: "upm-jhd1313m1", connection: "edison" },
pressure: { driver: 'analogSensor', pin: 2, connection: "edison" },
},

updateScreen: function (my, line1, line2) {
    my.screen.setColor(255, 0, 0);
    my.screen.setCursor(0, 0);
    my.screen.write(line1);
    my.screen.setCursor(1, 0);
    my.screen.write(line2);
},

work: function (my) {
    var that = this;
    var pressureValue = 0;

    every((0.1).second(), function () {
        my.led.toggle();
    });

    every((0.1).second(), function () {
        pressureValue = my.pressure.analogRead();
        that.updateScreen(my, 'Pressure: ' + pressureValue, '');
    });
}

}).start();

analogWrite doesn't work

I'm currently trying to do analogWrite(255) to pin 5 of an Arduino Uno, but it doesn't give me voltage reading at all. (it toggle the LED though)

I've tried it using regular arduino code directly on the board and at 255 it gives me around 4.8v.

This is my code:

"use strict";

const config = require(__dirname + "/config.json");
config.work = require(__dirname + "/lib/work");

(require("cylon")).robot(config).start();

this is the config part

{
    "name": "Testbot",
    "connections": {
        "arduino": { 
            "adaptor": "firmata", 
            "port": "/dev/ttyUSB0" 
        }
    },
    "devices": {
        "onboardLED": { 
            "driver": "led", 
            "pin": 13 
        },
        "writer": {
            "driver": "direct-pin",
            "pin": 5
        }
    }
}

and this is the work code

dev.onboardLED.toggle();
dev.writer.analogWrite(255);

Servos will not switch directions when using a Spark Core

I'm trying to write a simple cylon.js program to make a nodebot spin around in circles and alternating directions every second. With the program below I get it to spin, but it will not alternate directions. The output in the console shows that it is attempting to switch the servos cw/ccw but the nodebot continues to go in one direction.

Thinking something was up with my servos, I verified this worked with JohnnyFive so I'm not sure why cylon.js won't work.

Any ideas?

var Cylon = require('cylon');

// Initialize the robot
Cylon.robot({
    connection: {
        name: 'voodoospark',
        adaptor: 'voodoospark',
        accessToken: process.env.SPARK_TOKEN,
        deviceId: process.env.SPARK_DEVICE_ID,
        module: 'spark'
    },
    device: [
        { name: 'leftwheel', driver: 'continuous-servo', pin: 'D0' },
        { name: 'rightwheel', driver: 'continuous-servo', pin: 'D1' }
    ],

    work: function (my) {
        var cw = true;

        // turn right
        my.devices.leftwheel.clockwise();
        my.devices.rightwheel.counterClockwise();

        every((1).second(), function () {
            if (cw) {
                my.devices.leftwheel.counterClockwise();
                my.devices.rightwheel.clockwise();
                cw = false;
            } else {
                my.devices.leftwheel.clockwise();
                my.devices.rightwheel.counterClockwise();
                cw = true;
            }
        });
    }
}).start();

Stepper Motors with Cylon

I would like to use the BigEasyDriver to drive a stepper motor from the Arduino.

I've chosen Cylon over Johnny-Five because, although newer, I believe Cylon has the right structure in place to make the system incredibly extensible and I believe it fits a larger scheme that I have in mind.

What I noticed with Cylon is a lack of support for stepper motors, although Arduino firmata packages exist which can support steppers, one such instance even being configurable to include only the necessary features.

Here is what I'm looking for:

  1. If someone has already driven stepper motors using Cylon, I would like to know about it.
  2. If not, I am prepared to find time to make it happen myself (I have both C/C++ knowledge as well as minor Javascript knowledge), but I will definitely need some guidance: where should I start?

Please NOTE, I can always simply use individual pins to drive the BigEasy, but handling the timing for a stepper motor on the Node.js side is NOT ideal. It is far better to handle the timing for a stepper motor on the Arduino which is why these firmata's which include stepper motor functionality exist.

Typo in range() function infrared proximity sensor driver

The range() function in the infrared proximity sensor driver has a typo that causes a run time exception:

IrRangeSensor.prototype.range = function() {
  return(this.rangecm() / 2.54);
};

where rangeCm() is typed as rangecm(). This causes the following exception:

TypeError: Object #<IrRangeSensor> has no method 'rangecm'
    at IrRangeSensor.range (E:\Experiments\CylonJS\Arduino\arduino-uno-test1\node_modules\cylon-gpio\lib\ir-range-sensor.js:66:15)
    at Device.base.(anonymous function) [as range] (E:\Experiments\CylonJS\Arduino\arduino-uno-test1\node_modules\cylon\lib\utils.js:124:31)
    at null.<anonymous> (E:\Experiments\CylonJS\Arduino\arduino-uno-test1\ir_sensor.js:15:35)
    at wrapper [as _onTimeout] (timers.js:258:14)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

Similar mistake can be seen here as well:

if (opts.extraParams.model) {
    this.rangeTable = require(path.join(__dirname, './ir_range_tables/' + opts.extraParams.model.toLowerCase() + '.js'));
    this.device.on('analogRead', function(readVal) {
      this.device.emit('range', this.range());
      this.device.emit('rangeCm', this.rangecm());
    }.bind(this));

Cannot install cylon-gpio on Raspberry Pi

root@acp1:~# npm install -g cylon-gpio
npm http GET https://registry.npmjs.org/cylon-gpio
npm http 304 https://registry.npmjs.org/cylon-gpio
npm http GET https://registry.npmjs.org/cylon-gpio/-/cylon-gpio-0.7.0.tgz
npm http 404 https://registry.npmjs.org/cylon-gpio/-/cylon-gpio-0.7.0.tgz
npm ERR! fetch failed https://registry.npmjs.org/cylon-gpio/-/cylon-gpio-0.7.0.tgz
npm ERR! Error: 404 Not Found
npm ERR! at WriteStream. (/usr/local/node-v0.10.17-linux-arm-pi/lib/node_modules/npm/lib/utils/fetch.js:57:12)
npm ERR! at WriteStream.EventEmitter.emit (events.js:117:20)
npm ERR! at fs.js:1596:14
npm ERR! at /usr/local/node-v0.10.17-linux-arm-pi/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:103:5
npm ERR! at Object.oncomplete (fs.js:107:15)
npm ERR! If you need help, you may report this log at:
npm ERR! http://github.com/isaacs/npm/issues
npm ERR! or email it to:
npm ERR! [email protected]

npm ERR! System Linux 3.6.11+
npm ERR! command "/usr/local/node/bin/node" "/usr/local/node/bin/npm" "install" "-g" "cylon-gpio"
npm ERR! cwd /root
npm ERR! node -v v0.10.17
npm ERR! npm -v 1.3.8
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /root/npm-debug.log
npm ERR! not ok code 0

Button driver doesn't work

There are a couple of issues with the Button driver. I'm using the digispark connection, but I don't think this problem is specific to that connector.

From the example here:

var Cylon = require('cylon');

Cylon.robot({
  connection: { name: "digispark", adaptor: "digispark" },

  device: {name: 'button', driver: 'button', pin: 5},

  work: function(my) {
    my.button.on('push', function() {
      Logger.info("Button pushed!");
    });

    every(1000, function() {
        console.log("pressed?", my.button.isPressed());
    });
  }
}).start();
  1. the push event is never fired; I'd expect that it be triggered whenever the pin changes level
  2. Button#isPressed causes a stack trace:
/Users/blalor/devel/BSD/bum/node_modules/cylon/lib/utils.js:181
        return target[method].apply(target, args);
                              ^
TypeError: Object false has no method 'apply'
    at Device.base.(anonymous function) [as isPressed] (…/node_modules/cylon/lib/utils.js:181:31)
    at null.<anonymous> (…/button_test.js:14:31)
    at wrapper [as _onTimeout] (timers.js:258:14)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

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.