Upload
letitia-oconnor
View
213
Download
0
Embed Size (px)
Citation preview
Internet of Things with Intel EdisonCylonJS
Pierre Colletwww.Intel-Software-Academic-Program.com
[email protected] Software
2014-10-14
CylonJS ?Why ?You like NodeJS, but don’t like calling external shell scripts ?There’s a clean solution : CylonJS !
How ?Make sure you have the last version of the libmraa :
https://github.com/intel-iot-devkit/mraa
Install the NodeJS module :npm install cylon-intel-iot
Examples
Blink a LEDBlink a LED on pin #13
var Cylon = require('cylon');
Cylon.robot({ connection: { name: 'edison', adaptor: 'intel-iot' }, device: {name: 'led', driver: 'led', pin: 13 },
work: function(my) { every((1).second(), function() { my.led.toggle(); }); }}).start();
Control a ServoControl of a Servo
var Cylon = require('cylon'); Cylon.robot({ connection: { name: 'edison', adaptor: 'intel-iot' }, device: {name: 'servo', driver: 'servo', pin: 3 }, work: function(my) { var angle = 45 ; my.servo.angle(angle); every((1).second(), function() { angle = angle + 45 ; if (angle > 135) { angle = 45 } my.servo.angle(angle); }); } }).start();
This code make a servo motor switch every second from 45 to 90 to 135 degree.This servo of this exemple is plugged on the pin 3 of the Edison board.
Analog Read
work: function(my) { var analogValue = 0; every((1).second(), function() { analogValue = my.sensor.analogRead(); console.log('Analog value => ', analogValue); }); my.sensor.on('lowerLimit', function(val) { console.log("Lower limit reached!"); console.log('Analog value => ', val); }); my.sensor.on('upperLimit', function(val) { console.log("Upper limit reached!"); console.log('Analog value => ', val); }); }}).start();
Analog Read on A0
Cylon.robot({connection: { name: 'Edison', adaptor: 'intel-iot' }, device: { name: 'sensor', driver: 'analogSensor', pin: 0, lowerLimit: 100, upperLimit: 900 },
Conclusion
CylonJS is greatNodeJS / CylonJSNodeJS programming style is perfectly adapted to IoT. That’s why it is so popular.But you need a good library to interact with the GPIO : CylonJS.
CylonJS is great and available today. It targets robotics but can be used for anything IoT related.
Keep a eye on future NodeJS modules. You may see another one taking advantages of unique Edison features. But we propose you use CylonJS today.
License Creative Commons – By 3.0
You are free:• to Share — to copy, distribute and transmit the work • to Remix — to adapt the work • to make commercial use of the work Under the following conditions:• Attribution — You must attribute the work in the manner specified by the author or licensor (but
not in any way that suggests that they endorse you or your use of the work).With the understanding that: • Waiver — Any of the above conditions can be waived if you get permission from the copyright
holder. • Public Domain — Where the work or any of its elements is in the public domain under applicable
law, that status is in no way affected by the license. • Other Rights — In no way are any of the following rights affected by the license:
– Your fair dealing or fair use rights, or other applicable copyright exceptions and limitations; – The author's moral rights; – Rights other persons may have either in the work itself or in how the work is used, such as publicity or
privacy rights. • Notice — For any reuse or distribution, you must make clear to others the license terms of this
work. The best way to do this is with a link to this web page.
http://creativecommons.org/licenses/by/3.0/