Node.js on Khadas VIM


#1

I would like to see some docs on how to use the GPIO pins. Maybe a simple example to toggle a digital pin on and off as well as accessing the value of an analog pin.

Thanks!


Topics for Khadas Docs
#2

Hi, Ryanjgill:
Which OS do you run? Is it Android?


#3

I was running the Ubuntu Mate. Looking forward to programming in Node.js


#4

It seems that we need to port Node.js to Khadas VIM first :slight_smile:

Will research first, and update here.


#5

I installed the latest version of Node on the Ubuntu Mate image. It was running great! I did a quick stress test on an Express web server and the results were pleasing :slight_smile:


#6

Can you share the steps and guidance for your effort? A professional instructions is appreciated, and we will release it on Khadas Docs with the author name as you :wink:


#7

Sure, I will recreate the steps starting from the latest Ubuntu image.

I think we only need to run the following 2 commands.

Install Node.js:

sudo apt-get install nodejs-legacy

Install NPM:

sudo apt-get install npm

Then we should be able to see each of the versions by doing node -v and npm -v


#8

I am fond of nodejs, and i also wanted to install the latest version on the VIM (pro).
My installed firmware is Ubuntu 16.04 server, dated 11feb17.
I followed the instructions published here:


But I got stuck at some point.
Here are the commands I typed:

sudo apt-get install git
sudo apt-get install wget
sudo apt-get install build-essential libssl-dev
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash -
nvm ls-remote

at this point, we are able to list all available nodejs version up to 7.7.3 as of today.
BUT this next command failed miserably:

nvm install 7.7.3

BECAUSE the function nvm_get_arch() in the file ~/.nvm/nvm.sh is returning “aarch64” instead of “arm64” which is expected (see file list in https://nodejs.org/dist/v7.7.3/)

So I just modified nvm_get_arch() to return “arm64” exited my session, logged back in, then I was able to successfully run “nvm install 7.7.3”

last step to perform is:

nvm use 7.7.3

then “node --version” and “npm -v” were succesfull and we (hopefully) now can enjoy all the beauty of the latest nodejs functions on our beloved Khadas VIM;

Please try on your own and get back here to report about your success of failure.
Regards.


#9

Nice work ravelo. I was able to clone the latest version of nvm and it appears they have merged in a fix for the issue you were having.

I cloned the repo and then ran the install script.

git clone https://github.com/creationix/nvm.git

cd nvm && bash install.sh

Confirmed successful install of Node v7.7.3 and NPM v4.2.1

Nice work guys! :heart_eyes:


#10

NVM is totally awesome.

If you are feeling up for a treat, check out GVM.

Strong typing FTW ;).


#11

thanks!
i could have checked for and used the latest version of nvm on its github repo but i did not think of it,
now the fixed version does take into account aarch64, great!


#12

and now, what about doing gpio from node anyone ?
is there a valid solution someone has found and used successfully?


#13

@Terry has developed a demo APK on rooted Android Nougat ROM, he will release the demo source code after we release the new Android Nougat in this week.


#14

apk are android java apps, my need is in fact some javascript linux apps which is able to do gpio, so, does @terry have such a code ?


#15

Do you need the source code of GPIO on android ?
We will add the support for wiringpi in the future .


#16

@terry, I like Android, but here I really need to be able to write an nodejs ubuntu app.
So source code for and android apk (java or c++) might not tell me anything at all on how to do the same under nodejs and ubuntu.

The very 1st step for me is be able to read / write on a GPIO pin from (ubuntu) shell script, please take that need into account.
tks


#17

You can follow below step to read / write the GPIO

Steps

1). You need to reconfigure the kvim_defconfig in kernel

++   CONFIG_GPIO_DEVRES=y
++   CONFIG_GPIOLIB=y
++   CONFIG_OF_GPIO=y

2). The VIM GPIO port number list

	 GPIOH5:     176
	 GPIOH6:     177
	 GPIOH7:     178
	 GPIOH8:     179
	 GPIOH9:     180
    GPIOAO6:     151

3). Write / Read the GPIO

eg: config the GPIOH5 as high level output
echo  176 > /sys/class/gpio/export
echo  out  > /sys/class/gpio/gpio176/direction
echo  1    > /sys/class/gpio/gpio176/value

eg: config the GPIOH5 as input
echo  176 > /sys/class/gpio/export
echo  in  > /sys/class/gpio/gpio176/direction


MPI over GPIO and Clustering
Add Bluetooth Support for Ubuntu
#18

oh yeah !!! this is first class info and this really begins to be usefull !
I’ll test very soon and will report here


#19

when you modify kvim_devconfig , you need to recompile and install the new kernel, right ?
if you have already done so, could you please publish the modified kernel and tell us how to deploy it on a “khadas” ubuntu server installed on emmc?
thks !


#20

Support for wiringpi would be game changer for gpio. I look forward to this :+1: