Wednesday, June 29, 2016

Nodebot Blink Modified

Strobing Led and Piezo Song

This is one of the exercises for the Port Coquitlam Node and Nodebots Meetup.  This challenge was posted in order to do a quick piezo demo. 



'use strict';

var five = require('johnny-five'),   
    board = new five.Board();
 
board.on('ready', function(){
    console.log('Board is ready');
 
    led.strobe(10000, function(){                    

      var led = new five.Led(13);
      var piezo = new five.Piezo(3);

        piezo.play({          
            song: "C D F D A - A A A A G G G G - - C D F D G - G G G G F F F F - -",
            beats: 1 / 4,
            tempo: 100
        });      
    });  
});
console.log('Waiting for board...');

Hey, there is a bug in your code!

You got it!  There is a bug.  Can you spot it?  After loading the firmatta to the microcontroller and running the above program we saw in the console something like this:




The board is telling us that "pin 3 is already in use".  Hum, it is only instantiated once...  or is it? Strobe is an interval operation and every time the callback function is executed we try to create a new piezo in the scope of that function using pin 3.  During the first strobe interval there is no error but the second time the strobe interval passes then we get the warning because pin 3 is already taken.

To fix the bug we need to take the line where the new piezo is declared and place it before led.strobe()

Fixed!

'use strict';

var five = require('johnny-five'),
board = new five.Board();

board.on('ready', function(){
console.log('Board is ready');

var led = new five.Led(13);
var piezo = new five.Piezo(3);

led.strobe(10000, function(){
piezo.play({
song: "C D F D A - A A A A G G G G - - C D F D G - G G G G F F F F - -",
beats: 1 / 4,
tempo: 100
});
});
});
console.log('Waiting for board...');



Sunday, June 5, 2016

NodeBots Day-1: Getting the Environment Ready - Ubuntu 16.04 LTS

Getting the robotic NodeBot environment ready on Ubuntu worked without a glitch.  To get the environment ready follow the same sequence described in the previous note:

  1. Install Node and NPM
  2. Install Johnny-Five
  3. Install Arduino software IDE
  4. Optionally install Visual Studio Code as a Code Editor
    1. Install Git previous to the installation of Visual Studio Code


I have an old Fujitsu laptop kicking around (i3, 2.26 GHz, Dual Core, with 4 GB of RAM) running Ubuntu 16.04 LTS.  Follow the instructions described in the following how to guide for installing Nodejs on Ubuntu.

We already know how to install Johnny-Five using NPM:

$ npm install johnny-five

To install the Arduino software IDE (Sketch) on ubuntu , the easiest way, is by issuing a command from terminal:

$ sudo apt-get update
$ sudo apt-get install arduino

The first command updates the list of packages and dependencies and the second command installs the arduino software.  You will need to provide the password of the super user.  Accepts the defaults and required dependencies are installed.  Once the installation process ends, search for Arduino and lock it on the launcher for convenience.

Start the sketch IDE and a permission dialog is loaded:



Click Add and provide the super user password again.  Connect the Arduino board to your computer through the provided USB cable and verify that the correct port is selected by going to Tools > Serial Port...  however, initially "Serial Port" was not enabled.  This was strange but after restarting the computer the Tools > Serial Port item was enabled and I selected the only port available to me '/dev/ttyACM0'.

Verify that the board under Tools > Boards is Arduino Uno

Now you can load the firmata from File > Examples > Firmata > StandardFirmata.  In the Windows environment we selected StandardFirmataPlus, but this one is not available in the version which was just installed.  Uploading the firmata to the board works perfect and there is no need to edit SerialFirmata.h header file.

Now you can test Blink.js.  Optionally install Visual Studio Code and GIT which I highly recommend, it provides intellisense, you can debug your scripts, you'll love it and it is free.

Write Blink or copy the Windows version but omit the configuration object passed into the Board constructor function.  There is no need to specify the port number for this exercise in this environment.

$ node Blink.js

Enjoy.

