Using cylon.js with the Intel edison board and the intel Iot developer kit

Published Date
13 - Aug - 2015
| Last Updated
17 - Aug - 2015
 
Using cylon.js with the Intel edison board and the intel Iot deve...

The Intel® Edison board is an amazing new single-board computer. With its dual-core Intel® Atom™ processor, General Purpose I/O (GPIO), and other external interfaces, the Intel Edison board has a lot of potential for physical computing. That is why we added full support for the Intel Edison board in Cylon.js (http://cylonjs.com), our JavaScript* framework for robotics and Internet of Things (IoT) applications.

This article helps beginners learn about how to get started and access the full set of capabilities available. We’ll show you how to use Cylon.js to use almost all of the devices included in the Intel® IoT Developer Kit. Note, we said almost all. We exclude the relay due to safety reasons, because integrating alternating current (AC) electronics with the Intel® Edison board is a subject deserving of a whole separate article.

Image of the Intel® Edison board with everything connected:

Image of the Intel® Edison board with everything connected

https://github.com/hybridgroup/Using-Cylon.js-With-The-Intel-Edison-and-IoT-Starter-Kit/blob/master/images/full.jpg
Using Cylon.js, we will combine all of the direct current (DC) devices in the kit to create a single integrated solution: a smart front door system. The smart front door will have lights, a door buzzer, LCD indicator panel, sound and light sensors, and even its own API. It will be a complete (albeit scaled-down) IoT solution.

Please note that you will need to use an external DC power supply in order to have enough current to connect all of the devices to the Intel Edison board at the same time. Anything that provides between 7-15V with around 1000mA (1.0A) should work fine.

Part 1 - Lights
Parts used: Grove* - LED

We start out with turning on a light, represented by the LED in the kit. Turning on an LED is the “Hello, World” of IoT, and it provides a great place to get started. We are going to use the LED connector. You will also need to choose one of the colored LEDs and plug it into the small Grove board. Remember that the longer lead on the LED is the “+” and needs to match the “+” on the Grove board.

Plug the LED into the Grove LED board:

Plugging the LED into the Grove LED board

https://github.com/hybridgroup/Using-Cylon.js-With-The-Intel-Edison-and-IoT-Starter-Kit/blob/master/images/1.jpg
Here is the code to use: https://github.com/hybridgroup/Using-Cylon.js-With-The-Intel-Edison-and-IoT-Starter-Kit/blob/master/1.js
Copy/paste or enter the code into the “main.js” editor window of the Intel® XDK IoT Edition, save it, and upload it to the board.
Run the code and watch the LED blink.

Part 2 - Light Switch
Parts added: Button

Now we will add a button so users can turn the LED on and off themselves. The code shows how Cylon.js can respond to actions in the physical world. In JavaScript, events are typically used. If you have ever used jQuery, you have seem this common idiom with events such as “mouseOver”. Cylon.js makes extensive use of events that correspond to actions from hardware devices. In this case, the button driver supports both “push” and “release” events. We will connect the “release” event to the LED, so it turns on/off when the button is pushed down and then released.

Plug the button into the Grove button board:

Plugging the button into the Grove button board

https://github.com/hybridgroup/Using-Cylon.js-With-The-Intel-Edison-and-IoT-Starter-Kit/blob/master/images/2.jpg
Here is the code to use:
https://github.com/hybridgroup/Using-Cylon.js-With-The-Intel-Edison-and-IoT-Starter-Kit/blob/master/2.js
Copy/paste or enter the code into the “main.js” editor window of the Intel® XDK IoT Edition replacing the previous code, save it, and upload it to the board.

Run the code, push the button, and change the state of the LED.

Part 3 - Display
Parts added: LCD

Now we’re going to add a display, which will allow us to see what the board is doing as we continue to add more functionality to our system. The display included with the kit is a Liquid Crystal Display (LCD) that is backlit using a built-in RGB LED. This lets us change both the text displayed and the color of the backlighting. 

The LCD is an I2C device, which stands for “Inter-Integrated Chip” communication. I2C is a standard interface used for many different kinds of higher level sensors and devices. We will need to plug the LCD into one of the “i2c” connectors on the Grove shield.
First, we’ll add the code for the LCD. Then we’ll add code to display a message when we first run our Cylon.js code. Lastly, we will add code to the button.on(“released”) event, to update the display with the current lighting status.

Plug in the LCD:

Plug in the LCD

https://github.com/hybridgroup/Using-Cylon.js-With-The-Intel-Edison-and-IoT-Starter-Kit/blob/master/images/3.jpg
Here is the code to use:
https://github.com/hybridgroup/Using-Cylon.js-With-The-Intel-Edison-and-IoT-Starter-Kit/blob/master/3.js
Copy and paste or enter the code into the Intel® XDK IoT Edition editor window into the “main.js” replacing the previous code, save it, and upload it to the board.

Run the code, push the button, and change the message displayed on the LCD.

Part 4 - Web API
Parts added: none

We are going to add the Cylon.js HTTP API, which will let us see the web UI and control the system using REST. The Cylon.js API is modular and implemented in the form of several different plugins, so you can include different ways to communicate depending on your needs. We currently offer “http”, “socketio”, and “mqtt” API plugins, with more being added soon.

The HTTP API plugin, also includes Robeaux (http://robeaux.io), which is a simple, single-page web app based on React. This app shows you the current state of your robots and even lets you change their data.

In the various Cylon.js API plugins, there is a consistent way to figure out which robot or device you want to communicate with. This “routing” is documented in the form of a specification called the Common Protocol for Programming Physical Input/Output or “cppp.io” for short.
For example, in our current project “Doorbot”, the path to the LED device would be “/api/robots/doorbot/devices/led”. The pattern is “/api/robots/<robot name>/devices/<device name>” and by using this, we can use the Cylon.js API to allow other software to control our devices or send commands to our robot.

Here is the code to use:

https://github.com/hybridgroup/Using-Cylon.js-With-The-Intel-Edison-and-IoT-Starter-Kit/blob/master/4.js
Copy and paste or enter the code into the Intel® XDK IoT Edition editor window into the “main.js” replacing the previous code, save it, and upload it to the board.

Run the code and browse to the IP address that your board has been assigned using port 3000 (which is the default port for Robeaux).

You should see a screenshot of Robeaux:

A screenshot of Robeaux

https://github.com/hybridgroup/Using-Cylon.js-With-The-Intel-Edison-and-IoT-Starter-Kit/blob/master/images/robeaux.png
Click the “doorbot” robot. You should see the list of devices displayed. Click the “button” device. You will see details about the button displayed.
Under “Device Events” enter “push” into the field, then click the “Listen” button. Now push the actual physical button itself. You should see events appear in the web page, thanks to server-side events. This is great way to test if the devices are connected correctly.

Part 5 - Doorbell
Parts added: Touch Sensor, Buzzer

Now we’re going to add a way for a visitor to ring the buzzer -- and of course, the buzzer itself. From the point of view of Cylon.js, the touch sensor is simply a kind of button. Likewise, the buzzer acts very similar to an LED, in that it can be turned on or off, and not much else.
Touching the touch sensor triggers a touch.on(“released”) event. We will buzz the buzzer and display a message on the LCD screen.

Image of the Grove touch sensor board and buzzer board:

Grove touch sensor board and buzzer board

https://github.com/hybridgroup/Using-Cylon.js-With-The-Intel-Edison-and-IoT-Starter-Kit/blob/master/images/5.jpg
Plug in the touch sensor and buzzer.
Here is the code to use:
https://github.com/hybridgroup/Using-Cylon.js-With-The-Intel-Edison-and-IoT-Starter-Kit/blob/master/5.js
Copy and paste or enter the code into the Intel® XDK IoT Edition editor window into the “main.js” replacing the previous code, save it, and upload it to the board.

Run the code, tap the touch sensor, and listen to the buzzer.

Part 6 - Front Door Opener
Parts added: Rotary Potentiometer, Servo

Now we’re going to add the ability to move the servo using the rotary potentiometer to control it. This could be adapted for opening a lock or moving a security camera, but for the sake of simplicity we’re just going to use a couple more of the parts in the kit.

A potentiometer, or “pot” for short, is a kind of variable resistor. Based on how you turn it, it sends out more or less voltage on the other end—like a volume knob. In fact, most volume dials are pots.

Servos are a special kind of motor that can move back and forth within a range of motion, usually 180 degrees. They are often used as part of radio-controlled airplanes or boats to control the angle of the rudder. They can also be used to open door locks, move cameras across a sweep, and more.

Image of the Grove servo and pot:

Image of the Grove servo and pot

https://github.com/hybridgroup/Using-Cylon.js-With-The-Intel-Edison-and-IoT-Starter-Kit/blob/master/images/6.jpg
Plug in the servo and rotary potentiometer.
Here is the code to use:
https://github.com/hybridgroup/Using-Cylon.js-With-The-Intel-Edison-and-IoT-Starter-Kit/blob/master/6.js
Copy and paste or enter the code into the Intel® XDK IoT Edition editor window into the “main.js” replacing the previous code, save it, and upload it to the board.

Run the code, turn the dial, and watch the servo move.

Part 7 - Fire Alarm
Parts added: Temperature Sensor

Visitors are not the only concern for our smart door. We also want to be able to detect the heat of a fire and respond appropriately by setting an audible alarm. In the case of a fire, you wouldn’t want to open the door if the fire is just on the other side of it!

The temperature sensor is going to use the UPM library support that is built into Cylon.js. UPM is an Intel® library that has support for many different sensors. The Grove* - Temperature Sensor is one of them.

Image of the Grove temp sensor:

Image of the Grove temp sensor

https://github.com/hybridgroup/Using-Cylon.js-With-The-Intel-Edison-and-IoT-Starter-Kit/blob/master/images/7.jpg
Plug in the temperature sensor.
Here is the code to use:
https://github.com/hybridgroup/Using-Cylon.js-With-The-Intel-Edison-and-IoT-Starter-Kit/blob/master/7.js
Copy and paste or enter the code into the Intel® XDK IoT Edition editor window into the “main.js” replacing the previous code, save it, and upload it to the board.

Run the code and check out the latest temperature readings on the LCD.

Part 8 - Security Alarm
Parts added: Sound Sensor

If someone (or something) comes to the front door, our smart door can detect the sound using the sound sensor and turn on the lights. Intruders will be scared away and invited guests will be able to find the doorbell.

The sound sensor in the kit is simply an analog input device. Similar to the rotary dial, it provides an input ranging from 0 to 1024. In this case, the volume of the sound detected by the sensor corresponds to the voltage output by the sensor’s pin.

Image of the Grove sound sensor:

Image of the Grove sound sensor

https://github.com/hybridgroup/Using-Cylon.js-With-The-Intel-Edison-and-IoT-Starter-Kit/blob/master/images/8.jpg
Plug in the sound sensor.
Here is the code to use:
https://github.com/hybridgroup/Using-Cylon.js-With-The-Intel-Edison-and-IoT-Starter-Kit/blob/master/8.js
Copy and paste or enter the code into the Intel® XDK IoT Edition editor window into the “main.js” replacing the previous code, save it, and upload it to the board.

Run the code, make a noise, and watch the LED turn on.
 

Part 9 - Security Alarm (continued)
Parts added: Light Sensor

In similar fashion to our sound sensor, when someone comes to the front door at night, we can detect the presence of lights and turn on lights of our own. Once again, intruders will be scared away and invited guests will be able to find the doorbell.

The light sensor in the kit is yet another analog input device, so the code for it is similar to the sound sensor’s code.

Image of the Grove light sensor board:

Image of the Grove light sensor board

https://github.com/hybridgroup/Using-Cylon.js-With-The-Intel-Edison-and-IoT-Starter-Kit/blob/master/images/9.jpg
Plug in the light sensor.
Here is the code to use:
https://github.com/hybridgroup/Using-Cylon.js-With-The-Intel-Edison-and-IoT-Starter-Kit/blob/master/9.js
Copy and paste or enter the code into the Intel® XDK IoT Edition editor window into the “main.js” replacing the previous code, save it, and upload it to the board.

Run the code, expose the sensor to light, and watch the LED turn on.

Conclusion

In this article, we have shown you how to use Cylon.js with the Intel® Edison board and incorporate all of the parts in the Intel® IoT Developer Kit except for the relay. In addition, we’ve created a complete, miniature version of a smart front door system.

The Intel® Edison board is a very powerful machine in a very small package, and we have only scratched the surface of what it can do. Thanks to Cylon.js, it is also easy to exploit these capabilities to create the next generation of intelligent hardware devices. What will you make?

For more such intel IoT resources and tools from Intel, please visit the Intel® Developer Zone

Source: https://software.intel.com/en-us/articles/using-cylonjs-with-the-intel-edison-board-and-the-intel-iot-developer-kit/