Pages

Installing Nodejs and node-hid on a Raspberry Pi armv7+

I have done quite a few projects now using the node-hid library with Nodejs. It does require a little work to get up and running on a Raspberry Pi but it is well worth it. In this post I am going to cover the steps for getting it running on a PI mainly to self document as I am forever having to work this out every time I need it. If I used it everyday I would probably remember the steps but it's just long enough between installs that I forget the steps I take. I may come back to this post and edit it from time to time to ensure its correct as I find issues.

What does node-hid do?

Node-hid allows you to access USB HID devices from Nodejs projects. This as you might imagine is very handy. Joysticks, mice, keyboards, busylights to name a few but basically anything you can stick into your USB port that supports the HID standard.

https://github.com/node-hid/node-hid

Below are basic step by step instructions on everything from installing the image on the Pi and installing node to getting node-hid onboard. This is very basic guidance especially the initial installing the OS and node. If you want screenshots and all the rest go to here.

Installing OS on Pi

Step 1. Download Pi Image
https://www.raspberrypi.org/downloads/raspbian/
Step 2. Use Etcher to place image on SD card:

This is a great tool recommended by raspberrypi.org.
 https://www.balena.io/etcher/

Prepare Pi

Step 1. Upgrade Pi:
$ sudo apt-get update
Step 2. Update packages:
$ sudo apt-get dist-upgrade

Installing Nodejs on Pi armv7+ (This will not work for armv6 Pi's)

Check your Pi version using:
$ uname -m
 Step 1.  Updates Debian apt package repository to include the NodeSource packages:
$ curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
Step 2. Install
 $ sudo apt install -y nodejs 
Step 3. Check node version
$ node -V

Installing node-HID on a Pi

Step 1. Install tools:
Linux (kernel 2.6+) :
  • Compilation tools: $ sudo apt install build-essential git
  • gcc-4.8+: $ sudo apt install gcc-4.8 g++-4.8 && export CXX=g++-4.8 (note: not sure how applicable this is)
  • libusb-1.0-0 w/headers: $ sudo apt install libusb-1.0-0 libusb-1.0-0-dev (note: possibly already installed)
  • libudev-dev: $ sudo apt install libudev-dev
 Step 2. Compile:
$ npm install node-hid --build-from-source
 Step 3. Move on to building/installing application

VoIPNorm


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.