In our meetings we will try to cover as much as possible using the Johnny-Five gude.

References

Saturday, June 4, 2016

NodeBots Day-1: Getting the Environment Ready - Windows

For our "NodeBots Day" activity we are going to follow the "Johnny-Five" guide.  I feel that there is enough material to get the meetup started.  Johnny-Five is a JavaScript Robotics and Internet of Things (IoT) platform.

Pre Requisites

To be able to run the exercises we need:
  1. Install Node.js and NPM.
  2. Install Johnny-Five
  3. Arduino Software IDE
  4. Optionally install a Code Editor
    1. Visual Studio Code is excellent:  recommended over Notepad++, Notepad and even Sublime
      1. Visual Studio Code has a GIT dependency therefore you will need to install Git on your station.  Install Git Bash...  you'll love it!
  5. You might need to install Python and make sure it is included in the path in the case of Windows OS

Quickly

What is Node?  It is a server side platform built on Google's Chrome JavaScript engine (V8 Engine).  As we advance in our journey you will be exposed to other fantastic things that we can do with Node including:
  • Asynchronous
  • Event Driven
  • Very fast!
  • Single thread but it is very scalable
  • It is open source!
To install Nodejs, follow the link provided in this note and select the appropriate version for your system.  If you are using the Window installer make sure that you select to include NPM.  'npm' is the Nodejs package manager and we are going to install required modules using it.

What is Johnny-Five?
As previously mentioned; it is a JavaScript Robotic and IoT development platform.  Its is community based, open source.

Once you have installed Node with npm you can install Johnny-Five.  On my git bash window it looks like this:


Great!  We are almost there!  Next we need to install the Arduino IDE.

Do I really need the Arduino Software?
Well, no.  If you do not have an Arduino board you do not really need the software and instead you could run the Nodebot-Workshop, which provides a "stubbed" Arduino board for testing each workshop challenge...  but we have boards, and we are going to have these boards around so, you can do either!

Taking the path of the real thing requires a bit more work.  We need a protocol to communicate with the board.  Arduino provide this software and it is called "StandardFirmataPlus".


O load the firmata you need to go "File > Examples > Firmata > StandardFirmataPlus".  Once the firmata loads you need to upload it to the board by clicking the "upload" arrow.  This might not work.  I am not sure why this error is "out there".



To get rid of it you need to open the header file "SerialFirmata.h" and go to line 31 and comment the include "#include "



Save the file and upload again.  It should work now.  If it does not then write a comment here and we'll work it out together.

You are almost there!

Why do I need Python installed? 
We need Python because there are a few modules that need to be built for the specific platform.  We might not need it right away, but we will for sure.

Which programming language are we going to be using?  Can I use C for Arduino?
We are using Node, which is JavaScript.  Yes you are right, you could use a C like language for Arduino but in our meetup we are doing Node.

How do I know that I am ready to "go"?  How do I know that everything is ready?
That is a good question and it will depend on a variety of factors including:

  • Operating System
  • Version of Node
  • Version or Arduino and firmware
The classic "Hello World" for the board is the "Blink-Blink" program:


Testing "Blink-Blink"

Assume your board is ready to go.


and you try to run your code after loading the firmata and...  what!?


This was difficult to troubleshoot.  The solution to this "bug" is to explicitly indicate that the Arduino board, in my case, was connected to port COM4 and this was indicated passing a configuration object into the Board construction function.


Run again and smile!  You are on your way.  This is actually documented by Johnny-Five.  What johnny-Five says is that the platform will try to determine the port, however, the port could also be explicitly set, like we did above. 

We are going to make sure that every one can run this exercise on the available boards.

I will document this same setup for Ubuntu in a part 2.  I will add references to this note a little later, but I will publish it now so some of your can get going.

In our meetings we will try to cover as much as possible the examples posted by the Johnny-Five guide.

References



A1 Repo: Simple Pagination for WCF Service Operation

It is never a good idea to paginate on the client.  This post is about a simple pagination for a WCF service operation.  For this work I nee...