1 2 Previous Next 15 Replies Latest reply on Jan 11, 2016 11:08 AM by rexstjohn

    Using Johnny Five with Edison

    zcema06

      Hi,

       

      I have been trying to run my hello-worlds.js file on my intel Edison (shown below):

       

      var five = require("johnny-five");

      var Edison = require("galileo-io");

      var board = new five.Board({

        io: new Edison()

      });

       

       

      board.on("ready", function() {

        var led = new five.Led(13);

        led.blink(500);

      });

       

      I have installed Node.js, I also used npm install galileo-io johnny-five and downloaded files to my file directory of folder my-robotics-project.

      When i execute using node hello-worlds.js, I get the following error:

       

      This OS image is no longer supported.

      Please upgrade to IoTkit Image with libmraa0 support

       

      c:\User\Mohamed\my-robotics-project\node_modules\galileo\lib\galileo.js:66

      if <Pin.IO.getPlatformType<> === 2> {

       

      TypeError: Cannot read property 'getPlatformType' of undefined

      at Object.<anonymous> <c:\User\Mohamed\my-robotics-project\node_modules\galileo\lib\galileo.js:66:11>

      at Module._compile <module.js:435:26>

      at Object.Module.extensions..js <module.js:442:10>

      at Module.load <module.js:356:32>

      at function.Module._load <module.js:311:12>

      at Module.require <module.js:366:17>

      at require <module.js:385:17>

      at Object.<anonymous> <c:\User\Mohamed\my-robotics-project\hello-worlds.js:2:14>

      at Module._compile <module.js:435:26>

      at Object.Module._extensions..js <module.js:442:10>

       

      Appreciate any help.

      Thanks

        • 1. Re: Using Johnny Five with Edison
          Intel_Peter

          Hello zcema06,

           

          I have never used Johnny-Five before, nevertheless I was able to install it on my Edison with the command found in rwaldron/galileo-io · GitHub. I was able to compile the blink example found in the same page and it worked correctly. I believe that you are only missing mraa, I had no issues because I had already installed it.

          If you are missing mraa you can download it from AlexT's Repo. Follow these instructions to do so:

           

          echo src/gz all http://repo.opkg.net/edison/repo/all > /etc/opkg/base-feeds.conf
          echo src/gz edison http://repo.opkg.net/edison/repo/edison >> /etc/opkg/base-feeds.conf
          echo src/gz core2-32 http://repo.opkg.net/edison/repo/core2-32 >> /etc/opkg/base-feeds.conf
          opkg update
          opkg install mraa
          

           

          Then you should be able to use Johnny -Five. But since you are already installing mraa, why don't you try using this library? You can find a blink example on JavaScript in mraa/Blink-IO.js at master · intel-iot-devkit/mraa · GitHub

           

          Peter.

          • 2. Re: Using Johnny Five with Edison
            zcema06

            Hi Peter,

             

            I followed the steps and mraa was updated from 0.8.1 to 0.9.0. I still had the same error.

            I also tried running the following code (which in intel XDK template), both codes work when i run them from XDK but not from node.js:


             

             

            var mraa = require('mraa'); //require mraa

            console.log('MRAA Version: ' + mraa.getVersion()); //write the mraa version to the Intel XDK console

             

             

            //var myOnboardLed = new mraa.Gpio(3, false, true); //LED hooked up to digital pin (or built in pin on Galileo Gen1)

            var myOnboardLed = new mraa.Gpio(13); //LED hooked up to digital pin 13 (or built in pin on Intel Galileo Gen2 as well as Intel Edison)

            myOnboardLed.dir(mraa.DIR_OUT); //set the gpio direction to output

            var ledState = true; //Boolean to hold the state of Led

             

             

            periodicActivity(); //call the periodicActivity function

             

             

            function periodicActivity()

            {

              myOnboardLed.write(ledState?1:0); //if ledState is true then write a '1' (high) otherwise write a '0' (low)

              ledState = !ledState; //invert the ledState

              setTimeout(periodicActivity,1000); //call the indicated function after 1 second (1000 milliseconds)

            }

             

            I get the following error:

             

            module.js:339

                 throw err;

             

            Error: cannot find module 'mraa'

                 at Function.Module._resolveFilename <module.js:337:15>

                 at Function.Module._load <module.js:287:25>

                 at Module.require <module.js:366:17>

                 at require <module.js:385:17>

            • 3. Re: Using Johnny Five with Edison
              Intel_Peter

              That is very strange I installed the latest version of mraa and I had the same behavior as you. But I remembered that I had test it before successfully, so I uninstalled mraa and then installed a previous version, these are the steps I used:

               

              opkg remove mraa --force-removal-of-dependent-packages
              wget http://repo.opkg.net/edison/repo/core2-32/libmraa0_0.7.2-r0_core2-32.ipk
              opkg install libmraa0_0.7.2-r0_core2-32.ipk
              
              

               

              With the version 0.7.2 I was able to run the example:

               

              var m = require('mraa'); //require mraa
              console.log('MRAA Version: ' + m.getVersion()); //write the mraa version to the console
              
              var myLed = new m.Gpio(13); //LED hooked up to digital pin 13 (or built in pin on Galileo Gen1 & Gen2)
              myLed.dir(m.DIR_OUT); //set the gpio direction to output
              var ledState = true; //Boolean to hold the state of Led
              
              periodicActivity(); //call the periodicActivity function
              
              function periodicActivity()
              {
                myLed.write(ledState?1:0); //if ledState is true then write a '1' (high) otherwise write a '0' (low)
                ledState = !ledState; //invert the ledState
                setTimeout(periodicActivity,1000); //call the indicated function after 1 second (1000 milliseconds)
              }
              
              

               

              I'm not sure why the example is not working on the latest version of mraa. arfoll, am I missing something?

               

              Peter.

              • 4. Re: Using Johnny Five with Edison
                zcema06

                I just tried that and I got the same error.

                 

                What is really strange is that if I run off XDK it works, only problem is through node.js.

                I would like to point out that this issue is not only with mraa but with any sketch I have tired (without mraa).

                could I be doing something wrong with node.js?

                 

                Here are the steps I followed to run the file:

                I saved the sketch as hello-worlds.js, then in node I go to that directory where file is saved and enter command:

                "node hello-worlds.js"

                 

                should there be other folders / files installed in same directory as my hello-worlds.js file?

                • 5. Re: Using Johnny Five with Edison
                  Intel_Peter

                  That's weird, did you make sure to uninstall the 0.9.0 version and then install the 0.7.2 version. I had no issues after I did this. Maybe there's something odd with your board's OS, why don't you try reflashing it? You can do it with Flash Tool Lite, you can find this tool and a guide on how to use it in Intel® Edison Downloads, the latest image can also be found in the same place.

                   

                  Peter.

                  • 6. Re: Using Johnny Five with Edison
                    poseid

                    Most problems with Node.js and Edison traced back to using an outdated image.

                    I think there are two ways to check the version of the image:

                     

                    * configure_edison --version

                    * After boot, there should be a message Poky 1.7.2 if using the latest image

                    • 7. Re: Using Johnny Five with Edison
                      poseid

                      Also, a tip for flashing the Edison, somehow the USB driver that provides the virtual disk drive seems to be buggy. For me, it helped to reboot the laptop, and start the firmware upgrade with a clean OS driver. Also, I attach a serial monitor to the other serial port to monitor progress. In my case of OS X, I do:

                       

                        $ screen /dev/cu.usbserial-AXXXX

                       

                      Load Flash tool.

                       

                      Monitor Firmware upgrade, e.g.

                       

                      Screenshot 2015-12-30 22.09.10.png

                      • 8. Re: Using Johnny Five with Edison
                        poseid

                        The upgrade takes around 5 minutes, and the result looks as such:

                         

                        Screenshot 2015-12-30 22.10.17.png

                        • 9. Re: Using Johnny Five with Edison
                          CMata_Intel

                          Hi zcema06,

                           

                          Did you check your image version? configure_edison --version

                          Which node version do you have on your board? node –version

                           

                          Regards,

                          Charlie

                          • 10. Re: Using Johnny Five with Edison
                            zcema06

                            I downloaded the Yocto 2.1 image from intel downloads link. Used the flash tool with .Json file.

                            My current edison version is: 159.devkit

                             

                            How can I upgrade to Poky 1.7.2?

                            • 11. Re: Using Johnny Five with Edison
                              zcema06

                              My current edison version is: 159.devkit

                              • 12. Re: Using Johnny Five with Edison
                                Intel_Peter

                                That is in fact the latest version of the image. Do you still have the same issue? Or, were you able to install and use Johnny-Five?

                                 

                                Peter.

                                • 13. Re: Using Johnny Five with Edison
                                  zcema06

                                  No, the problem hasn't been solved. I can't run anything off node.js.

                                   

                                  Do you know how the blink sketch mentioned above can run on my Edison if uploaded from XDK but not work when run from node.js?

                                  • 14. Re: Using Johnny Five with Edison
                                    Intel_Peter

                                    Could you take a screenshot of the error message you are currently getting? It would help us determine the root of the issue.

                                    The reason why the script does work when you use the XDK is because the XDK installs a version of mraa to be specifically used with the XDK project so it runs a little bit different than if you were running it directly from Linux. If you want to run the script from Linux, you will have to install a version mraa for general Linux use. I mean, they are not different versions of the same library, they are the same but they are stored in different places and can be used in different scenarios.

                                     

                                    Peter.

                                    1 2 Previous Next