Community
cancel
Showing results for 
Search instead for 
Did you mean: 
MAref
Novice
1,720 Views

Using Johnny Five with Edison

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 === 2> {

TypeError: Cannot read property 'getPlatformType' of undefined

at Object. <<span style="font-size: 13.3333px;">c:\User\Mohamed\my-robotics-project\node_modules\galileo\lib\galileo.js:66:11>

at Module._compile

at Object.Module.extensions..js

at Module.load

at function.Module._load

at Module.require

at require

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

at Module._compile

at Object.Module._extensions..js

 

Appreciate any help.

Thanks

15 Replies
Pedro_M_Intel
Employee
233 Views

Hello zcema06,

I have never used Johnny-Five before, nevertheless I was able to install it on my Edison with the command found in https://github.com/rwaldron/galileo-io/ 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 http://alextgalileo.altervista.org/edison-package-repo-configuration-instructions.html AlexT's Repo. Follow these instructions to do so:

echo src/gz all http://repo.opkg.net/edison/repo/all http://repo.opkg.net/edison/repo/all > /etc/opkg/base-feeds.conf

echo src/gz edison http://repo.opkg.net/edison/repo/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 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 https://github.com/intel-iot-devkit/mraa/blob/master/examples/javascript/Blink-IO.js mraa/Blink-IO.js at master · intel-iot-devkit/mraa · GitHub

Peter.

MAref
Novice
233 Views

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

at Function.Module._load

at Module.require

at require

Pedro_M_Intel
Employee
233 Views

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 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.

MAref
Novice
233 Views

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?

Pedro_M_Intel
Employee
233 Views

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 https://software.intel.com/en-us/iot/hardware/edison/downloads Intel® Edison Downloads, the latest image can also be found in the same place.

Peter.

PMuld2
New Contributor II
233 Views

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

PMuld2
New Contributor II
233 Views

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.

PMuld2
New Contributor II
233 Views

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

MAref
Novice
233 Views

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?

Carlos_M_Intel
Employee
233 Views

Hi zcema06,

Did you check your image version? configure_edison --version

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

Regards,

Charlie

MAref
Novice
233 Views

My current edison version is: 159.devkit

Pedro_M_Intel
Employee
233 Views

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.

MAref
Novice
233 Views

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?

Pedro_M_Intel
Employee
233 Views

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.

Rex_S_Intel
Employee
233 Views

Here is what I would try:

1.) Reflash the board with the very latest image (already covered)

2.) Manually delete the node_modules folder and re-run NPM install again in your project directory

3.) Update your dependencies in your package.json file to "*" or "latest" -> I have seen several cases where source code snippets online targeting older versions of Johnny-Five and Galileo.io are pointed at out-of-date versions which don't work with the latest MRAA

4.) The error you are seeing looks like it is MRAA related, I suspect you have older Johnny-Five targets in your Package.json

Hope that helps.

Reply